수색…


두 위치 간 단순 이동

이를 위해 최선의 해결책은 actions 사용 actions 입니다. Scene2D 의 액터에 새로운 액션을 추가하려면 다음을 호출하십시오.

Action action = Actions.moveTo(x,y,duration);
actorObject.addAction(action);

여기서 x와 y는 목표 위치이고 duration은이 이동 속도 (초)입니다 ( float ).

이 작업 (및 해당 작업자)을 중지하려면 다음을 호출하여 수행 할 수 있습니다.

actorObject.removeAction(action);

또는 다음을 호출하여 모든 작업을 제거 할 수 있습니다.

actorObject.clearActions();

이렇게하면 작업 실행이 즉시 중단됩니다.

moveTo 액션은 액터의 x 및 y 속성을 조작하므로 액터를 화면에 그릴 때 항상 getX () 및 getY ()를 사용하여 텍스처를 그립니다. 다음 예제와 같이 :

public class MovingActor extends Actor {

    private Action runningAction;
    private float speed = 2f;

    public void moveTo(Vector2 location) {
       runningAction = Actions.moveTo(location.x, location.y, speed);
       this.addAction(runningAction);
    }

    public void stopAction() {
       this.removeAction(runningAction);
    }

    public void stopAllActions() {
       this.clearActions();
    }

    @Override
    public void draw(Batch batch, float parentAlpha){
        batch.draw(someTexture, getX(), getY());
    }
}


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow