Nicotico

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');
game.physics.arcade.enable(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;
game._vasoGroup.add(vaso);
vaso.body.gravity.y = Juego.gravedadVaso;

},

agarraVaso: function(vaso){

vaso.kill();
Juego._vidas += 1;
Juego._vidasText.setText(Juego._vidas);
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.animations.play('mas_vida');
this.physics.arcade.enable(this.vidaExtra);
this.vidaExtra.body.velocity.y -= 100;

}

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.