[Resolved] Beginner question on setPosition with variable

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({
    currentX:300,
    ctor:function(){
        this._super(); 
        this.initWithFile("images/jet.png");
    },
    update:function(dt){
        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

    },
    handleKey:function(e)
    {
        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.

:slight_smile:

Now I feel really silly.

Thanks for the help.

/Johan