i3Designer Posted June 8, 2014 Share Posted June 8, 2014 I have: var w = window.innerWidth;var h = window.innerHeight; var game = new Phaser.Game(w, h, Phaser.AUTO, 'Mio videogioco', { preload:preload, create:create, update:update }); I use the arcade physics but I can not get the camera to follow my sprite "box" the box moves only vertically So the box.velocity.x = -15; I used example.phaser.io but I can not Link to comment Share on other sites More sharing options...
lewster32 Posted June 8, 2014 Share Posted June 8, 2014 Without seeing more of the code we cannot say what the problem is. One unrelated issue you may have is using 'Mio videogioco' as the parent - this should really be the id attribute of where you want the game to appear on the page, which cannot contain spaces. Something like this:<div id="gamecontainer"></div>var game = new Phaser.Game(w, h, Phaser.AUTO, 'gamecontainer', { preload: preload, create: create, update: update }); Link to comment Share on other sites More sharing options...
i3Designer Posted June 9, 2014 Author Share Posted June 9, 2014 function create() {game.add.tileSprite(0, 0, w, 2000, 'sfondo');game.physics.startSystem(Phaser.Physics.ARCADE);game.physics.arcade.gravity.y=500;player = game.add.sprite(150, 320, 'player');player.events.onInputDown.add(jump)game.physics.p2.enable(player);game.camera.follow(player);game.physics.enable (player);} function jump(){player.body.velocity.y=-15;} I want the camera follows the player Link to comment Share on other sites More sharing options...
j0hnskot Posted June 9, 2014 Share Posted June 9, 2014 Camera can't go out of bounds. Since you put the height and width of the world to be equal to the window's ,the camera finds the end of world (which is the screen, let's say 800x600) and does not move. Try increasing the bounds of the world and see what changes.game.world.setBounds(0, 0, w, 2000); Link to comment Share on other sites More sharing options...
lewster32 Posted June 9, 2014 Share Posted June 9, 2014 game.physics.enable (player);Make sure you remove the space here so that it's:game.physics.enable(player); Link to comment Share on other sites More sharing options...
i3Designer Posted June 9, 2014 Author Share Posted June 9, 2014 Lewster 32 ... It is not space ... ... ...LOLNow I do a little test Link to comment Share on other sites More sharing options...
i3Designer Posted June 9, 2014 Author Share Posted June 9, 2014 I resolvedfunction create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.world.setBounds(0,0,0,2000); //Settiamo la gravità game.physics.arcade.gravity.y=500; sfondo= game.add.sprite(0,0,'bg'); sfondo.anchor.setTo(0,0); sfondo.inputEnabled=true; sfondo.events.onInputDown.add(salto); box = game.add.sprite(150,300,'box'); box.anchor.setTo(0.5,0.5); game.physics.enable(box); game.camera.follow(box);} Link to comment Share on other sites More sharing options...
Recommended Posts