How do I code skins efficiently?

Get help using Construct 2

Post » Fri Nov 04, 2016 10:15 pm

Hello!

First off, I already searched a bit in this Forum but didn't get the answer I was looking for.
I am working on a 2D moba and adding some skins. For now I just copy / paste the complete coding block of 1 character and replace every "classic" character with a new sprite which is his skin.

Is there a better way to implement skins in my game? For example a condition where you just replace all objects of a projects with an other. So character "Blue skin" is chosen, replace every classic sprite with the sprite of the blue skin or something like that.

Making different animation is also kind of odd. And I guess I still would have the same amount of code as I got now.

So is there any good solution for adding chooseable skins in a game?
B
13
S
2
Posts: 80
Reputation: 821

Post » Fri Nov 04, 2016 10:22 pm

Well with the different animations you could just keep the same sprite object and 'play' the different skins? Having each character separated isn't a bad thing either but to minimize it I guess you would do it with animations so the character object is the same but they 'look different'. If you're changing all characters to blue when blue is chosen (just trying to picture the game) I guess you could set each blue animation to be called 'blueskin' and then make all characters set the 'blueskin' animation when blue is selected.

When you say making animations is kind of odd, what do you mean? Surely the animations need to exist already to display the skin?
B
47
S
17
G
81
Posts: 2,227
Reputation: 48,101

Post » Fri Nov 04, 2016 10:28 pm

@plinkie
I also thought that but I would need new animations for walking, jumping etc too...
Right now when I swap a skin, the skin has the same named animations, that's why I don't have to change it in the coding.

So I had to change everything to "set Player1 Animation to blue_walk", "blue_jump" etc.
Maybe you have a better overview when I show you my game...At the beginning you can chose a skin.

https://kingdanius.itch.io/league-of-pixels-2d-moba
B
13
S
2
Posts: 80
Reputation: 821

Post » Fri Nov 04, 2016 10:55 pm

From looking at the game, because you are spawning a new character in I guess I would spawn whichever object is required, where each character is a separate sprite object. You can group all of the character stuff in a family. If you create the characters as separate objects including blue variants then add them all into a family, you can assign the movement controls to the family just the one time. Each object will have its own animations that correspond with the default names, so archer has jump and equally blue archer has jump. In terms of code it'll be a few events, the work will come with the separate objects.
B
47
S
17
G
81
Posts: 2,227
Reputation: 48,101

Post » Fri Nov 04, 2016 11:37 pm

The free edition doesn't have families, though. But with something as big as a MOBA, I would start to look into some serious data structures. Just looking at what you need, here's an idea:

-Make all your characters one object with a bunch of different animations.
-Make an array with the names of all the different animations (e.g., P1Walk, P1Idle, P2Walk...). Put different character types along the X axis and different actions (walk, idle, etc) along the Y.
-Give the character a number variable for which character it is and another for what it's doing.
-When you want a character to do an action, have the events change the value of the action variable.
-Finally, add an event like this one:

Every Tick - Characters play animation array.at(Characters.identity, Characters.action) from current frame
Eh, Steve!
B
115
S
54
G
13
Posts: 113
Reputation: 16,151

Post » Fri Nov 04, 2016 11:54 pm

@calebbennetts
Thank you for the tip, I will try something of it (if I am able to xD )
B
13
S
2
Posts: 80
Reputation: 821

Post » Sat Nov 05, 2016 11:11 am

Hmm I didn't see any mention of free version only. Making a MOBA with the free version, restricted layers, 100 events and no families seems like a bit of a challenge, you would just be tying your hands behind your back. Your game is showing some promise so I would suggest purchasing a C2 license rather than creating a load of workarounds for what I explained can be only a few events. The workarounds themselves are going to make you start pushing toward that 100 event cap anyway.
B
47
S
17
G
81
Posts: 2,227
Reputation: 48,101


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests