I want to make an “inventory”, something like that:
with items which icons are stored in one big atlas image.
Each item of the inventory is a Sprite. If I want to use atlas I can add a Tilemap+Tile into each Sprite to make item ico visible, but something tells me it’s a bad idea to create many tilemaps. Is there any other way to add item ico from atlas into a sprite without creating a new Bitmap for each Sprite?
Tilemap inherits from DisplayObject, so you could just create one Tilemap instance (defining the bounding rectangle), and add one Tile for each picture.
Reminder : 1 Tilemap = 1 draw call
you can always copy a partial bitmap, that is why people always have sprite atlas arrays, with the array of rectangles to subset when drawing.
At first I wanted to do so, to use only one Tilemap. But we’ve decided to imlement items drag’n drop + items tooltips (mouseOver event). And it’ll be a bit complicated to do with Tilemap. As I understand there is no way I can catch mouse events on Tiles.
Do you mean .copyPixels() from sprite atlas?
you can put the mouse event on Stage and check if the mouse coordinates are inside a Tile by looping through Tilemap children.
To handle drag & drop, you may create a temporary Sprite during mouse movement, so it’d just cost 1 extra draw call while dragging.
Ok, definitely got some good ideas, thanks!