Jump to content

button help!


dthrasher90
 Share

Recommended Posts

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

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

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


            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

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

          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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...