
cc.Class({
extends: cc.Component,
properties: {
},
onLoad () {
},
start () {
},
update (dt) {
if(game.isBgMove==true){
this.node.y = this.node.y-2;
}
if(this.node.y<=-600){
game.on_enemy_1_killed(this.node);
}
},
die(){
var anim = this.getComponent(cc.Animation);
anim.play("enemy1_die_animation_clip");
}
}); onCollisionEnter(other,self){
console.log("碰到了");
if(self.tag==0){
game.onBulletKilled(self.node);
}
if(other.tag==1){
var js = other.node.getComponent("enemy_1");
if(js){
js.die();
}
}
},敌机代码加
cc.Class({
extends: cc.Component,
properties: {
},
onLoad () {
this.isDie = false;
},
start () {
},
update (dt) {
if(game.isBgMove==true){
this.node.y = this.node.y-2;
}
if(this.node.y<=-600){
game.on_enemy_1_killed(this.node);
}
},
die(){
this.isDie = true;
var anim = this.getComponent(cc.Animation);
anim.play("enemy1_die_animation_clip");
}
});子弹代码加
onCollisionEnter(other,self){
console.log("碰到了");
if(self.tag==0){
game.onBulletKilled(self.node);
}
if(other.tag==1){
var js = other.node.getComponent("enemy_1");
if(js&&js.isDie==false){
js.die();
}
}
},
右击编辑 在funcion输入框架中输入 over

在敌机中写代码
die(){
this.isDie = true;
var anim = this.getComponent(cc.Animation);
anim.play("enemy1_die_animation_clip");
anim.over = function(){
game.on_enemy_1_killed(this.node);
}
},从而得出结论,敌机在对象池创建后 上面的参数也保留的有。

添加初化代码。


init(){
this.isDie = false;
var anim = this.getComponent(cc.Animation);
anim.play("enemy_1_normal_Animation_clip");
}game。js创建敌机时 执行init方法

站长微信:xiaomao0055
站长QQ:14496453