Answer the question
In order to leave comments, you need to log in
How to reuse sprites for shapes in a game like match3?
Good afternoon, I study the game engine at my leisure and decided to write a simple game in the match3 genre for practice.
Suppose we have a playing field 10 by 10. Accordingly, in the cycle I create 100 shapes from the prefab. I also have a sprite (atlas) with 8 types of shapes. I want to allocate memory for 100 shapes and 8 sprites once, and as the player destroys them on the screen, change their type, position and sprite and display them again. How is this usually resolved? This suggests a simple solution to change the sprite through the code or use 8 states and change through the animation mechanism. But all methods seem crooked. How to solve it correctly?
Answer the question
In order to leave comments, you need to log in
Usually not sprites are cached, but entire gameobjects.
A cache controller is being made, which the GO that is not currently using turns off, but leaves on the stage. You need to create a new object - ask the controller to create, and he looks - whether he has an object of the desired type or not. If there is, just turn it on. If not, it creates a standard Instantiate.
In order not to change the sprite through the code, you can make not 1 prefab, but a prefab for each type of element for your game.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question