我有一个sprite,其纹理定义如下:
// Create sprite
spriteObj = new PIXI.Sprite(tileTexture);
spriteObj.interactive = true;
spriteObj.anchor = new PIXI.Point(0,0.5);
spriteObj.click = function(mouseData) {
alert("Clicked Me!");
};
然后,我使用多边形创建一个命中区域,如下所示:
polyCords = new PIXI.Polygon([
new PIXI.Point(xPos,yPos),
new PIXI.Point(xPos + (tileWidth / 2), yPos + (tileHeight/2)),
new PIXI.Point(xPos + tileWidth, tyPos),
new PIXI.Point(xPos + tileWidth / 2, this.yPos - (tileHeight/2)),
]);
我将多边形指定为精灵的命中区域:
spriteObj.hitArea = polyCords;
然后将子画面添加到舞台上:
stage.addChild(spriteObj);
到目前为止一切顺利。但是,命中区域不正确。为了测试命中区域的坐标是否正确,我使用图形对象绘制一个彩色形状来表示多边形,如下所示:
testTile = new PIXI.Graphics();
testTile.beginFill(0x21B837);
testTile.drawShape(polyCords);
testTile.endFill();
stage.addChild(testTile);
形状绘制(完美),命中面积,我会期望,但实际命中面积不符合我所画的形状!
1条答案
按热度按时间z0qdvdin1#
以下TypeScript可与PIXI v3.0.3配合使用
加上返回的sprite,命中区域是我所期望的。