html5中如何js,如何在波动中移动html5(createjs)中的对象

我正在从这里学习html5和画布互动

这是代码的一部分

function handleComplete() {

exportRoot = new lib.PlatypusGame();

exportRoot.removeChild(exportRoot.platypus);

stage = new Stage(canvas);

stage.addChild(exportRoot);

Touch.enable(stage);

Ticker.setFPS(20);

// add the listener to window, so we can do some work before updating the stage:

Ticker.addListener(window);

}

function tick() {

if (platypii.length < 1 || Math.random() < 0.01 && platypii.length < 5) {

var platypus = new lib.Platypus();

platypus.scaleX = platypus.scaleY = Math.random()*0.3+0.3;

platypus.x = 800;

// nominalBounds holds the dimensions of the first frame of the symbol at export time.

platypus.y = Math.random()*(400-platypus.scaleY*platypus.nominalBounds.height);

platypus.velX = (1+platypus.scaleX)*-6;

platypus.velY = 0;

// we only want to know about clicks on the balloon, not the whole platypus:

platypus.platypusIdle.balloon.onClick = handleBalloonClick;

platypus.onPopped = handleBalloonPopped;

platypii.push(platypus);

exportRoot.addChild(platypus);

}

// go in reverse to make it easier to splice items from the array

for (var i=platypii.length-1; i>=0; i--) {

platypus = platypii[i];

// add gravity to the Y velocity if it's falling:

if (platypus.falling) { platypus.velY += 3; }

platypus.x += platypus.velX;

platypus.y += platypus.velY;

if (platypus.x < -platypus.nominalBounds.width*platypus.scaleX || platypus.y > 400) {

platypii.splice(i,1);

exportRoot.removeChild(platypus);

// add +100 points if it fell or -500 if it escaped

updateScore(platypus.y > 400 ? 100 : -500);

}

}

stage.update();

}

我试图通过改变platypus.velY = 0来改变Platypus进入波浪状态。 to platypus.velY = Math.sin(platypus.x)* 5; ,但没有成功,任何想法?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值