1 decade ago by jtokarchuk
found this excellent code as a starting point:
however, when I use it, the player is shifted to the right (as the code does not take into account the player's width/2), however -- when I make the if statements reflect this, I get black overscroll on the right and bottom. I don't know how to stop that.
scrollScreen: function() { if(this.player.pos.x > (ig.game.collisionMap.width*ig.game.collisionMap.tilesize-ig.system.width/2)) { this.screen.x = ig.game.collisionMap.width*ig.game.collisionMap.tilesize-ig.system.width; } else if (this.player.pos.x < ig.system.width/2) { this.screen.x = 0; } else { this.screen.x = (this.player.pos.x - ig.system.width/2); } if(this.player.pos.y > (ig.game.collisionMap.height*ig.game.collisionMap.tilesize-ig.system.height/2)) { this.screen.y = ig.game.collisionMap.height*ig.game.collisionMap.tilesize-ig.system.height; } else if (this.player.pos.y < ig.system.height/2) { this.screen.y = 0; } else { this.screen.y = (this.player.pos.y - ig.system.height/2); } }
however, when I use it, the player is shifted to the right (as the code does not take into account the player's width/2), however -- when I make the if statements reflect this, I get black overscroll on the right and bottom. I don't know how to stop that.