so I have a player script, an enemy script, a food pick-up script, and a spawner script for enemy/pick-up. So the player gets 1 exp every time they hit the food pick-up and for every 10 exp, they gain a level. all this works fine. Here is the problem that I can figure out. When my player levels up, I want the sprite to change to the food sprite, the enemy sprite to change to the player, and then the enemy sprite to a new sprite.
You need to be more clear on what exactly you mean here. I understand that you want the sprite of certain nodes changed. However, I don’t see in what way these sprites should be changed when you say “the enemy sprite to change to the player”; what does that mean?
Is your goal simply to change the sprite of a set of nodes when your player levels up?
okay, I’ll try my best to explain am very new. There are always 3 sprites on the screen: player, food, and enemy. Each one of these has its scene made up of characterbody2d, animatedsprite2d (each with a sprite sheet), collision, and area2d. So when the player eats the food they get 1exp after 10 exp I want them to level up. When the player levels up I want his sprite to turn into the enemy sprite, and the player sprite to because of the new food also the enemy sprite would become a new sprite. It is an evaluation-themed game.
I simply don’t understand what you’re trying to say here. The enemy’s sprite should get switched to a new one – okay – but this: “the player sprite to because of the new food also…”. What?! Didn’t you just say that the player’s sprite should be switched to the enemy’s sprite?
Okay. Just so I’m sure I know what you mean, you want:
Player sprite → enemy sprite
Food sprite → player sprite
Enemy sprite → unknown sprite
If this is indeed what you’re looking to achieve, it looks to me like the sprites for different entity types (e.g. player, enemy, food etc.) is offset on level up. In other words, a queue with constant length where the front is dequeued, and the back is enqueued. You can use an Array as a queue through its functions: pop_front() and push_back().
Here is an example:
@export var sprite_queue: Array
# This is the queue which contains references to the sprites for your current level.
func level_up():
var new_sprite: Texture2D # The "unknown sprite"
sprite_queue.pop_front() # Remove the front entry
sprite_queue.push_back(new_sprite) # Add the new sprite in the back
You would need to store the “queue” in a place that is globally accessible. Perhaps an autoload would be useful in this regard. Each entity would now have to reference a specific index in this sprite_queue. You could even implement a signal that lets your nodes (player, food etc.) know when to update their sprite.
Let me know if you have any questions regarding my proposed approach to your problem.
Thank you. With me being very new some of that made cents to me, but a lot of it didn’t. So being that each one (player, food, enemy) are different scene will I have to make an array on each one? and the player would need an animation sheet for each new level.
No. As I said, you would need to store the array in a place that is globally accessible. Please read my previous reply.
Yes, but new members have restrictions which only disappear after some time. Since you recently joined, I don’t think you can share more than one picture. You’ll find out.
Listen, there’s nothing wrong with asking questions – this whole post is just getting a little repetitive when you don’t proof read your own posts and don’t read my full replies.
Given that you’re new to Godot, I would recommend looking up some beginner tutorials so you can get a grasp on the basics. Godot has their own tutorial(s) in the documentation (click here).
If there’s anything else you need help with, let me know. Otherwise, good luck!
Sorry if this has been answered and I’m just not understanding it. But I didn’t think arrays could hold animatedsprit2ds as my player, food and enemy have animations. again sorry if I’m misunderstanding you.
In the case of an AnimatedSprite2D, I assume you would want to store the SpriteFrames resources in the array since that is the data that determines what is displayed.
An Array can contain pretty much any type of data though. An array is just a way of structuring the data.
You’re not misunderstanding me. You are just still new to programming which leaves you unfamiliar with why things are the way they are. That’s why it’s important to ask questions!