Adding action to a subclassed sprite

  • fechox
    Likes 0

    Problem Description

    Hi,
    I'm new to Cocos2d-JS and I'm having problems when subclassing cc.Sprite; I have the following simple game layer:

    --------------------------------------------------------------------------
    var GameLayer = cc.Layer.extend({
        ballSprite:null,
        
        ctor:function () {
            this._super();
            this.init();
        },

        init:function () {
            this._super();
            this.ballSprite=new aBall();
            this.addChild(this.ballSprite);


        }
        
    });
    --------------------------------------------------------------------------

    and this is the aBall subclass:

    var aBall = cc.Sprite.extend({
        
        ctor:function() { 
            this._super(); 
            this.initWithFile(res.aBall1_png);
        },

        onEnter:function(){
            this._super;
            this.setPosition(500, 500);
            var moveAction=cc.MoveTo.create(4,cc.p(0,500));
            this.runAction(moveAction);

        },
    })

    --------------------------------------------------------------------------------

    I have a PlyScene:

    var PlayScene = cc.Scene.extend({
        
        onEnter:function () {
            this._super();
            add three layer in the right order
            this.addChild(new BackgroundLayer());
            this.addChild(new GameLayer());
        },
    });

    The problem is that the ball won't move at all, it positions fine on the screen but the runAction has no effect at all and the ball remains static at the initial coordinates.
     What am I doing wrong?

  • Sonar Systems admin
    Likes 0

    try replacing this

    this.runAction(moveAction);

    with

    aBall.runAction(moveAction);

     


    This reply has been verified.
  • fechox
    Likes 0

    Thank You!


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    Your welcome :D

Login to reply