efusien Posted September 29, 2014 Report 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 ? Quote Link to comment Share on other sites More sharing options...
tomas.polz Posted September 30, 2014 Report Share Posted September 30, 2014 Hi, I think this method would do it http://docs.phaser.io/Phaser.Physics.Arcade.html#setBounds Quote Link to comment Share on other sites More sharing options...
lewster32 Posted September 30, 2014 Report 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. Quote Link to comment Share on other sites More sharing options...
efusien Posted September 30, 2014 Author Report 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 Quote Link to comment Share on other sites More sharing options...
lewster32 Posted October 1, 2014 Report 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/ Quote Link to comment Share on other sites More sharing options...
jvinhit Posted September 21, 2015 Report 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.