Issue with EaselJS
Issue with EaselJS
我用EaselJS开发TD游戏,遇到了一个问题。当敌人来到城堡时,他应该以 uniq 延迟开始攻击它。(例如女巫:3秒,元素:2秒等)如何使用启用的股票代码设置此延迟?
createjs.Ticker.on("tick", moveTick);
createjs.Ticker.setFPS(20);
console.log(mobs);
function moveTick(event) {
for (var i = 0; i < mobs.length; i++) {
if (mobs[i].y > stage.canvas.height - castle.castleHeight - mobs[i].elemSize) {
setTimeout(console.log("attacking"), 600000);
} else {
mobs[i].y = mobs[i].y + mobs[i].movementSpeed;
}
}
field.update(event);
}
由于您知道在执行操作之前要等待多少秒,并且知道程序每秒将运行多少帧,因此您可以做的是在执行操作之前计算帧数。
计算帧数的一个好方法是维护一个刻度计数器,并在计数器为正数时递减计数器,然后在计数器达到 0 时执行操作。下面是一个代码示例,部分利用了您的代码,了解其工作原理:
createjs.Ticker.on("tick", moveTick);
createjs.Ticker.setFPS(20);
console.log(mobs);
// note that enemy_ticker would probably be a property of your enemy object:
var enemy_ticker = -1;
function moveTick(event) {
if (event that causes enemy to attack soon) {
enemy_ticker = 60; // this gives us 3 seconds
}
if (enemy_ticker > 0) {
enemy_ticker--;
} else if (enemy_ticker = 0) {
enemy_ticker--;
// put your code to start your enemy's attack here
}
field.update(event);
}
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- how to split a string with ','
- Understanding Javascript scope with "var that = this&qu
- Architecture for CPU intensive tasks with NodeJS & Socke
- How to declare a Map containing certain properties with flow
- 在EaselJS中设置精灵表动画时出现问题
- 设置'这'在React with Inverse Data Flow中
- Unit-testing multiple use cases with Karma & Mocha.js
- problems with EaselJS getCacheDataURL
- EaselJS with TweenJS with MovieClip
- Issue with EaselJS