1 decade ago by levo
I have been trying to get ig.TouchButtons to work on mobile devices but I am having some issues with pressing the button.
In my main.js file I have
The code works and spawns the button in the bottom left hand side with the image drawn if I am on a mobile device.
But I am having trouble pressing the button. I have
I know the code to switch colors works because I have it bound to the keyboard and if I press Z it does switch the color of the entity.
I don't know if the ig.input.pressed is the right code to use for the touch button. I have been searching the forums and I looked at the example code on http://impactjs.com/ejecta/integrating-impact-games to help me but it doesn't show the code for when a button is pressed.
Simplified down: I want to have a button shown on mobile devices that when pressed it changes the color of the entity.
Thanks in advance for the help
In my main.js file I have
'plugins.touch-button',
// Levels
'game.levels.main'
)
.defines(function(){
MyGame = ig.Game.extend({
font: new ig.Font( 'media/04b03.font.png' ),
buttons: null,
buttonImage: new ig.Image( 'media/iphone-buttons.png' ),
init: function() {
if( ig.ua.mobile ) {
this.buttons = new ig.TouchButtonCollection([
new ig.TouchButton( 'switch', {left: 0, bottom: 0}, 80, 96, this.buttonImage, 0 ),
]);
this.buttons.align();
}
ig.game.spawnEntity('EntityMainmenu', 0, 0);
},
update: function() {
// Update all entities and backgroundMaps
this.parent();
// Add your own, additional update code here
},
draw: function() {
// Draw all entities and backgroundMaps
this.parent();
if( this.buttons ) {
this.buttons.draw();
}
}
});
The code works and spawns the button in the bottom left hand side with the image drawn if I am on a mobile device.
But I am having trouble pressing the button. I have
if(ig.input.pressed('switch)){
// change color of entity
}
I know the code to switch colors works because I have it bound to the keyboard and if I press Z it does switch the color of the entity.
I don't know if the ig.input.pressed is the right code to use for the touch button. I have been searching the forums and I looked at the example code on http://impactjs.com/ejecta/integrating-impact-games to help me but it doesn't show the code for when a button is pressed.
Simplified down: I want to have a button shown on mobile devices that when pressed it changes the color of the entity.
Thanks in advance for the help
