1 decade ago by SnakePlissken
So I am having a very weird problem while working on getting an entity to move to a certain pixel destination. What happens is when I click the entity tile that my main "Knight" entity wants to move to I find the tiles selected pos.x and the knight pos.x and increase the vel on the knight until it reaches the selected pos.x
Now the trouble I run into is the fact that vel.x will give decimal numbers. So my first thought was why not just update it so it becomes an integer before the if statement to see if it is at its destination.
Well that did not work and would stop my 'knight'. Then here is the strange part. While debugging in chrome I found out that the code I am using is working correctly. So it works while debugging but not while live.
Here is code everything being done at the destination entity tile.
Now the trouble I run into is the fact that vel.x will give decimal numbers. So my first thought was why not just update it so it becomes an integer before the if statement to see if it is at its destination.
Well that did not work and would stop my 'knight'. Then here is the strange part. While debugging in chrome I found out that the code I am using is working correctly. So it works while debugging but not while live.
Here is code everything being done at the destination entity tile.
update: function() { var currentXFloor; var currentYFloor; var CurrentXCeiling; var currentYCeiling; var PositionToInt; currentXFloor = this.pos.x; currentYFloor = this.pos.y; currentXCeiling = currentXFloor + 25; currentYCeiling = currentYFloor + 25; if((ig.input.pressed('click')) && (ig.input.mouse.y <= currentYCeiling && ig.input.mouse.y >= currentYFloor ) && (ig.input.mouse.x <= currentXCeiling && ig.input.mouse.x >= currentXFloor) ) { ig.global.SelectedXPos = this.pos.x; ig.global.SelectedYPos = this.pos.y; alert(ig.global.SelectedXPos + ', ' + ig.global.SelectedYPos); if (ig.global.SelectedKnight.pos.x > ig.global.SelectedXPos) { ig.global.SelectedKnight.vel.x = -25; } else if (ig.global.SelectedKnight.pos.x < ig.global.SelectedXPos) { ig.global.SelectedKnight.vel.x = 25; } ig.global.SelectedKnight.currentAnim = ig.global.SelectedKnight.anims.move; this.kill(); } ig.global.SelectedKnight.pos.x = ig.global.SelectedKnight.pos.x.toInt(); if(ig.global.SelectedKnight.pos.x == ig.global.SelectedXPos) { ig.global.SelectedKnight.vel.x = 0; ig.global.SelectedKnight.currentAnim = ig.global.SelectedKnight.anims.idle; } }