dthrasher90 Posted March 14, 2017 Share Posted March 14, 2017 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 More sharing options...
samme Posted March 15, 2017 Share Posted March 15, 2017 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 More sharing options...
Recommended Posts