JohnD Posted December 15, 2015 Share Posted December 15, 2015 I am trying to create movement controls for my game. I created an Up button, which, when held down, should make the player go upwards. The problem is that it only goes up once by 5 pixels when clicked. I tried to use isDown, but I don't know how to use it with buttons, only with keyboard controls. What is the correct way to do it? In CreatebuttonUp = game.add.button(16, game.world.centerY, 'button_up', goUp, this, 0, 1);buttonUp.anchor.setTo(0, 1);buttonUp.fixedToCamera = true;In Updatefunction goUp() { player.position.y -= 5;} Link to comment Share on other sites More sharing options...
Batzi Posted December 15, 2015 Share Posted December 15, 2015 Is this in the update()? I would something like this In Create:cursors = this.game.input.keyboard.createCursorKeys();In Update:if(cursors.up.isDown){ player.y -= 5;} Link to comment Share on other sites More sharing options...
JohnD Posted December 15, 2015 Author Share Posted December 15, 2015 Thank you for your answer! Yes, the function is in Update. I have already set controls for the keyboard cursors, but I also need buttons for touch devices. That is what I've been trying to implement unsuccessfully. Link to comment Share on other sites More sharing options...
drhayes Posted December 15, 2015 Share Posted December 15, 2015 The callback will only get called when the button is pressed, not every frame. In your callback, set a boolean like "isTouchingUp" to true and in your update method change your players position. Link to comment Share on other sites More sharing options...
JohnD Posted December 15, 2015 Author Share Posted December 15, 2015 I have finally figured it out. The only things I needed were buttonUp.input.pointerOver() and this.game.input.activePointer.isDown. This way when the button is being clicked or pointed on, the player goes up. Link to comment Share on other sites More sharing options...
Recommended Posts