Answer the question
In order to leave comments, you need to log in
What programming pattern to use in this situation?
I have already made a prototype game in es6 and I have a problem.
In short, there is only one unit class in the game and many instances of this class. And everything suited me until I decided to add my own skins for each unit.
Each skin is not just a sprite, but a certain combination of sprites and other things.
Initially, the structure looked like this
Game Loop: unit1 = new Unit();
Unit Class
class Unit() {
var blabla = blabla
head = new Skin('HEAD');
arrayOfBody = new array;
for (i = 0; i > 10; i++){
child = new Skin('BODY');
array.push(child);
}
}
unit1 = new Unit('Skin10');
class Unit(Skin) {
this.Skin = Skin;
var blabla = blabla
head = new Skin(this.Skin,'HEAD');
arrayOfBody = new array;
for (i = 0; i > 10; i++){
child = new Skin(this.Skin, 'BODY');
array.push(child);
}
}
Answer the question
In order to leave comments, you need to log in
What patterns are commonly used in this situation?Builder is most suitable here .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question