我试图动画一个数字和添加一个健康栏在它之上。我创建了一个精灵(new PIXI.sprite()
)图形和一个图形对象(new PIXI.Graphics()
)的健康栏。
我可以通过设置它的X,Y坐标来移动sprite,但是当我对Graphics对象做同样的操作时,它总是被移开的,它的原点看起来是sprite的当前位置。见下面的图片。健康栏应高于数字。
var app = new PIXI.Application(windowWidth, windowHeight, {backgroundColor: 0x1099bb});
var prey = new PIXI.Sprite(texturePath);
var healthBar = new PIXI.Graphics();
healthBar.beginFill(0x00BB00);
healthBar.lineStyle(1, 0x000000);
healthBar.drawRect(prey.x - spriteLength, prey.y - spriteLength, spriteLength, 5);
prey.energyBar = healthBar;
app.stage.addChild(prey);
app.stage.addChild(healthBar);
prey.energyBar.position.set(prey.x,prey.y);
我怎样才能将健康栏的位置设置在数字之上?
发布于 2017-11-24 15:33:23
要做到这一点,一个更好的方法是作为猎物雪碧本身的孩子拥有健康棒。举个例子(你已经解决掉的部分)
var prey = new PIXI.Sprite( texturePath );
var heathbar = new PIXI.Graphics();
healthbar.y = -100;
prey.addChild( healthbar );
app.stage.addChild( prey );
现在,生命棒是你的猎物雪碧的孩子,当你移动猎物雪碧时,它会随之移动(我想这是你在你的情况下想要的)。
发布于 2017-11-23 23:00:37
将健康栏的初始坐标设置为(0,0)
解决了这个问题。
healthBar.drawRect(0, 0, spriteLength, 5);
https://stackoverflow.com/questions/47463647
复制相似问题