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;, 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);'mas_vida');
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.

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.


  • Recently Browsing   0 members

    No registered users viewing this page.