스프라이트를 0보다 작게 만들면 화면 가장자리에서 튀게 만들려고합니다. 지금은 그냥 화면을 가로 질러 보이드로 확대합니다. CentipedeBody는 Sprite를 확장 한 클래스입니다. render
메서드에서 나는 클래스의 개체 인 ex.update();
을 호출합니다. 그 다음에 나는 당신의 자식 클래스의 경계, 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