Jump to content

Animations in prefab does not works like expected


PeterC
 Share

Recommended Posts

Hi,

 

I'm creating a 3d/2d world.

I'm trying to create prefab so it's easy to structure and re-use the code.

 

I found a weird issue with prefabs that is using animations.

 

You expect that when you create a object of your class in your state, you mostly provide the parameter with "this" that stands for the game object:

 

    this.pl1 = new PL1(this, this.loadMap.playx, this.loadMap.playy);
    this.add.existing(this.pl1);

 

In the prefab class i'm adding my animation:

    this.animations.add('left', [1,2], 10, true);

but as soon when i run the game, it will raise an error:

http://screencast.com/t/GICvrV1x
 

This will happen only when i'm using animations.

 

The solution at this moment that i found (as weird as it sounds) is to create the object class like this:

    this.pl1 = new PL1(this.game, this.loadMap.playx, this.loadMap.playy);

 

I'm just adding this.game instead of this, this only works for prefab classes that having animations included.

 

This class also has 'use strict'; at the top, like all the other prefab classes.

 

 

Is there another way to solve this issue? Because at this moment i can't use global variables in my player class, because it's using another game object.

 

 

Grtz,

Peter

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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