Is that a normal decision or am I missing something?



  • Airplane class

     public class Airplane extends BasicObject {
    
    public Airplane(){
    
        // по центру экрана
        x = MyMainClass.WIDTH/2;
        y = MyMainClass.HEIGHT/2;
        dx = speed = 200;
    
        // делаю прямоугольник
        rectangle = new Rectangle();
        rectangle.x = x;
        rectangle.y = y;
        rectangle.width = 64;
        rectangle.height = 64;
    
        // как самолет будет выглядеть
        texture = new Texture("AIRPLANE.png");
        sprite = new Sprite(texture);
    
        // позиция спрайта соответствует позиции прямоугольника
        sprite.setPosition(rectangle.x, rectangle.y);
    

    public void update(float dt){

    // если нажать B, то x сдвинется вправо, прямоугольник движется за x,
    // а позиция спрайта становится равной позиции прямоугольника
    if(Gdx.input.isKeyJustPressed(Input.Keys.В)) {

            x += dx * dt;
            rectangle.x = x;
    
            sprite.setPosition(rectangle.x, rectangle.y);
        }
    }
    

    Now the question is, isn't it too much? update()or is that normal and should we do it? If you remove it. sprite.setPosition(rectangle.x, rectangle.y); or rectangle.x = x;There's no movement. x changing. So, is it okay or is there a better solution?



  • Maybe it's better for some kind of manager to add a compression to pick up and send a message (or callback interface) to all signatory, reporting a state like Publisher-Subscriber.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2