1 decade ago by Sledge
I have a question regarding the correct way to implement the .getTile(x, y) method as it applies to a block of code (posted below) that I use to adjust the screen position based on the player position. Basically, the screen is supposed to follow the player unless the boundary of the game window is outside of the game map. So far it only checks for the left and right hand map boundaries, but something is not quite working.
However, instead of following the player the x coordinate is always stuck such that the left boundary of the screen is flush against the map boundary on the left side. I think that the problem has to do with the call to
Is this an incorrect assumption? If so, how do the tile coordinates relate to the player coordinates?
Edit: fixed a mistake in the code, hopefully now it is more clear as to what I am trying to do.
However, instead of following the player the x coordinate is always stuck such that the left boundary of the screen is flush against the map boundary on the left side. I think that the problem has to do with the call to
map.getTile(screenXPos, player.pos.y)
in the first conditional statement, which I assume uses the same coordinate system as the player. Is this an incorrect assumption? If so, how do the tile coordinates relate to the player coordinates?
update: function() { // screen follows the player, unless player moves to boundary of map var player = this.getEntitiesByType( EntityPlayer )[0]; //var map = this.getMapByName('collision' ); var screenXPos = player.pos.x - ig.system.width/2; var screenYPos = player.pos.y - ig.system.height/2; //var isTileOnScreen = map.getTile(player.pos.x - ig.system.width/2, player.pos.y) && map.getTile(player.pos.x + ig.system.width/2, player.pos.y); var isTileOnScreen = ig.CollisionMap.getTile(player.pos.x - ig.system.width/2, player.pos.y) && ig.CollisionMap.getTile(player.pos.x + ig.system.width/2, player.pos.y); if( player && isTileOnScreen && ig.game.lives > 0 ) { this.screen.x = screenXPos; this.screen.y = screenYPos; } else { this.screen.y = screenYPos; if( player.accel.x > 0 && this.instructText) { this.instructText = null; } } },
Edit: fixed a mistake in the code, hopefully now it is more clear as to what I am trying to do.