How do I create sprite object instance that look different

Just started using Construct 2? Post your questions here

Post » Tue Jul 19, 2016 10:22 am

I have one type of enemy. They all have the same instance variables values. They all act the same, have the same health etc... and they spawn in every few seconds. How do I make it so that they spawn in with a slightly different looking uniform (different color)? Do I have to create a different object type of each different enemy color, even though they are really all the same (except for their look) or is there a simple way to make each new instance of the same object type look different?

Thank you
B
9
S
3
G
2
Posts: 13
Reputation: 1,601

Post » Tue Jul 19, 2016 1:35 pm

@neoflash1979
There are many ways to go about this.

You should add an instance variable for your sprites appearance: ex. Enemy.Skin.
Now when you spawn your Enemy, add the action: set value of Enemy.Skin to choose("blue", "red", "green"....)

If you plan on increasing the number of appearances, you might consider storing that info on an array and calling it by: set value of Enemy.Skin to SkinArray.At(ceil(random(0, (SkinArray.Width)))-1)

Name your animations according to the skin names you might choose ex.: "blue", "red", "green"...
Don't forget to call your Enemy's animation in the spawning process:
Set animation to Enemy.Skin

Does your enemy sprite need more than one animation to run? If so:
Change your animation names from "Running", "Shooting", etc to "BlueRunning", "RedRunning", RedShooting"

Set the animation to Enemy.Skin&Enemy.Action (Assuming Enemy.Action is the instance variable that dictates your sprites action states).

Of course, if your sprite does not animate (has only one frame) you can just add difference frames, set animation speed to 0 and randomly choose a frame to be set to.

I hope this helps!
B
16
S
9
G
5
Posts: 74
Reputation: 4,120

Post » Tue Jul 19, 2016 2:44 pm

Brilliant! That is exactly what I was looking for. Thank you.
B
9
S
3
G
2
Posts: 13
Reputation: 1,601


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest