efusien Posted September 29, 2014 Share Posted September 29, 2014 Hi, I want my player sprite to move only inside a restricted area inside the game world.This area is a rectangle. Is there a way to set like mySprite.body.collideWorldBounds = true, but inside such a rectangle ? A solution is to have 4 sprites for each rectangle side, and collide with my player sprite.But doesn't sound good, eh ? Link to comment Share on other sites More sharing options...
tomas.polz Posted September 30, 2014 Share Posted September 30, 2014 Hi, I think this method would do it http://docs.phaser.io/Phaser.Physics.Arcade.html#setBounds Link to comment Share on other sites More sharing options...
lewster32 Posted September 30, 2014 Share Posted September 30, 2014 If you need it per-object, you'll probably want to extend Sprite and add some extra bounds checking into the preUpdate method. Link to comment Share on other sites More sharing options...
efusien Posted September 30, 2014 Author Share Posted September 30, 2014 Thanks guys. I tried this code:game.physics.arcade.setBounds(0, 0, 200, 200);The player stays in this 200 x 200 area. Good!But in my case I want the player to go outside this area on some conditions. Like drag and drop the player to another area.So in this case I have to make my own bounds conditions. I'll try to extend the sprite like lewster32 said. If you have any example with preUpdate method, let me know Link to comment Share on other sites More sharing options...
lewster32 Posted October 1, 2014 Share Posted October 1, 2014 Yeah sure, if you look near the bottom of this fiddle you'll see where I extend the preUpdate method and add some bounds checking for moving platforms: http://jsfiddle.net/lewster32/zxcqhfzq/ Link to comment Share on other sites More sharing options...
jvinhit Posted September 21, 2015 Share Posted September 21, 2015 Yeah sure, if you look near the bottom of this fiddle you'll see where I extend the preUpdate method and add some bounds checking for moving platforms: http://jsfiddle.net/lewster32/zxcqhfzq/hi lewster32, i want collide in circle bounds. help! Link to comment Share on other sites More sharing options...
Recommended Posts