10.07.2015 Views

A Tutorial: NextWeb- Adobe CreateJS Toolkit; Export ... - fen-om data

A Tutorial: NextWeb- Adobe CreateJS Toolkit; Export ... - fen-om data

A Tutorial: NextWeb- Adobe CreateJS Toolkit; Export ... - fen-om data

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}var platypus = eventObj.target.parent.parent;platypus.gotoAndPlay("pop");function handleBalloonPopped(platypus) {platypus.falling = true;}And refer to them in the ticker function:platypus.platypusIdle.balloon.onClick = handleBalloonClick;platypus.onPopped = handleBalloonPopped;Now the platypus needs to fall to its death when the balloon pops. For that, we just need to add anaccelerating Y velocity to the basic platypus movement (which currently only involves X across thescreen):if (platypus.falling) { platypus.velY += 3; }Finally, let's get s<strong>om</strong>e points for that shot! Add this function:function updateScore(delta) {score = Math.max(0,score + delta);exportRoot.scoreTxt.text = "SCORE: "+score;}And refer to it in the ticker function (basic platypus movement):if (platypus.y > 450) {platypii.splice(i,1);exportRoot.removeChild(platypus);updateScore(100);}Yes, we get points, not when the balloon pops, but when the platypus crosses the bott<strong>om</strong> of the screen.That's so that we can get points and remove the platypus fr<strong>om</strong> memory, all at the same time. And wecan actually expand this same boundary-detection code to include the case where the platypus reachesthe left edge of the screen: (also remove fr<strong>om</strong> memory, but don't add points)if (platypus.x < -platypus.n<strong>om</strong>inalBounds.width*platypus.scaleX || platypus.y > 450) {platypii.splice(i,1);exportRoot.removeChild(platypus);// add +100 points if it fell or 0 if it escapedupdateScore(platypus.y > 400 ? 100 : -500);}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!