Jump to content

Problems to add sprite


Recommended Posts

Good morning everyone, I hope the translator is as accurate as possible to make me understand.

The problem I have is the following, I have an object (vaso) that falls through the screen (soltarVaso), when I click, the event onInputDown executes another function (agarraVaso), I want a sprite (heart) to appear on the screen that I won a Extra life (vidaExtra) but the following error appears: Uncaught TypeError: Can not read property 'sprite' of undefined and I can not understand where I have the error.

Could you give me a hand please, thank you very much!


soltarVaso: function(game){
var dropPos = Math.floor(Math.random()*Juego.GAME_WIDTH);
var vaso = game.add.sprite(dropPos, 0, 'vaso');
vaso.inputEnabled = true;
vaso.events.onInputDown.add(this.agarraVaso, this);
vaso.checkWorldBounds = true;
vaso.anchor.setTo(0.5, 0.5);
vaso.rotateMe = (Math.random()*2)-2;
vaso.body.gravity.y = Juego.gravedadVaso;


agarraVaso: function(vaso){

Juego._vidas += 1;
this.vidaExtra = this.add.sprite(vaso.body.x, vaso.body.y, 'vidaExtra'); //here shows me the error
this.vidaExtra.animations.add('mas_vida', [0,1,2,3,4], 10, false);
this.vidaExtra.body.velocity.y -= 100;



Link to comment
Share on other sites

Hello Aguacero, I had already tried that, if I add "game" as function in the function it keeps throwing me "Can not read the property 'sprite' of undefined" if it is not available or is not acceptable game as I throw the following error: game is not defined

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...