dthrasher90 Posted March 6, 2017 Share Posted March 6, 2017 Is this button logic set correctly? var button = this.game.add.button(game.world.centerX, 500, 'button', this.action, this, 0,0,0); button.scale.setTo(0.5); }, action: function(){ move(); }, update: function(){} }; function move(){ alert("button pressed"); tweenA = game.add.tween(wr1).to({x:400}, 2000); } Link to comment Share on other sites More sharing options...
dthrasher90 Posted March 6, 2017 Author Share Posted March 6, 2017 The game wont move the sprite, instead, it renders a violation handler took 1754 of runtime Link to comment Share on other sites More sharing options...
dthrasher90 Posted March 6, 2017 Author Share Posted March 6, 2017 I realized tween start method wasnt there, updated it and it still renders the same response. Link to comment Share on other sites More sharing options...
NewGuy Posted March 7, 2017 Share Posted March 7, 2017 var button = this.game.add.button(game.world.centerX, 500, 'button', action, this, 0,0,0); button.scale.setTo(0.5); function action() { move(); } function move(){ alert("button pressed"); tweenA = game.add.tween(wr1).to({x:400}, 2000); } Try this? Kinda hard to know where you're working from Link to comment Share on other sites More sharing options...
dthrasher90 Posted March 7, 2017 Author Share Posted March 7, 2017 No, it didnt like that. Link to comment Share on other sites More sharing options...
dthrasher90 Posted March 7, 2017 Author Share Posted March 7, 2017 I can get it to fire off the alter the other way, but it also gives me these errors and the tweens wont run. [Violation] Handler took 219ms of runtime (150ms allowed) [Violation] Long running JavaScript task took 638ms phaser.min.js:12 [Violation] Handler took 824ms of runtime (150ms allowed) [Violation] Long running JavaScript task took 826ms Link to comment Share on other sites More sharing options...
samme Posted March 7, 2017 Share Posted March 7, 2017 Start with examples/v2/buttons/action-on-click . Add your changes one at a time. scheffgames 1 Link to comment Share on other sites More sharing options...
dthrasher90 Posted March 7, 2017 Author Share Posted March 7, 2017 var wr1, wr2, wr3, wr4; var game = new Phaser.Game(800, 600, Phaser.AUTO); var GameActionState = { preload: function(){ game.load.image('field', 'field.png'); game.load.image('wr1', 'reddot.png'); game.load.image('wr2', 'reddot.png'); game.load.image('wr3', 'reddot.png'); game.load.image('wr4', 'reddot.png'); game.load.image('qb', 'reddot.png'); game.load.image('football','football.png'); game.load.image('button', 'button.jpg'); }, create: function(wr1){ game.physics.startSystem(Phaser.Physics.ARCADE); var field = game.add.sprite(game.world.centerX, game.world.centerY, 'field'); field.scale.setTo(2.75); field.anchor.setTo(0.5); var wr1 = this.game.add.sprite(500, 100, 'wr1'); wr1.scale.setTo(0.5); var wr2 = this.game.add.sprite(500, 300, 'wr2'); wr2.scale.setTo(0.5); var wr3 = this.game.add.sprite(500, 400, 'wr3'); wr3.scale.setTo(0.5); var wr4 = this.game.add.sprite(500, 455, 'wr4'); wr4.scale.setTo(0.5); var qb = this.game.add.sprite(500, 300, 'qb'); qb.scale.setTo(0.5); var football = this.game.add.sprite(500, 300, 'football'); football.scale.setTo(0.1); var button = this.game.add.button(game.world.centerX, 500, 'button', this.actionOnClick, this, 0,0,0); button.scale.setTo(0.5); game.physics.arcade.enable(wr1, wr2, wr3, wr4); }, actionOnClick: function(){ alert("button pressed"); var tween = game.add.tween('wr3'); tween.to({x: '+300'}, 3000); tween.start(); // var tweenA = game.add.tween('wr1').to({x: '-200' }, 1000); // tweenA.start(); }, update: function(){ } }; game.state.add('GameActionState', GameActionState); game.state.start('GameActionState'); Still no luck, here is the entirety of the code. The sprite still doesnt move on the button click, but the alert fires with this portion. Link to comment Share on other sites More sharing options...
dthrasher90 Posted March 7, 2017 Author Share Posted March 7, 2017 Do the functions have to be set as objects? Thats how I saw one tutorial work it. Link to comment Share on other sites More sharing options...
dthrasher90 Posted March 7, 2017 Author Share Posted March 7, 2017 I got it to work this way. this is more conve var wr2 = this.game.add.sprite(500, 300, 'wr2'); wr2.scale.setTo(0.5); var wr3 = this.game.add.sprite(500, 400, 'wr3'); wr3.scale.setTo(0.5); var wr4 = this.game.add.sprite(500, 455, 'wr4'); wr4.scale.setTo(0.5); var qb = this.game.add.sprite(500, 300, 'qb'); qb.scale.setTo(0.5); var football = this.game.add.sprite(500, 300, 'football'); football.scale.setTo(0.1); var button = this.game.add.button(game.world.centerX, 500, 'button', function(){ alert("button pressed"); var tween = game.add.tween(wr3); tween.to({x: '+300'}, 3000); tween.start(); }, this, 0,0,0); button.scale.setTo(0.5); game.physics.arcade.enable(wr1, wr2, wr3, wr4); nient Link to comment Share on other sites More sharing options...
dthrasher90 Posted March 7, 2017 Author Share Posted March 7, 2017 var button = this.game.add.button(game.world.centerX, 500, 'button', function(){ alert("button pressed"); var tween = game.add.tween(wr1); tween.to({x: '+30'}, 1000); var tween1 = game.add.tween(wr2); tween.to({x: '+30'}, 3000); var tween2 = game.add.tween(wr3); tween.to({x: '+30'}, 3000); tween.start(); tween1.start(); tween2.start(); }, this, 0,0,0); My next question, is it possible to fire off all these tweens simultaneously when the button is pressed? As of mow tween is the only one to move Link to comment Share on other sites More sharing options...
Recommended Posts