Adding sprites on touch

Hello EveryBody ,

I want to ask about adding sprites on touch … I’ve written this code the entire statements works outside the eventListener while it doesn’t inside it

    var self = this;

cc.eventManager.addListener({
event : cc.EventListener.TOUCH_ONE_BY_ONE,

        onTouchBegan: function(touch , event){
             x = touch.getLocation().x;
             y = touch.getLocation().y;
            console.log(x ,y);
            node = new cc.Node("New Sprite");
            sprite = node.addComponent(cc.Sprite);
            node.parent = this.node;
            texture = cc.textureCache.addImage(url);
            sprite.spriteFrame = new cc.SpriteFrame(texture);
            node.setPosition(x,y);
            return true;
        },
        
  },self.node);
},

Not an expert here, but I think that your solution might be to use self instead of this inside of your onTouchBegan function, e.g. node.parent = self.node;

Inside onTouchBegan, this refers to your touch listener and not your node.