Creating 2nd entity vs Creating additional animation within the same entity

Bruce

Active member
Hello everyone,

As far as performance or/and memory usage,
which method is better?

1. Create an additional animation within the same entity and use the script below to call out the animation:

Code:
@cmd    spawn01 "Fireball" 0 0 0 openborconstant("ANI_idle2")

Code:
void spawn01(void EntityName, float fX, float fY, float fZ, int AnimID)
{
    ...
    ...
    if(AnimID != NULL()){performattack(vSpawn, AnimID);}
}

Fireball:
Code:
name          Fireball
type         none
gfxshadow     1 3
candamage    enemy obstacle shot

anim    idle
    loop        1
    followanim    1
    followcond    1 
    hitflash    flash
    hitfx    data/sounds/beat3.wav
    attackone    1
    fastattack    1
    offset    55 40
    bbox    0 0 0 0
    delay    4
    move    40
    attack1     30 13 138 132 10 0 1 0 30 120
    frame    data/chars/Test/Fireball/idle01.png
    frame    data/chars/Test/Fireball/idle02.png
    frame    data/chars/Test/Fireball/idle03.png
    frame    data/chars/Test/Fireball/idle04.png
    frame    data/chars/Test/Fireball/idle05.png
    frame    data/chars/Test/Fireball/idle06.png
    frame    data/chars/Test/Fireball/idle07.png
    frame    data/chars/Test/Fireball/idle08.png
    frame    data/chars/Test/Fireball/idle09.png
    @cmd    NextSkill openborconstant("ANI_FOLLOW1")
    frame    data/chars/Test/Fireball/idle10.png   
    
anim    idle2
    loop        1
    followanim    1
    followcond    1 
    hitflash    flash
    hitfx    data/sounds/beat3.wav
    attackone    1
    fastattack    1
    offset    55 40
    bbox    0 0 0 0
    delay    4
    move    40
    attack1     30 13 138 132 10 0 1 0 35 120
    frame    data/chars/Test/Fireball/idle201.png
    frame    data/chars/Test/Fireball/idle202.png
    frame    data/chars/Test/Fireball/idle203.png
    frame    data/chars/Test/Fireball/idle204.png
    frame    data/chars/Test/Fireball/idle205.png
    frame    data/chars/Test/Fireball/idle206.png
    frame    data/chars/Test/Fireball/idle207.png
    frame    data/chars/Test/Fireball/idle208.png
    frame    data/chars/Test/Fireball/idle209.png
    @cmd    NextSkill openborconstant("ANI_FOLLOW1")
    frame    data/chars/Test/Fireball/idle210.png   
    
    
anim    follow1
    loop        0
    attackone    0
    hitflash    flash
    hitfx    data/sounds/beat3.wav
    offset    240 110
    bbox    0 0 0 0
    delay    3
    move    40   
    frame    data/chars/Test/Fireball/FB_BlowUp01.png
    frame    data/chars/Test/Fireball/FB_BlowUp02.png
    frame    data/chars/Test/Fireball/FB_BlowUp03.png
    frame    data/chars/Test/Fireball/FB_BlowUp04.png
    frame    data/chars/Test/Fireball/FB_BlowUp05.png
    frame    data/chars/Test/Fireball/FB_BlowUp06.png
    frame    data/chars/Test/Fireball/FB_BlowUp07.png
    frame    data/chars/Test/Fireball/FB_BlowUp08.png
    frame    data/chars/Test/Fireball/FB_BlowUp09.png
    attack1     176 50 254 234 5 0 1 0 5 120
    frame    data/chars/Test/Fireball/FB_BlowUp10.png
    delay    5
    @cmd    killentity getlocalvar("self")
    frame    data/chars/misc/empty.png

or

2. Create a 2nd Entity and declare it on the model:
Code:
name          Fireball2
type         none
gfxshadow     1 3
candamage    enemy obstacle shot

anim    idle
    loop        1
    followanim    1
    followcond    1
    hitflash    flash
    hitfx    data/sounds/beat3.wav
    attackone    1
    fastattack    1
    offset    55 40
    bbox    0 0 0 0
    delay    4
    move    40
    attack1     30 13 138 132 10 0 1 0 30 120
    frame    data/chars/Test/Fireball/idle201.png
    frame    data/chars/Test/Fireball/idle202.png
    frame    data/chars/Test/Fireball/idle203.png
    frame    data/chars/Test/Fireball/idle204.png
    frame    data/chars/Test/Fireball/idle205.png
    frame    data/chars/Test/Fireball/idle206.png
    frame    data/chars/Test/Fireball/idle207.png
    frame    data/chars/Test/Fireball/idle208.png
    frame    data/chars/Test/Fireball/idle209.png
    @cmd    NextSkill openborconstant("ANI_FOLLOW1")
    frame    data/chars/Test/Fireball/idle210.png   
    
    
anim    follow1
    loop        0
    attackone    0
    hitflash    flash
    hitfx    data/sounds/beat3.wav
    offset    240 110
    bbox    0 0 0 0
    delay    3
    move    40   
    frame    data/chars/Test/Fireball/FB_BlowUp01.png
    frame    data/chars/Test/Fireball/FB_BlowUp02.png
    frame    data/chars/Test/Fireball/FB_BlowUp03.png
    frame    data/chars/Test/Fireball/FB_BlowUp04.png
    frame    data/chars/Test/Fireball/FB_BlowUp05.png
    frame    data/chars/Test/Fireball/FB_BlowUp06.png
    frame    data/chars/Test/Fireball/FB_BlowUp07.png
    frame    data/chars/Test/Fireball/FB_BlowUp08.png
    frame    data/chars/Test/Fireball/FB_BlowUp09.png
    attack1     176 50 254 234 5 0 1 0 5 120
    frame    data/chars/Test/Fireball/FB_BlowUp10.png
    delay    5
    @cmd    killentity getlocalvar("self")
    frame    data/chars/misc/empty.png

I like the first method, but I want to make sure it does not hurt the performance or/and memory usage,

Thank you so much
 
Honestly, I just create a new entity only if:

- I have a good reason why*
- It will be easier to handle (when you start to have many conditions to check, its better to have a new entity. Or hitflashes.)
If not, I just make a different animation on the same entity.

*But there is a catch: I used to make one single entity to handle different type of effects. This could work if its an entity which will be active all the time (IOW, an entity which you LOAD on models.txt and never unload it, like flashes), but will have the opposite effect if not.

To explain better, imagine that you have an entity that is a dust effect that you use all the time and, inside it, you create an animation of a fire effect that you will use very few times during a level or just a single character will use that animation.

In this case, creating a second entity would be more advantageous, as you can unload it from memory when you are no longer using it.

Currently, I unload all enemies I use after the level. Even though this technically increases the load time (I honestly found it minimal), it helps to consume less memory and made things simpler for me - because before I had to think about whether I was going to use a certain enemy in the next phase and, if so, Otherwise, I would unload it.

So I just use this:

spawn max 1
coords 150 190
at 0

It's way better to unload entities using this instead of :

load max 3
as Kratus discovered a bug which causes a silent crash (with no trace in the log), probably a null pointer.

The only side effect is: if you are using OpenBORstats, you won't see the entity on the stage preview anymore. But this doesn't happens in CMT.
 
Honestly, I just create a new entity only if:

- I have a good reason why*
- It will be easier to handle (when you start to have many conditions to check, its better to have a new entity. Or hitflashes.)
If not, I just make a different animation on the same entity.

*But there is a catch: I used to make one single entity to handle different type of effects. This could work if its an entity which will be active all the time (IOW, an entity which you LOAD on models.txt and never unload it, like flashes), but will have the opposite effect if not.

To explain better, imagine that you have an entity that is a dust effect that you use all the time and, inside it, you create an animation of a fire effect that you will use very few times during a level or just a single character will use that animation.

In this case, creating a second entity would be more advantageous, as you can unload it from memory when you are no longer using it.

Currently, I unload all enemies I use after the level. Even though this technically increases the load time (I honestly found it minimal), it helps to consume less memory and made things simpler for me - because before I had to think about whether I was going to use a certain enemy in the next phase and, if so, Otherwise, I would unload it.

So I just use this:



It's way better to unload entities using this instead of :


as Kratus discovered a bug which causes a silent crash (with no trace in the log), probably a null pointer.

The only side effect is: if you are using OpenBORstats, you won't see the entity on the stage preview anymore. But this doesn't happens in CMT.
If I understood it correctly, once the entity is loaded, the images from all animations will be kept in the memory regardless if the 2nd animation is being used or not?

For example,
this entity has 2 idles:

idle1
idle2

If I only use idle1, the system will still keep all the images from both animations in the memory regardless?

Also, you mentioned about unloading:
If I use this function @cmd spawn01 "Fireball" 0 0 0 openborconstant("ANI_idle2")
do I need to unload it, how?

I really appreciate for your help, thank you
 
If I understood it correctly, once the entity is loaded, the images from all animations will be kept in the memory regardless if the 2nd animation is being used or not?
if you LOAD the entity, yes. The engine doesn't care (neither it should) if you are using all the animations on a loaded entity.

Also, you mentioned about unloading:
If I use this function @cmd spawn01 "Fireball" 0 0 0 openborconstant("ANI_idle2")
do I need to unload it, how?
I won't unload a projectile like that, personally speaking. Unless I would use that fireball in only one entity and in just one specific case.
Or it would cause more harm than good (like you forgetting that you unload it and trying to spawning it later).

ah, two things:
- it shold be ANI_IDLE2, in uppercase
- Using IDLE2 is a bad idea, are you aware how aditional IDLEs work? They work by proximity - so there is a chance of your entity to use IDLE2 when it should not. I would use FOLLOW2 if I was you.
 
if you LOAD the entity, yes. The engine doesn't care (neither it should) if you are using all the animations on a loaded entity.


I won't unload a projectile like that, personally speaking. Unless I would use that fireball in only one entity and in just one specific case.
Or it would cause more harm than good (like you forgetting that you unload it and trying to spawning it later).

ah, two things:
- it shold be ANI_IDLE2, in uppercase
- Using IDLE2 is a bad idea, are you aware how aditional IDLEs work? They work by proximity - so there is a chance of your entity to use IDLE2 when it should not. I would use FOLLOW2 if I was you.
Ahh, I am so glad that I asked. I saw they used multiple animations in 1 entity from a template and I thought it was neat.
I guess I will just stick with the old fashion way - create more entity then unless all animations are being used all the time.
Thank you
 
I guess I will just stick with the old fashion way - create more entity then unless all animations are being used all the time.
I suggest you to think about it first. Sometimes its better to have one entity for multiple animations.

For example, on my Avengers game, I have a circle of dust using just a set of sprites. When I want them to be rotated, instead of creating new entities (or worse, rotating the sprites myself), I just made mutiple animations with different angles (8) and I call the the same entity using different animations.

This saved me the work to make 8 different entities ;)
 
Back
Top Bottom