[Resolved] Beginner question on setPosition with variable

[Resolved] Beginner question on setPosition with variable
0.0 0


Hi everyone

I am just getting started with the basics of cocos2d-html. I am used to programming in C and Java but not Javascript so I get stuck on some basic things.

To start with I am trying to follow a tutorial and I want to move a sprite left and right on the screen with the keyboard and I have this code.

var JetSprite = cc.Sprite.extend({
        this.setPosition(100, 300);  //This works
        this.setPosition(currentX, 300);  //This does not work and I do not get why, tried to create a Point but same result

        if(e === cc.KEY.left)
            this.currentX = this.currentX - 10;
        else if(e === cc.KEY.right)

So, the problem is that when trying to pass a variable to setPosition, it does not work. Anyone able to tell me why?

Thanks in advance


use this.currentX in your update.



Now I feel really silly.

Thanks for the help.