Sprites not displaying correctly when updating from 4.1.0 to 4.4.1

Hello everyone,

I decided to update OpenFl from 4.1.0 to 4.4.1, but suddenly, everything from my spritesheet are not displaying correctly. I was wondering if someone can tell me what are the big differences between those two versions.

I’m thinking that maybe it has something to do with how Tile and Tilemap are working? Maybe it’s something with a certain width/height of a specific container of my sprites?

Thank you for your thinking! :slight_smile:

The Tilemap API has grown in consistency since earlier versions

A couple things that might be worth checking:

  • Make sure the tilemap.width or height are large enough to frame all the content you are using
  • See if the tilemap is scaled, the behavior of scaleX and scaleY changed to be more consistent with other objects
  • Make sure you use a default tileset when you construct your tilemap, or set tile.tileset for your tiles

Thanks for your reply!

I checked all that, but everything was fine. I managed to find a solution, but I am wondering if this is normal.

For a frame by frame animation, everytime a frame is changing, I delete the current sprite:


And then calculate a new position on X and Y for the next sprite to display. (from informations I get from the software TexturePacker)

Then, here’s what I was doing in 4.1.0:

tilemap.addTile(new Tile(value, posX, posY));

In 4.4.1, this is not working and I need to keep the new tile at 0,0 and change the X and Y of the tilemap:

tilemap.x = posX;
tilemap.y = posY;
tilemap.addTile(new Tile(value, 0, 0));

Now, every static sprites and animated sprites are displayed perfectly!

Is this okay the way I did it?

What if you change the tile.x, tile.y and tile.id, rather than removing and adding?

That might work, I’ll try that soon.

Thanks for your lightning fast answers! :slight_smile:

I tried your suggestion with no success… By changing tile.x, tile.y and tile.id, I have the same problem and I don’t see my sprites. I sometime see the bottom right of a sprite, like if the container is misplaced and start in the center to reveal the bottom right.

Here’s what I do…
I create and set my tileset for all the different sprites:

tileset = new Tileset(Assets.getBitmapData(spritesheet_path));

for (i in 0...spritesheet.length) {
tileset.addRect(new Rectangle(spritesheet[i].frame.x, spritesheet[i].frame.y, spritesheet[i].frame.w, spritesheet[i].frame.h));


Then, in another class, I create my tilemap and my tile:

tilemap = new Tilemap(800, 600, tileset, false);

tilemap.addTile(new Tile());

After that, for my frame by frame animation, I try to change the id, x and y:

tilemap.getTileAt(0).id = value;

tilemap.getTileAt(0).x = posX;
tilemap.getTileAt(0).y = posY;

Maybe I’m missing something here or I don’t really understand how Tilemaps work?

The fact that I wasn’t seeing all my sprites and only the bottom right is because the sprite was in the top left corner of the tilemap, so I did an offset, so the tile can be created in the middle and it worked. What do you think?

tilemap = new Tilemap(800, 600, TexturePacker.tileset, false);
tilemap.x = -400;
tilemap.y = -300;
tilemap.addTile(new Tile(0, 400, 300));

I suppose changing the ID instead of removing and adding tiles is faster for the computer to compute?

Yeah, changing id should be super cheap, and not cause garbage collection :slight_smile:

It’s not that you can’t create a new Tile, but the garbage collection costs could add up if you do it a lot

Then I’m glad I was able to upgrade my code! Thanks for the help and explanations! :slight_smile: