Jump to content

Last sprite of a spritesheet not showing


Durden
 Share

Recommended Posts

Hey,

I've been learning my way around Phaser for a week for a personal project, I resolved almost every bug I had until now with older posts from this forum (thanks A LOT to all of you), but I'm stuck with one I found no solution for.

I have 8 "information signs" I want to add to the background in different places, all looking alike but with slight changes to each (basically, the text on each sign is different). I made a spritesheet with all 8 signs, preloaded it, and then I added some of the signs like this :

var skillsSign = this.game.add.sprite(80, 20, 'guidance'),
            experienceSign = this.game.add.sprite(this.game.width - 64 - 90 - 16, 20, 'guidance'),
            contactSign = this.game.add.sprite(this.game.width - 90, this.game.height - 128 - 40, 'guidance'),
            formationSign = this.game.add.sprite(0, this.game.height - 128 - 40, 'guidance');
        
        skillsSign.frame = 1;
        experienceSign.frame = 5;
        contactSign.frame = 6;
        formationSign.frame = 7; //problem is with this one

The first three work as intended, but the last one, which is the last of the sprites in the spritesheet, appears as the first. I can put 0 instead of 7 in the last statement and get the same result. 

I checked, every single sign is working as intended, except this 8th sprite appearing as the 1st.

 

Any idea what causes this ? Also, if that's not at all the best way to go for what I want to do, I'm open to any advices :) 

Link to comment
Share on other sites

This way :

this.load.spritesheet('guidance', 'assets/img/tilesheet-guidance.png', 90, 26, -1, 0, 4);

(by the way, the .png file's height is 30px, but for some reason if I try to put any number >= 27 instead of 26 in my statement, the sprite sheet freaks out and the page displays the full sprite sheet, I have no clue why it behaves like that)

Link to comment
Share on other sites

Those dimensions (90x26 with 4px spacing) don't match the PNG you posted above, because the final frame in it is only 90px wide (needs to be 94) - if you just add 4px to the png it should be fine. Personally I'd recommend you use texture atlases (avoids issues like this and packs more in!)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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