flame-engine / flame

A Flutter based game engine.
https://flame-engine.org
MIT License
9.23k stars 901 forks source link

Direct access to tiled images (Sprites) #2900

Closed Mythar closed 10 months ago

Mythar commented 10 months ago

Problem to solve

I would like to have direct access to the the images used by tiled. For now i have to make a SpriteSheet like:

finale ss = SpriteSheet( image: images.fromCache('../tilesets/../../images/world/tiles/ground.png'), srcSize: { some size } );

Proposal

It would be nice to have something like:

Sprite = TiledComponent.getSprite('ground.png', 1, 1);

More information

I had to do an override of Images _assets as : "Map<String, _ImageAsset> get getAssets => _assets" to find the key to the image:

images.getAssets.forEach((key, value) { print(key); });

spydon commented 10 months ago

Interesting, what is the use-case?

ufrshubham commented 10 months ago

TiledComponent creates atlases on the fly using all the images used by the tilemap. So it will require some bookeeping if you want to get the individual images. You can already access these atlases using TiledComponent.atlases

erickzanardo commented 10 months ago

I believe you can just pass a Images instances to the RenderableTiledMap.from method , so all the images loaded by flame tiled, will be stored on the cache of that instance that you have control of

Mythar commented 10 months ago

TiledComponent dose not have "atlases" property.

Its just easier to just TiledComponent.load for the tmx file to load all :)

I want to re-use the "tiles" as sprites. As an example If a player wants to plant a new tree in his garden, a tree sprite would be added and the player could then drag the tree to a tile. Having a TiledComponent.getSprite would make it easier :)

ufrshubham commented 10 months ago

TiledComponent dose not have "atlases" property.

It does: https://github.com/flame-engine/flame/blob/caf2b90930ca500c85b9f9f63e7d3d7a5d82c18e/packages/flame_tiled/lib/src/tiled_component.dart#L206 Maybe you are on a older flame version?

Sprite = TiledComponent.getSprite('ground.png', 1, 1);

I am not sure how that would work internally. Should the tilemap store a list of all the images even though an atlas was created out of it? And what does the (1, 1) represent?

Mythar commented 10 months ago

Im using:

flame: ^1.10.1 flame_tiled: ^1.17.0

I must be on an older version. With access to atlas, getSprite is not needed