Jump to content

PRoblem with load animatiorn to one object from two file


P4nch0
 Share

Recommended Posts

Hello,

I have a problem with load animation from two files to one obecjt.

Load files to the game:

    this.load.spritesheet('cowwalk', 'assets/images/animal/cow_walk.png',128,128);
    this.load.spritesheet('coweat', 'assets/images/animal/cow_eat.png',128,128);

 

Create object from file cowwalk:

 

this.cow =this.animal.create(zwierzex, zwierzey, 'cowwalk');

 

Adding animation to object:

    this.cow.animations.add('cowleft',[7,6,5,4]);
    this.cow.animations.add('cowright', [12, 13, 14, 15]);
    this.cow.animations.add('cowdown', [8, 9, 10, 11]);
    this.cow.animations.add('cowup', [0, 1, 2, 3]);
    this.cow.animations.add('coweatleft', [7,6,5,4]);
    this.cow.animations.add('coweatright', [12, 13, 14, 15]);
    this.cow.animations.add('coweatdown', [8, 9, 10, 11]);
    this.cow.animations.add('coweatup', [0, 1, 2, 3]);    
      

 

Animation walk i going well, but please tell my now, how to add animation coweat to the object, and them chose wich animation shoud be play? I must create animal from obect coweat or what?

Maybe i should to compile two files to one and them add? Please give me some ideas :)

Link to comment
Share on other sites

I'm not so sure about if you can create it from two files, maybe it's possible, or maybe you'll need one object per file.

But the object is only looking for the animation where you've told it to look (cowwalk spritesheet):

this.cow =this.animal.create(zwierzex, zwierzey, 'cowwalk');

But in general, I'd say compile all related objects and images into a single spritesheet, and even everything into one spritesheet because it's easier to load. Anything you can do to speed up the loading times is a good investment.

This tool (link here) is great, using the JSON-TP-Array. And this site has all the information in a tutorial (link here).

Link to comment
Share on other sites

Short Answer:
Create a single sprite sheet.

Long Answer:
While I certainly don't know why would you need to have two spreadsheets, it is certainly possible. Create a new object with two phaser sprite objects each for two animation mode. Create methods to start different animations, or use a single method with parameters to decide which animation to play. When eating animations are playing set visibility of the object with moving animation to false, when moving animation is playing, set visibility of the object with eating animations to false.


I'd suggest you merge both spritesheets.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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