PIXI.JS 点击获取当前坐标
source link: https://www.joynop.com/p/426.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
PIXI.JS 点击获取当前坐标
PIXI Canvas 点击事件如下
onMounted(() => {
console.log('mounted')
app.renderer.plugins.interaction.on('pointerdown', (event: PIXI.InteractionEvent) => {
let ax = event.data.getLocalPosition(container)
console.log(ax)
})
})
通过监听pointerdown
事件获取点击时的PIXI Event
可以获取相关的信息,其中有一个Global.Point
这个坐标是相对的,根据不同的页面大小会显示不同的坐标,并非真是坐标,需要对其加以转换
根据文档https://pixijs.io/examples/#/interaction/dragging.js 可知,有getLocalPosition
相关API
InteractionData.getLocalPosition<PIXI.Point>(displayObject: PIXI.DisplayObject, point?: PIXI.Point | undefined, globalPos?: PIXI.IPointData | undefined): PIXI.Point
getLocalPositio()
方法需要有对应的DisplayObject
若画布中有Graphics
、Sprite
或其他类型的DisplayObject
则直接引用即可
如无特殊DisplayObject
可以添加一个PIXI.Container
作为容器
const container = new PIXI.Container()
app.stage.addChild(container)
PIXI .DisplayObject
在屏幕上呈现的所有对象的基类。
Display objects implemented in PixiJS
Display ObjectDescriptionPIXI.ContainerAdds support for children to DisplayObjectPIXI.GraphicsShape-drawing display object similar to the Canvas APIPIXI.SpriteDraws textures (i.e. images)PIXI.TextDraws text using the Canvas API internallyPIXI.BitmapTextMore scaleable solution for text rendering, reusing glyph texturesPIXI.TilingSpriteDraws textures/images in a tiled fashionPIXI.AnimatedSpriteDraws an animation of multiple imagesPIXI.MeshProvides a lower-level API for drawing meshes with custom dataPIXI.NineSlicePlaneMesh-relatedPIXI.SimpleMeshv4-compatibile meshPIXI.SimplePlaneMesh-relatedPIXI.SimpleRopeMesh-related打赏: , - (付款时请注明赞赏)
Recommend
-
32
In this article, I will show you pixi.js, a super fast rending tool, also a swiss-army-knife tool with a friendly API. What is it? Pixi.js is a display tool that allows you to use the power of WebGL...
-
9
Canvas2D渲染库简析:(三)Pixi 2019年12月30日 |
-
7
Unity3D研究院之获取BoxCollider八个点的世界坐标 雨松MOMO
-
4
当Pixi使用WebGL去调用GPU渲染图像时,需要先将图像转化为GPU可以处理的版本。而能够被GPU处理的图像就叫做 纹理 ,在pixi中使用 纹理缓存 来存储和引用所有纹理。通过将纹理分配给精灵,再将精灵添加...
-
9
获取Dom元素的X/Y坐标 浏览:2468次 出处信息 现在Web页面的交互方式越来越多样化,其...
-
4
V2EX › 程序员 使用 pixi.js 和 oixi2 开发微信小游戏 WLDragon · 1 天前 · 383 次点击...
-
0
实现 pixi + DragonBones 播放动画雷电将军最近上线了,流水的主C,铁打的神。七神必抽,一个10发娶回家,还附赠一个小保底美滋滋。当然,这篇文章不是为了凡,还是回到我们的主题...
-
2
使用 Pixi.js 构建一个视差滚动器(第三篇) 2019-3-19 19:20 PM ·
-
2
My New Portfolio View the site here: endigodesign.com I recently launched a new version of Endigo Design, my personal portfolio. This is a process I u...
-
5
by zhangxinxu from https://www.zhangxinxu.com/wordpress/?p=11060 鑫空间-鑫生活 本文欢迎分享与聚合,全文转载...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK