zyy-engine

图形引擎API


屏幕坐标

<h1>屏幕坐标</h1> <h2>1. H5Position</h2> <p><code>H5Position</code> 表示一个H5坐标对象</p> <h3>构造</h3> <pre><code class="language-javascript">new BCore2DFastFast.Extension2D.H5Position(id, position)</code></pre> <h3>参数</h3> <table> <thead> <tr> <th>参数名</th> <th>类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>id</td> <td>string</td> <td>唯一标识符</td> </tr> <tr> <td>position</td> <td>{x, y, z}</td> <td>世界坐标,如{ x:0, y: 0, z: 0}</td> </tr> </tbody> </table> <h3>属性</h3> <ul> <li><strong>id</strong>: string - 唯一标识符</li> <li><strong>worldPosition</strong>: Vector3 - 世界坐标</li> <li><strong>screenPosition</strong>: Vector2 - 屏幕坐标</li> <li><strong>onChange</strong>: Function? - 当viewer2D渲染时触发的回调,返回值为this。</li> </ul> <hr /> <h2>2. H5PositionManagerConfig</h2> <p>H5坐标对象管理容器的配置。</p> <h3>构造</h3> <pre><code class="language-javascript">new BCore2DFastFast.Extension2D.H5PositionManagerConfig(viewer2D)</code></pre> <h3>成员变量</h3> <table> <thead> <tr> <th>成员变量 类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>viewer2D</td> <td>BCore2DFastFast.Viewer.viewer2D</td> <td>2D Viewer对象</td> </tr> </tbody> </table> <hr /> <h2>3. H5PositionManager</h2> <p>H5坐标对象管理容器。</p> <h3>构造</h3> <pre><code class="language-javascript">new BCore2DFastFast.Extension2D.H5PositionManager(config)</code></pre> <h3>成员变量</h3> <table> <thead> <tr> <th>成员变量</th> <th>类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>config</td> <td>BCore2DFastFast.Extension2D.H5PositionManagerConfig</td> <td>H5坐标管理配置</td> </tr> </tbody> </table> <h3>方法</h3> <ul> <li><strong>addPosition(position: H5Position)</strong>: 添加H5屏幕坐标</li> <li><strong>getPosition: string)</strong>: 获取指定id的H5Position | undefined</li> <li><strong>deletePosition(id: string)</strong>: 移除指定id的H5Position</li> <li><strong>clearAllPosition()</strong>: 清空所有H5屏幕坐标</li> <li><strong>getAllPosition(): H5Position[]</strong>: 获取所有H5屏幕坐标</li> </ul> <hr /> <h3>3.1 示例代码</h3> <h4>添加H5屏幕坐标</h4> <pre><code class="language-javascript">let mydiv = document.createElement(&amp;quot;div&amp;quot;); let root = document.getElementById('bcorecontainer'); mydiv.style.width = &amp;quot;100px&amp;quot;; mydiv.style.height = &amp;quot;30px&amp;quot;; mydiv.style.position = &amp;quot;absolute&amp;quot;; mydiv.style.top = '0px'; mydiv.style.left = '0px'; mydiv.style.marginLeft = '-50px'; mydiv.style.marginTop = '-15px'; mydiv.style.lineHeight = '30px'; mydiv.style.backgroundColor = &amp;quot;#FF0000&amp;quot;; mydiv.innerHTML = &amp;quot;Hello BCore&amp;quot;; root.appendChild(mydiv); let h5Position = new BCore2DFastFast.Extension2D.H5Position('zz', {x: 0, y: 0, z: 0}); h5Position.onChange = (val) =&amp;gt; { mydiv.style.left = val.screenPosition.x + 'px'; mydiv.style.top = val.screenPosition.y + 'px'; } let h5PositionManagerConfig = new BCore2DFastFast.Extension2D.H5PositionManagerConfig(viewer2D); let h5PositionManager = new BCore2DFastFast.Extension2D.H5PositionManager(h5PositionManagerConfig); h5PositionManager.addPosition(h5Position);</code></pre> <h4>移除H5屏幕坐标</h4> <pre><code class="language-javascript">var h5Position = new BCore2DFastFast.Extension2D.H5Position('1', {x: 0, y: 0, z: 0}); h5Position.onChange = (val) =&amp;gt; { console.log(val); } var h5PositionManagerConfig = new BCore2DFastFast.Extension2D.H5PositionManagerConfig(viewer2D); var h5PositionManager = new BCore2DFastFast.Extension2D.H5PositionManager(h5PositionManagerConfig); h5PositionManager.addPosition(h5Position); h5PositionManager.deletePosition(h5Position.id);</code></pre> <h4>清空所有H5屏幕坐标</h4> <pre><code class="language-javascript">var h5PositionManagerConfig = new BCore2DFastFast.Extension2D.H5PositionManagerConfig(viewer2D); var h5PositionManager = new BCore2DFastFast.Extension2D.H5PositionManager(h5PositionManagerConfig); h5PositionManager.clearAllPosition();</code></pre> <hr />

页面列表

ITEM_HTML