Nicotico Posted December 4, 2018 Share Posted December 4, 2018 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; } Link to comment Share on other sites More sharing options...
Aguacero Posted December 4, 2018 Share Posted December 4, 2018 Probably use game.add.sprite instead of this.add.sprite Intenta usar game.add.sprite en lugar de this.add.sprite Link to comment Share on other sites More sharing options...
Nicotico Posted December 4, 2018 Author Share Posted December 4, 2018 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 More sharing options...
samme Posted December 4, 2018 Share Posted December 4, 2018 2 hours ago, Nicotico said: Uncaught TypeError: Can not read property 'sprite' of undefined (undefined).sprite(vaso.body.x, vaso.body.y, 'vidaExtra') Link to comment Share on other sites More sharing options...
Nicotico Posted December 4, 2018 Author Share Posted December 4, 2018 Hello samme, I also did not have luck with that option, it keeps throwing "Can not read property 'sprite' of undefined" Link to comment Share on other sites More sharing options...
Recommended Posts