Я вызываю метод и хочу ссылаться на спрайт объекта вне метода с .javascript передать метод объекта
Адрес Этот объект в объекте предоставляет только переданный объект события. Я пытаюсь получить доступ к this.sprite в moveSprite: функция
var roomMap = cc.Layer.extend({
sprite:null,
listener:null,
ctor:function(){
this._super();
this.init();
},
init: function() {
this._super();
this.sprite = new cc.Sprite.create("#player-stand-f-0");
this.sprite.setPosition(new cc.Point(300,300));
this.addChild(this.sprite);
this.listener = cc.EventListener.create({
onMouseDown: function(event) {
cc.log("onMouseDown");
},
onMouseUp: this.moveSprite
});
cc.eventManager.addListener(this.listener, this);
return this;
},
moveSprite:function(event){
cc.log("mouse up: "+event.getLocationX() + "mouse move: "+event.getLocationY());
console.log(this);
var sprite_action = cc.MoveTo(2,cc.p(event.getLocationX(),event.getLocationY()));
this.sprite.runAction(sprite_action);
this.addChild(sprite_action);
}
});
Вы должны объяснить, какая библиотека вы используете. Где документация? –
@JuanMendes: Как это выглядит: http://cocos2d-x.org/docs/manual/framework/html5/v3/eventManager/en –