Jump to content

update question


dthrasher90
 Share

Recommended Posts

  function movePlayer(){

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


                tweenA.start();
                tweenB.start();
                tweenC.start();

                var tweenFootball = game.add.tween(football).to( {x: '+200', y: '-20'},500, "Linear", true, 2500);
                tweenFootball.onComplete.add(logCoord, this); function logCoord() {
                  console.log(football.body.x, football.body.y);



                }

I am creating a javascript football game and this block of code, simulates a completed pass, where the football just moves to the wr1 location.  I want to create a line of scrimmage variable, that will update to the new location of the football once the play has been completed.  Assuming that the catch was made, where and how do I tell it to update the line scrimmage position.  Does that go in the update functions???

Link to comment
Share on other sites

Think you can do something like

var football;
var lineOfScrimmage;
// […]

function movePlayer () {
  // […]
  var tweenFootball = game.add.tween(football).to({x: '+200', y: '-20'}, 500, 'Linear', true, 2500);
  tweenFootball.onComplete.add(onTweenFootballComplete, this);
}

function onTweenFootballComplete () {
  lineOfScrimmage = football.x;
  console.log('Line of scrimmage is now ', lineOfScrimmage);
}

function update () {
  // Play starts from
  lineOfScrimmage;
  // …
}

 

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...