Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 984 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Yet another blending code #87187
08/23/06 13:56
08/23/06 13:56
Joined: Jul 2005
Posts: 366
eleroux Offline OP
Senior Member
eleroux  Offline OP
Senior Member

Joined: Jul 2005
Posts: 366
I just wanted to share this code I came with while playing with ent_blendpose.

I know blendpose is slower than ent_blend, but we are talking about just a few frames, and I think there are other advantages.

What I like in this is that the animation that is blending-in starts animating right away (no wait for the blend to end), and that the code ended up ridiculously simple. (To tell the truth I had no idea it would end this way when I started coding)

Be aware that this is not ready-to-use. It doesn't include the functions for setting up strings and animations, or entity physics - I just provide it as a general idea of using ent_blendpose.

Code:


Function mAnim_Animate_Actor()
{

mAnim_initSceneStrings(); //setup animation strings

var base_scene = 1;
var base_scene_old = 1;
var base_mode = 0; //cyclic, one time, one time no blend
var base_cycle = 0;

var base_anim = 0;
var base_anim_old = 0;

var blending = 0;


//loop while actor exists
while (me)
{
//set animation state
if (my._mActor_movestate == STATE_NONE)
{
//no animation
wait(1);
continue;
}

//Get Base scene and parameters
mAnim_setBaseAnim(); //will determine the scene and other global vars below
base_scene = mAnim_temp_basescene;
base_mode = mAnim_temp_basemode;

base_cycle = mAnim_temp_basecycle; //temp globals set by the function


if (base_cycle == 0)
{
base_cycle = 16; //to avoid possible errors
}

if (base_cycle < 0)
{
//time based animation
my._mAnim_distance += time_step;
}
else
{
//distance based
my._mAnim_distance += (my._mActor_distance); //add phisical distance to animation value
}

//At the end of a cycle
if (my._mAnim_distance >= base_cycle)
{
if (base_mode != 0)
{
//Animation is Once-Only. Reset state
my._mActor_movestate = STATE_MOVE;
my._mActor_movestate_val = STATEVAL_FORWARD;
my._mAnim_distance = 0;

wait(1);
continue; //go back to the loop //what happens to the upper scene?
}

//warp time or distance
if (my._mAnim_distance > abs(base_cycle)) //why while?
{
my._mAnim_distance -= abs(base_cycle);
}
}

//Warp if negative
if (my._mAnim_distance < 0)
{
my._mAnim_distance += abs(base_cycle);
}


if (base_cycle == 0)
{
beep; //error
base_cycle == 1;
}

//calculate a percentage for the time/dist
base_anim = (100* my._mAnim_distance / abs(base_cycle));

//NOTE: should prevent empty pointer errors here (from the "text" array)
ent_animate(me,mAnim_scene_text.string[base_scene],base_anim,ANM_CYCLE *(base_mode ==0));


//THE BLEND CODE

if ( (base_scene != base_scene_old) && ( blending <= 0) )
{
//set up a blend, only if not blending
my.pose = 2;
//store the old pose in pose 2 (only once)
ent_animate(me,mAnim_scene_text.string[base_scene_old],base_anim_old, ANM_CYCLE);
my.pose = 1;

blending = 99;
}


//Execute the blend each cycle, backwards
if (blending >0)
{
ent_blendpose(me,1,2,blending);
blending -=50*time_step;
}


if (blending <=0)
{
//end blend
base_scene_old = base_scene;
base_anim_old = base_anim;
}


wait(1); //wait (redraw) a frame

} //end while (me)


}




Note that the Blend part of the function is about the 15 last lines.

|Emilio|

Re: Yet another blending code [Re: eleroux] #87188
08/23/06 14:06
08/23/06 14:06
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
frazzle Offline
Expert
frazzle  Offline
Expert

Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
Nice code contribution eleroux !!
As you said, short and not complictated at all ^^
Btw, could you show a small video which shows us the blending code in action

Cheers

Frazzle


Antec® Case
Intel® X58 Chipset
Intel® i7 975 Quad Core
8 GB RAM DDR3
SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB
NVIDIA® GeForce GTX 295 Memory 1795GB
Re: Yet another blending code [Re: frazzle] #87189
08/23/06 15:03
08/23/06 15:03
Joined: Jul 2005
Posts: 366
eleroux Offline OP
Senior Member
eleroux  Offline OP
Senior Member

Joined: Jul 2005
Posts: 366
Better (hopefully...)

I uploaded a demo. If you don't mind the ugly level, models and animations, try it

Use the usual WSAD keys to walk around.

Z X and C will switch to Crawl, Walk and Run respectivelly.

SHIFT will RUN if current mode is WALK.

Please note that the blendspeed is set to SLOW (about 8 frames) , so I can look for bugs. It's intended to be faster (2 or 4 frames blend) just as any other blending code from the templates.

No jump or attack for now. (coming soon). Sorry that it's packed, but the rest of the code is confidential. The reason for this is that it's ugly and ordinary and I feel shame to show it away.

Re: Yet another blending code [Re: eleroux] #87190
08/27/06 19:56
08/27/06 19:56
Joined: Jul 2005
Posts: 366
eleroux Offline OP
Senior Member
eleroux  Offline OP
Senior Member

Joined: Jul 2005
Posts: 366
I just updated the demo link (the same above) and added new Jump and Fall animation states. However, I didn't make new animations so I am using Stand for jump and a slow Run for jump.

Also, when the character falls from a certain distance, it LANDS (another animation state). I am using the CRAWL animation scene for now.

I am very happy with the blending code: I can add as many animations as I want without having to worry anymore about specific blends.

The main reason I have to use ent_blendpose instead of ent_blend is that I will need to add Base animations and Upper Body animations, like attacking while running etc. This code allows a blend without worrying about the actual animation state of the character, nor the new scene(s) involved.

Emilio


Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1