Jump to content

Problem with Tweens


totallybueno
 Share

Recommended Posts

Hi there, I´m starting with Phaser and I´m having some kind of problem with tweens, the console is giving me this error "TypeError: this._object is undefined" and here´s my code:

 

<script type="text/javascript">
        var game;
        var fondo, iconoAcierto, iconoError;
        
        game = new Phaser.Game(383, 511, Phaser.AUTO, '', { preload: preload, create: create, update: update });
        
        function preload(){
            fondo = game.load.image("iconoAcierto", "assets/iconoAcierto.png");
        }
        function create(){
            game.add.sprite(margen,0,"iconoAcierto");

            var tween = game.add.tween(iconoAcierto);
            tween.to({y: 200}, 2000);
            tween.start();

        }
        function update(){

        }
    </script>

 

 

Also, do I need to have this line in the <head> of the doc?
<script src="src/tween/Tween.js"></script>

 

 

Thanks in advance.

Link to comment
Share on other sites

You don't need Tween.js in the html, no. Just phaser.js

 

The problem is that Tween expects to be given an object it can actually tween. In your example all you need do is this:

var theSprite = game.add.sprite(0, 0, 'iconoAcierto');var tween = game.add.tween(theSprite);tween.to( { y: 200 }, 2000);tween.start();
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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