Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Attanar

In my player.js file I have this:

    init: function(x,y,settings){
        
        this.parent(x,y,settings);
        
        this.addAnim('idle',0.1,[0]);
        this.vel.x = 300;
        
        // Referencia para acceder a la instancia desde el juego
        ig.game.player = this;

In my main.js I have this:

this.player.jump();

The game starts without any errors or warnins. Yet, when I do something that calls the jump, I get this error:

Uncaught TypeError: Cannot call method 'jump' of undefined


How can player be undefined, if I already referenced it? In the code examples that seems to work fine.

1 decade ago by Joncom

Can you please give a little more context/code surrounding the line:
this.player.jump();

1 decade ago by Attanar

OK forget it, I solved the problem.

In case it can help someone in the future, the problem was this.player.jump() was called inside a callback function, so "this" was not a reference to the game object.
Page 1 of 1
« first « previous next › last »