dnassler Posted February 14, 2014 Share Posted February 14, 2014 I'm brand new to Phaser so bear with me. I'm trying to tweak the "basic follow" camera example so that the camera will only follow the movable "player" sprite when the player moves to within 50 pixels of the right side of the viewable space. The example by default follows the "player" when it is in the center of the viewable space so long as the world is big enough to allow for the camera to move. So when I move the player sprite by the cursor keys "right" when the player.x is at or greater than 400 the camera moves with the sprite (400 is the center in the example)... But I want the camera to follow the player only if the player is nearer to the edge of the viewable space... say within 50pixels. When I add the following statement just after the "follow" statement in the example then the camera does not scroll at all. What am I doing wrong? How do you use the deadzone? game.camera.follow(player); game.camera.deadzone.setTo(50,50,700,500); Thanks in advance for anyone's help. Link to comment Share on other sites More sharing options...
rich Posted February 14, 2014 Share Posted February 14, 2014 How large is your game world? Have you set the bounds on that? Link to comment Share on other sites More sharing options...
dnassler Posted February 14, 2014 Author Share Posted February 14, 2014 This is from the example... The world is 2000 by 2000. The game is 800 by 600. Link to comment Share on other sites More sharing options...
dnassler Posted February 14, 2014 Author Share Posted February 14, 2014 Also the behaviour varies depending on where the deadzone is set. So.... game.camera.deadzone.setTo(50,50,700,500); game.camera.follow(player); Causes the camera to not follow at all but... game.camera.follow(player); game.camera.deadzone.setTo(50,50,700,500); Causes the camera to follow the sprite as if the deadzone was not specified (i.e. behaves the same as the example for "basic follow"). Link to comment Share on other sites More sharing options...
dillydadally Posted July 4, 2014 Share Posted July 4, 2014 I'm not sure if you ever solved this problem, but I had the same one so I thought I'd post the answer in case anyone has this problem in the future. The problem is the deadzone object is not instantiated by default, so setTo() can't be called on an undefined object. You have to create a new rectangle first like this: game.camera.follow(player);game.camera.deadzone = new Phaser.Rectangle(50,50,700,500); After instantiating the deadzone Rectangle, you can then adjust it in the future with the setTo() function if you need to. The reason it would sort of work if follow was called first was because execution was stopping at the error when you called setTo, so if you called follow afterwards, it would never get executed. Hope this helps someone. Link to comment Share on other sites More sharing options...
Recommended Posts