スプライトが0より小さい場合は、スプライトが画面の端からはね返るようにしようとしています。今は画面全体を空白にズームするだけです。 CentipedeBodyはSpriteを拡張するクラスです。 render
メソッドでは、クラスのオブジェクトであるex.update();
を呼び出します。その後batch.begin()
とbatch.end()
の間に私はあなたの子供のクラスの境界、Sprite
はすでに限界を持つが、あなたが他のオブジェクトとの衝突に興味を持っている場合は、その使用する理由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)'を実行できますか?最後の試合では、スプライトが左に移動し、画面の端にぶつかり、ちょっと下り、もう一方の端に右に移動し、繰り返します。今私はちょうどそれが端から跳ね返る得る少なくともほしいと思う。 – retchers
画面の端でタイルと何らかのタイプのタイル衝突を実行できますか? – retchers