Jump to content

calling tweens in other functions


dthrasher90
 Share

Recommended Posts

Ok cool thanks, I may have to try that.  Basically I had one function that loaded a bunch of tweens and then exeucted them.  I want to break that up and have a button execute them instead.  So, I was going to try and load them in the functions and execute with another.  Curently they run as a closure, but I want to get another button to start the tween movement.   

  function passPlayRight(){

                      var ct = this.game.add.sprite(400, 220, 'ct');
                                ct.scale.setTo(0.03);

                      var QBx = ct.x - 20;
                      var QBy = ct.y;
                      var qb = this.game.add.sprite(QBx, QBy, 'qb');
                                qb.scale.setTo(0.02);

                      var RGx = ct.x;
                      var RGy = ct.y + 20;

                      var rg = this.game.add.sprite(RGx, RGy, 'rg');
                                rg.scale.setTo(0.03);

                      var RTx = ct.x;
                      var RTy = rg.y + 20;

                      var rt = this.game.add.sprite(RTx, RTy, 'rt');
                                rt.scale.setTo(0.03);

                      var LGx = ct.x;
                      var LGy = ct.y - 20;


                      var lg = this.game.add.sprite(LGx, LGy, 'lg');
                                lg.scale.setTo(0.03);


                      var LTx = ct.x;
                      var LTy = lg.y - 20;

                      var lt = this.game.add.sprite(LTx, LTy ,'lt');
                                lt.scale.setTo(0.03);


                      var WR1x = ct.x;
                      var WR1y = rt.y + 100;
                      var wr1 = this.game.add.sprite(WR1x, WR1y, 'wr1');
                                wr1.scale.setTo(0.02);


                      var WR2x = ct.x -20;
                      var WR2y = ct.y + 50;
                      var wr2 = this.game.add.sprite(WR2x, WR2y, 'wr2');
                                wr2.scale.setTo(0.02);

                      var WR3x = ct.x - 20;
                      var WR3y = rt.y + 50;
                      var wr3 = this.game.add.sprite(WR3x, WR3y, 'wr3');
                                 wr3.scale.setTo(0.02);




                    var tweenA = game.add.tween(wr1).to({x: '+200'}, 3000);


                    var tweenB = game.add.tween(wr2).to({x: '+50', y: '+50'},2000);
                    var tweenB2= game.add.tween(wr2).to({y: '+50'}, 2000);
                    tweenB.chain(tweenB2);

                    var tweenC = game.add.tween(wr3).to({x: '+100'}, 2000);
                    var tweenC2 = game.add.tween(wr3).to({y: '+50'}, 2000);
                    tweenC.chain(tweenC2);


                    var tweenD = game.add.tween(lt).to({x:  '-35'}, 2000);
                    var tweenE = game.add.tween(rt).to({x:  '-35'}, 2000)
                    var tweenF = game.add.tween(lg).to({x:  '-20'}, 2000);
                    var tweenG = game.add.tween(rg).to({x:  '-20'}, 2000);

                    var tweenH = game.add.tween(qb).to({x:  '-50'},  1800);



                    var tweenFootballA =game.add.tween(football).to({x: '+35', y: '+50'}, 3000);
                    var tweenFootballB =game.add.tween(football).to({x: '+100',y:  '+50'}, 3000);
                    var tweenFootballC =game.add.tween(football).to({x: '+200'}, 3000);

                    tweenA.start();
                    tweenB.start();
                    tweenC.start();
                    tweenD.start();
                    tweenE.start();
                    tweenF.start();
                    tweenG.start();
                    tweenH.start();
                    qbPass();

                        function qbPass() {
                              var x = Math.floor((Math.random() * 3) + 1);
                              console.log(x);
                              switch (x){

                                case 1:

                                    tweenFootballA.start();
                                    console.log('1');
                                    break;

                                case 2:
                                    tweenFootballB.start();
                                    console.log('2');
                                    break;

                                case 3:
                                    tweenFootballC.start();
                                    console.log('3');
                                    break;

                              }

                            }
                      }

.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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