Good afternoon How can you change the sprite during the game? I tried to do this using a global variable. I walk into a store in another scene. I’m shopping for a new sprite. I change the global variable there. Then I return to the previous scene. I check if the variable =1 then I control the tarelka sprite, if the variable =2 then I create the purchased sprite on the stage and delete the tarelka sprite. A new sprite is created but key control is not transferred to it. It’s something like a player shot with a pistol and bought a machine gun to shoot with it. But I can’t change a pistol to a machine gun during the game. or is this done via sprite animation? And you don’t need to change the sprites themselves?
What’s wrong?
Did you check if the variable Cursor is changing?
You need a trigger once when creating Tarelka as well, if not it’ll be created multiple times.
If the variable is changing then it should work. Both objects would have to have the same active behaviors.
Another way is with an object group. You could place the objects in a group. Add and delete from the scene but you would reference them with the group name. That way, you would only need 1 set of control events.
You can use the same object with different animations. Instead of a number, I would use the character’s name. You put all the animations into 1 sprite, name the animations with a consistent format like cat_left, cat_up or whatever and then matching dog_left and dog_up…
Then anywhere you set the animation, you set it by name and use the global variable to create the animation name.
Using global string variable pet
Set pet to “cat”
Something like:
Change animation of pet to GlobalVariableString(pet ) + “_left”
If you’re using an extension to set the animation then you would update the extension.
I haven’t quite figured out the debugger yet, but the variable changes for sure. When changing a variable, I called the animation by number. When variable =2 then play animation 1. It works. But I would like to understand why that code does not work or maybe I did the wrong subevents in the photo above.
Are your sprites being created?
Yes. The sprite is created. But I did it this way. I added several animations and simply play another animation, in which there is already a different picture
If your sprite Tarelka is already in the scene at the beginning, you don’t need create it.
If it’s not, you need to use a trigger once, to avoid creating it multiple times.
How did you assign value 1 to your variable Cursor?
The cursor changes depending on which picture the player selects in the second scene. The second scene is the same store. If he selects picture 3, then we assign the value 3 to the cursor. And then we return to the stage and check what the cursor is equal to, depending on the number in the variable, we play the animation of the same sprite
But I’ve already remade the game. Previously, I controlled the cursor, but now I just use the buttons to move the sprite. As soon as I entered the store, I clicked on the desired sprite and assigned the sprite number to the cursor variable. I’m going back. I check the cursor variable and play an animation with this number.