js cocos 中鼠标点击事件调用其它方法出错, uncaught typeerror: undefined is not a function 5

代码如下:/***CreatedbyAdministratoron2014/9/30.*/varShooter=cc.Sprite.extend({speed:100,H... 代码如下:
/**
* Created by Administrator on 2014/9/30.
*/

var Shooter=cc.Sprite.extend({
speed:100,
HP:5,
layer:null,
ctor:function(layer,x,y){
this._super("#ship03.png");
this.tag = this.zOrder;
this.x = x;
this.y = y;
this.scale=1;
this.layer=layer;
this.shootBullet(this.x,this.y);
this.addMouse();
},
addMouse: function () {
if ('mouse' in cc.sys.capabilities) {
cc.eventManager.addListener({
event: cc.EventListener.MOUSE,
onMouseDown: function (event) {
cc.log("shoot MOUSE DOWN EVENT");
this.shootBullet(this.x,this.y);
},
onMouseUp: function (event) {
cc.log("shoot MOUSE UP EVENT");
}
}, this);
cc.log("ADD shoot MOUSE");
} else {
cc.log("MOUSE Not supported");
}
},
//添加子弹,并且向上移动;
shootBullet: function (x,y) {
cc.log("Bullet shooted");
var Bullet = new Bullets(x, y);
Bullet.setTag(1);
Bullet.Move();
Bullet.setTag(6);
this.layer.addChild(Bullet, 2);
this.layer._bullets.push(Bullet);
GC.FILE = false;
}
});
在点击事件中调用this.shootBullet时报错,估计在Listener中this指针已经发生变化,但是不知道解决方法,望大神相助~~
展开
 我来答
前端报错
2014-10-10 · 前端开发技术分享,分析
前端报错
采纳数:1573 获赞数:7026

向TA提问 私信TA
展开全部
/**
 * Created by Administrator on 2014/9/30.
 */
var Shooter = cc.Sprite.extend({
    speed: 100,
    HP: 5,
    layer: null,
   拆滑 ctor: function(layer, x, y) {
        this._super("#ship03.png");
        this.tag = this.zOrder;
        this.x = x;
        this.y = y;
        this.scale = 1;
        this.layer = layer;
        this.shootBullet(this.x, this.y);
        this.addMouse();
    },
    addMouse: function() {
        var 祥腊that = this; //缓存this指针
        if ('mouse' in cc.sys.capabilities) {
            cc.eventManager.addListener({
                event: cc.EventListener.MOUSE,
                onMouseDown: function(event) {
            旅宴腊        cc.log("shoot MOUSE DOWN EVENT");
                    that.shootBullet(that.x, that.y);
                },
                onMouseUp: function(event) {
                    cc.log("shoot MOUSE UP EVENT");
                }
            }, that);
            cc.log("ADD shoot MOUSE");
        } else {
            cc.log("MOUSE Not supported");
        }
    },
    //添加子弹,并且向上移动;
    shootBullet: function(x, y) {
        cc.log("Bullet shooted");
        var Bullet = new Bullets(x, y);
        Bullet.setTag(1);
        Bullet.Move();
        Bullet.setTag(6);
        this.layer.addChild(Bullet, 2);
        this.layer._bullets.push(Bullet);
        GC.FILE = false;
    }
});
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式