Jerorx Posted March 7, 2016 Share Posted March 7, 2016 Hi, So I want a sprite that is controlled by the player to only be able to move within a specific perimeter of the map. I'm looking for ideas about how to achieve this in the best way possible. My first idea was to put sprites all around the perimeter to act as borders, and to use collisions to prevent the player from leaving that area. The problem is : the borders obviously have to be immovable, but for reasons specific to my game, the player sprite also has to be immovable (although it has to be movable by the player, I don't want it to be moved when some projectile hits it). And unfortunately, collisions don't work when both sprites are immovable ; they are still detected, but the sprites are not acted upon since they are both supposed to be immovable. I'm able to fire a processCallback tough, and I can use it to change the x or y coordinates of my player character, but the results looks like an ugly bouncing, not near as elegant as the standard collision handling. Any ideas? Edit : equally helpful would be a way to prevent my player character to move when hit by a projectile, without using the body.immovable property. Second edit : Nevermind, I found the solution : I use overlap instead of collide to handle collisions between projectiles and the player's character. That way, they are not separated,hence the character doesn't move ; therefore, no need for it to have the immovable property, so problem solved. I leave the post in case someone has the same issue ... Link to comment Share on other sites More sharing options...
iKest Posted March 8, 2016 Share Posted March 8, 2016 you can also create bitmap collision layer... Link to comment Share on other sites More sharing options...
drhayes Posted March 8, 2016 Share Posted March 8, 2016 Subclass Phaser.Sprite for your player and override the position setters. If the value that is trying to be set falls outside of the range you want then clamp it, maybe even using Phaser.Math.clamp. I'm not sure what effect this'll have on physics collisions, probably something weird and unexpected. Link to comment Share on other sites More sharing options...
Recommended Posts