如何知道pixi.js中光标所在的对象

时间:2015-09-24 14:53:16

标签: javascript pixi.js

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

1 个答案:

答案 0 :(得分:1)

使用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库内置了一个。