版本:cocos2d-js-3.0
平台:Android
问题:会定时卡顿下,有解决方案么
代码:
var QyScene = cc.Scene.extend({
ctor: function() {
this._super();
this.addChild(new QyLayer());
}
});
var QyLayer = cc.Layer.extend({
ctor: function() {
this._super();
var bgSprite = cc.Sprite.create('res/levelbg_1.jpg');
bgSprite.setAnchorPoint(cc.p(0, 0));
this.addChild(bgSprite);
var plane = new QyPlane();
this.addChild(plane);
}
});
var QyBullet = cc.Sprite.extend({
ctor: function() {
this._super("res/major_bullet_3.png");
this.setPosition(cc.p(Math.random() * 1000, this.getContentSize().height / 2));
this.scheduleUpdate();
},
update: function(dt) {
var pos = cc.pMult(cc.p(0, 1000), dt);
this.setPosition(cc.pAdd(pos, this.getPosition()));
if (this.getPositionY() > 1024) {
this.removeFromParent();
}
}
});
var QyPlane = cc.Sprite.extend({
ctor: function() {
this._super("res/enemy_1.png");
this.setPosition(cc.p(320, this.getContentSize().height / 2));
this.setFlippedY(true);
this.getScheduler().scheduleCallbackForTarget(this, function function_name(dt) {
for (var i = 0; i < 20; i++) {
this.getParent().addChild(new QyBullet());
}
}.bind(this), 0.1, cc.REPEAT_FOREVER, 0, false);
}
});
```