Jump to content

Setting sprite.body.x won't update draw until I click and drag the scene


Recommended Posts

I have a strange issue, which I wonder if it's a bug or some optimization in phaser that's not getting triggered


I have a unit I click & select, and when I click another tile I set his (x,y) to the tile

this.entity.updatePosition(tile.getX(), tile.getY());// entityupdatePosition: function(x, y) {            if (this.sprite) {                this.sprite.body.x = x;                this.sprite.body.y = y - 64;            }        },

The numbers/values are right in console (I see them get updated), but until I hold down the mouse and drag the view, he doesn't change. I'm using arcade physics


I'm not using the Phaser camera, I wrote my own input handler, and it doesn't do anything different than the above code does.



  if (this.game.input.activePointer.isDown) {                if (this.game.origDragPoint) {                    // move the camera by the amount the mouse has moved since last update                    var movex = this.game.origDragPoint.x - this.game.input.activePointer.position.x;                    var movey = this.game.origDragPoint.y - this.game.input.activePointer.position.y;                    this.tileManager.drag({                        x: movex,                        y: movey                    });                 }}

and all tileManager.drag does is iterate through active tiles and update their positions

// tileManager.drag -> tileManager.updateTiles() -> for (var k in view) -> view[k].drag()drag: function() {            if (this.sprite) {                this.sprite.body.x = this.getX();                this.sprite.body.y = this.getY();            }             if (this.entity) {                this.entity.updatePosition(this.getX(), this.getY());            }                        // Check if tiles are in scope, otherwise destroy            this.checkRender();        },

Is there a way to force the sprite to update the body manually? This is the second time I've ran into this issue.


The first time was when I wrote a centerCameraOnTile(x,y), if I set it to move across the map it worked, but if I moved it only a couple tiles up I wouldn't see the tiles move unless I clicked and dragged. That one was fixed by running a blank drag event on game.update(), which has no logic behind it but it seemed to work

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...