我试图让雪碧在小于0时从屏幕边缘反弹。现在它只是将屏幕放大到虚空。这里是我的代码注意,CentipedeBody是一个扩展Sprite的类。在render
方法中,我称之为ex.update();
,它是该类的一个对象。然后在batch.begin()
和batch.end()
之间我有batch.draw(ex,ex.getPosition().x,ex.getPosition().y,ex.getSize().x,ex.getSize().y);
让雪碧从边缘反弹
public class CentipedeBody extends Sprite
{
public CentipedeBody(TextureRegion image,Vector2 position,Vector2 size) {
super(new TextureRegion(image));
this.position = position;
this.size=size;
bounds=new Rectangle(position.x,position.y,8,8);
left=true;
}
public void update() {
bounds.set(getPosition().x,getPosition().y,8,8);
if (left==true) {
position.x-=(.5f);
up=false;
down=false;
right=false;
left=true;
}
if (right==true) {
position.x+=.5f;
left=false;
right=true;
down=false;
up=false;
}
if (down==true) {
position.y-=(.5f);
right=false;
left=false;
down=true;
up=false;
if(position.x<0)
{
left=false;
right=true;
}
}
}
根据你的代码片段只有'if(left){}'执行,所以你的精灵只向左移动 – Aryan
那么我会如何让if(right)'execute?对于最后一场比赛,我希望精灵向左移动,击中屏幕边缘,稍微向下,然后向右移动到另一个边缘,然后重复。现在我只想至少让它从边缘反弹。 – retchers
我们可以通过屏幕边缘与瓦片进行某种类型的瓦片碰撞吗? – retchers