1 decade ago by TaikoTaito
Hello there.
I've been lately trying to add touch buttons to my game. The documentation for Input suggests using the TouchButton plugin to ease use of touch buttons.
However, when I use it, it gets drawn, but fails to recognize any input. I have tested it on Chrome (iPad & Android), a built-in internet browser (Android), Opera (Android), Chrome (PC), Firefox (PC & Android), IE9 (PC) and CocoonJS (Android) but all failed.
I've been lately trying to add touch buttons to my game. The documentation for Input suggests using the TouchButton plugin to ease use of touch buttons.
However, when I use it, it gets drawn, but fails to recognize any input. I have tested it on Chrome (iPad & Android), a built-in internet browser (Android), Opera (Android), Chrome (PC), Firefox (PC & Android), IE9 (PC) and CocoonJS (Android) but all failed.
MyGame = ig.Game.extend({ buttons: [], // This was done as part of debugging leftButton: new ig.Image('media/button-left.png'), rightButton: new ig.Image('media/button-right.png'), shootButton: new ig.Image('media/button-shoot.png'), jumpButton: new ig.Image('media/button-jump.png'), init: function() { // Initialize your game here; bind keys etc // ... ig.input.bind(ig.KEY.LEFT_ARROW, 'left'); ig.input.bind(ig.KEY.RIGHT_ARROW, 'right'); ig.input.bind(ig.KEY.X, 'jump'); ig.input.bind(ig.KEY.C, 'shoot'); // Touch buttons var ypos = ig.system.height - 60; this.buttons = [ new ig.TouchButton('left', 0, ypos, 60, 60, this.leftButton), new ig.TouchButton('right', 60, ypos, 60, 60, this.rightButton), new ig.TouchButton('shoot', ig.system.width-120, ypos, 60, 60, this.shootButton), new ig.TouchButton('jump', ig.system.width-60, ypos, 60, 60, this.jumpButton), ]; // ... }, update: function() { // ... }, draw: function() { // Draw all entities and backgroundMaps this.parent(); // ... for(var i = 0; i < this.buttons.length; i++) { this.buttons[i].draw(); } } });