Handling Multiple Actors (using clones)
Posted: Thu Feb 05, 2009 5:18 pm
Sometimes handling many actors can be a bother, but you must learn to deal with CLONES in order to make successful games.
You will find, over time, that you can reduce the number of actors each time you make a game, and that doing so will reduce the complexity and difficulty in programming your game.
Here are two basic examples of cloning vs. new actor creation.
#1. Powerups.
Ok, so you got a health powerup, a weapons powerup, an ammo powerup, an extra life powerup....these should be 1 cloned actor.
Simply add an animation, 'healthp', for instance. to the powerup actor. Add another animation...'weaponp'.
Powerup>CreateActor>
Now player>collision>any side>powerup
Animindex refers to the # of the animation in the animation list; the first animation you add is 0, etc. etc.
Now you have one actor for unlimited powerup types, and only 1 create actor, and only 1 collision to deal with.
Much much much easier than having multiple powerup actors!!!!!!!
#2. Text Meters.
You might have a text actor displaying a variables, such as score.
textactor>DrawActor>
You can reuse that actor too! Try cloning it and:
textactor>DrawActor>
Also, when you create text, DO NOT USE COLORS. Make text WHITE, then on textactor>createactor, set the rgb values. In this way you can make an unlimited number of colors with only 1 font! The more fonts you use, the more likely you are to experience errors.
Using these methods will greaty increase the running speed of your game, the ease of programming/changing script, and as well the handling of other variables(like ZDEPTH).
If the coding involved in the case switch seems like a pain when you're a beginner, you'll soon find that the amount of time it saves and the amount of power and flexibility it offers is more than worth it. Take time to familiarize yourself with the case switch, it is vital to making complex games.
If you've never used a case switch, here is the syntax:
all 'case x' must be followed by a colon :
all 'break' must be followed by a semicolon ;
Also, you can omit cases you won't be needing. If you don't want to take any action when the variable is 0, you can simply omit case 0 from the switch, and start with case 1 instead.
You will find, over time, that you can reduce the number of actors each time you make a game, and that doing so will reduce the complexity and difficulty in programming your game.
Here are two basic examples of cloning vs. new actor creation.
#1. Powerups.
Ok, so you got a health powerup, a weapons powerup, an ammo powerup, an extra life powerup....these should be 1 cloned actor.
Simply add an animation, 'healthp', for instance. to the powerup actor. Add another animation...'weaponp'.
Powerup>CreateActor>
- Code: Select all
type=rand(2);
switch(type){
case 0:
ChangeAnimation("Event Actor", "healthp", FORWARD);
break;
case 1:
ChangeAnimation("Event Actor", "weaponp", FORWARD);
break;
}
Now player>collision>any side>powerup
- Code: Select all
switch(collide.animindex){
case 0:
health+=3;
break;
case 1:
weapon+=1;
break;
}
DestroyActor("Collide Actor");
Animindex refers to the # of the animation in the animation list; the first animation you add is 0, etc. etc.
Now you have one actor for unlimited powerup types, and only 1 create actor, and only 1 collision to deal with.
Much much much easier than having multiple powerup actors!!!!!!!
#2. Text Meters.
You might have a text actor displaying a variables, such as score.
textactor>DrawActor>
- Code: Select all
textNumber=score;
You can reuse that actor too! Try cloning it and:
textactor>DrawActor>
- Code: Select all
switch(cloneindex){
case 0:
textNumber=score;
break;
case 1:
textNumber=lives;
break;
case 2:
textNumber=time;
break;
}
Also, when you create text, DO NOT USE COLORS. Make text WHITE, then on textactor>createactor, set the rgb values. In this way you can make an unlimited number of colors with only 1 font! The more fonts you use, the more likely you are to experience errors.
Using these methods will greaty increase the running speed of your game, the ease of programming/changing script, and as well the handling of other variables(like ZDEPTH).
If the coding involved in the case switch seems like a pain when you're a beginner, you'll soon find that the amount of time it saves and the amount of power and flexibility it offers is more than worth it. Take time to familiarize yourself with the case switch, it is vital to making complex games.
If you've never used a case switch, here is the syntax:
- Code: Select all
switch (variablenametobechecked){
case 0:
action here
break;
case 1:
action here
break;
}
all 'case x' must be followed by a colon :
all 'break' must be followed by a semicolon ;
Also, you can omit cases you won't be needing. If you don't want to take any action when the variable is 0, you can simply omit case 0 from the switch, and start with case 1 instead.