Page 1 of 1

changing animation speed demo

PostPosted: Thu Jun 05, 2008 5:26 am
by feral
just a quick and dirty (but easy) way to change animation speed of a sprite during gameplay
animspeed.zip
version two - with arial.ttf
(174.3 KiB) Downloaded 250 times

this demo only has five speeds/ but can be any number of speeds from 0 upt o your current games framerate

does NOT use if statements/case statements etc

use keys a to slow down ( speed six is set at 1 frame a sec)
use keys z to speed up ( speed 0 is set at 60 frames a sec)

note: it also move to the next speed without losing the current animtion position (use NO_CHANGE)
just make sure all animations are named the same with a "count" at the end - the demo shows why


feral

ps: i only used a 5 frame sprite, so a sprite with more frames should work even better - if you have one handy try it... let me know

Re: changing animation speed demo

PostPosted: Thu Jun 05, 2008 7:48 am
by DST
Error: Couldn't open data/ARIAL.ttf

Re: changing animation speed demo

PostPosted: Thu Jun 05, 2008 8:15 am
by feral
DST wrote:Error: Couldn't open data/ARIAL.ttf


sorry guys.. fixed version now uploaded to first post in this thread..version two - with arial.ttf

feral


ps: there may even be an easier way.. that is, if there is a way to change animindex value from a script ? I don't know if that is possible.. ?

Re: changing animation speed demo

PostPosted: Thu Jun 05, 2008 8:16 am
by Spidy
Nice demo ,can i used this code in my GTA Game project and if u dont mind i fix the error as DST said arial.ttf error

Re: changing animation speed demo

PostPosted: Thu Jun 05, 2008 8:22 am
by feral
Spidy wrote:Nice demo ,can i used this code in my GTA Game project and if u dont mind i fix the error as DST said arial.ttf error



LOL, we must of posted the "fix" within seconds of each other..

and yes, feel free to use the code if it works..

feral

ps: I thinking of writing it out as a function, for "cut and paste" programming.. would that be of use ?

ie: something like to use in scripts just say "ChangeSpeed( Event Actor, -1/or 1)" -1 to slow 1 to speed up..

then have a prewritten ChangeSpeed function ready to be pasted into global codes ??

Re: changing animation speed demo

PostPosted: Fri Jun 06, 2008 12:35 am
by speckford123
woohoo! just made my own code to put next to this one
it might not be the best code that poped into my head, but this is how i approached this topic :D

i make it so you need only 1 animation

PS. i used the left and right arrow keys, cause im old fasioned like that :wink:

Re: changing animation speed demo

PostPosted: Fri Jun 06, 2008 12:49 am
by feral
speckford123 wrote:woohoo! just made my own code to put next to this one
it might not be the best code that poped into my head, but this is how i approached this topic :D

i make it so you need only 1 animation

PS. i used the left and right arrow keys, cause im old fasioned like that :wink:



ooohh ... very nice.. :D I like this one even better, good work ..point to you!

feral

PS: I would have used the left/right arrow keys too.. but for some reason GE was crashing on me... ended up changing the keys and it worked.. weird

Re: changing animation speed demo

PostPosted: Fri Jun 06, 2008 12:54 am
by speckford123
feral wrote:

ooohh ... very nice.. :D I like this one even better, good work ..point to you!

feral

PS: I would have used the left/right arrow keys too.. but for some reason GE was crashing on me... ended up changing the keys and it worked.. weird


thanks for the point, i allready gave you one a second ago, and yeah, i know all about glitches, im running windows vista :lol:

Re: changing animation speed demo

PostPosted: Sun Jun 22, 2008 8:27 am
by DST
Yes thats a good way to change the speed.
Here's a way to reduce the script.

Create a timer based on your fps (30 is horrible, math doesn't sync with ms) so i used 25 or 40 fps.

at 25 fps, timer>40ms>
Code: Select all
count+=1;
if(count>=time){
animpos+=1;
count=0;
if (animpos>3){animpos=0;}}


and then i just change the value of 'time' to speed or slow the animation.

Re: changing animation speed demo

PostPosted: Tue Jul 08, 2008 6:42 am
by feral
sorry.. this is a double post, but as the other one is posted in the advance section under a title probably most new guys won't read... well

a function for modifying animation speeds

This version uses a actor variable called 'speed' to hold the desired frame rate.

The actual frame rate of the actor animation (from the animspeed2() function) can also be used in game processes as with any other actor variables.


In otherwords, the variable 'speed' can be used like any other actor struct variable (like actor.x actor.width actor.etc and can be modified and read by other actors etc..

eg player1.speed

for example
if (enemy.speed<=5)
{
//enemy is going slow enough to shoot
}
else
// enemy too fast to shoot accurately
}
Code: Select all
/ Global Function - animspeed2()
// By: feral
// note: this version animspeed2() runs based on frames rates
// and not percentages of game speed like the original animspeed()
//
// Purpose: sets animation speed of an actor
// and can be used by multiple actors at different speeds
// Usage:
// 1. Set a new user Variable (using Variables button in script editor)
// Set as:
// name: speed (lowercase)
// type: integer
// variable type: Actor variable
// note: this adds a new unique variable called 'speed' to every actor
// and is used to store the individual frame speed of that actor (from animspeed).
//
// To Use:
// 1. In any actor in the 'Create Actor' event script insert
//
// ChangeAnimationDirection("Event Actor", STOPPED);
//
//
// 2. In the Draw Actor event to "animate"
// use
//
// animspeed(var);
//
// where the variable = 0 to total game FPS
// 0 will stop the animation
// game rate will give highest speed eg: in a 30 FPS game a var of 30 is max speed
// numbers higher then current game rate will defualt back to current game max
// eg if game rate is set at 30,  a animspeed var of 50 will still run at 30 frames
//-------------------------------------------------

void animspeed2(float i)
{
speed=speed+i;

if (speed>=real_fps)
// note using real_fps should stop frames skipping if game lags..

  {
  animpos=animpos+1;
  speed=0;
  }
  if (animpos>=nframes)
  {
     animpos=0;
  }
}

//-------------------------------------------------

Re: changing animation speed demo

PostPosted: Tue Jul 08, 2008 7:08 am
by feral
actually .. I just changed my mind again :?

in the above script using real_fps should work most of the time, but if the game lags it will actually CAUSE frame skipping... not solve it... sorry

change the line in the above script from
if (speed>=real_fps)
to if (speed>=30) ( if game rate is 30)
or if (speed>=60) ( if game rate is 60 etc etc)

Is there a way to access the games set FPS ? ie: the one in config->Game Properties

feral