Heppell08 Posted April 3, 2014 Share Posted April 3, 2014 I've looked at gamecontroller js and i'm pretty happy with how it works, the only problem i have is using it to call a function.I has the touchmove and the a jump button has a touchstart function.My problem is that my jump is very specific. Not for just going up or down but it depends on what the gravity is doing and there the player is and what the player is 'touching'. I tried to copy the update code i use for jumping and placing it in a simple function then calling it on the jump button from the gamecontrollers touchscreen button provided.Problem is i get a weird error saying that: Uncaught TypeError: Object #<t> has no method 'jump' Game.js:297 Now on line 297 i have:GameController.init( { left: { type: 'joystick', touchMove: function(joystick_details) { this.input.joystickLeft = joystick_details; }, touchEnd: function() { this.input.joystickLeft = null; } }, right: { position: { right: '5%' }, type: 'buttons', buttons: [ { label: 'jump', fontSize: 13, touchStart: function() { this.jump(); } }, false, false, false ] } } );So in the code above i put it as the numbers are in my game and you see i just has this.jump();Now i battled last night with this but was too late to keep testing with it and didnt post this last last night.I also tried putting just jump(); but its not defined, i tried this.player.jump(); but cant call jump. I'm using a state set up and not a single js file. Any help/exmaple etc are highly appreciated. Thanks Link to comment Share on other sites More sharing options...
Heppell08 Posted April 3, 2014 Author Share Posted April 3, 2014 Ok I got it working by writing the function inside the function and calling it after the inner function so its just jump(); with a function jump function() { // logic }. My next mission is to get the left/right of the thumbsticks working for my left/right walking. Link to comment Share on other sites More sharing options...
valueerror Posted April 3, 2014 Share Posted April 3, 2014 maybe this helps:GameController.init({ left: { type:'joystick', joystick: { touchMove: function(details){ if (details.dx < -5){left=true;} else if (details.dx > 5){right=true;} else {left=false;right=false;} if (details.dy < -5){ duck=true;} else{duck=false;} renderdetailsx=details.dx; renderdetailsy=details.dy; }, touchEnd: function() {left=false;right=false;duck=false;} } }, right: { position: {right: 60,bottom: 60}, type: 'buttons', buttons: [ { label: 'B', fontSize: 13, touchStart: function() { jump=true;}, touchEnd: function() { jump=false; } }, { label: 'A', fontSize: 13, touchStart: function() { fire=true;}, touchEnd: function() { fire=false; } }, false, false ] }, });and in the update function i just check the vars (up,down,left,right,jump,fire) and do whatever is needed... and if you decide to trash gamecontroller js (because of minor bugs with the buttons and low performance ^^): http://www.html5gamedevs.com/topic/1813-the-monthly-phaser-examples-contest/?p=27173 Link to comment Share on other sites More sharing options...
Heppell08 Posted April 3, 2014 Author Share Posted April 3, 2014 Yeah i looked at your button example, pretty nice set up. Also the posted code you sent worked!! thanks it was scratching my head a bit with the code but got it full added with your snippet! Thanks Link to comment Share on other sites More sharing options...
valueerror Posted April 4, 2014 Share Posted April 4, 2014 glad i could help Link to comment Share on other sites More sharing options...
Recommended Posts