gpt4 book ai didi

javascript - 如何知道pixi.js中光标位于哪个对象

转载 作者:行者123 更新时间:2023-11-27 23:50:23 24 4
gpt4 key购买 nike

如何知道光标所在的对象?
模拟 Flash 事件 mouseover-mouseout。 pixi.js v3.0.7

最佳答案

使用 2d 对象时,您可以依赖 pixi 对象回调,例如 this example或者那里:

var bunny = new PIXI.Sprite(texture);

// enable the bunny to be responsive to mouse and touch events
bunny.interactive = true;

// this button mode hand cursor appears when you rollover the bunny with your mouse
bunny.buttonMode = true;

bunny.mousedown = bunny.touchstart = function(data) { this.dragging = true; }

bunny.mouseup = bunny.mouseupoutside = bunny.touchend =
bunny.touchendoutside = function(data) { this.dragging = false; }

bunny.mousemove = bunny.touchmove = function(data) { if(this.dragging) drag(); }

bunny.mouseover = function(data) {}

bunny.mouseout = function(data) {}

如果您想通过对象拾取来模拟 3D 世界,您需要一个名为 raycaster 的东西。 Three.js库已经内置了一个。

关于javascript - 如何知道pixi.js中光标位于哪个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32764528/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com