changing animation speed demo

Post here your demos and examples with the source files.
Forum rules
Always post the games with a screenshot.
The file must have the ged and data files (complete game source)
Use the forum attachment to post the files.
It is always better to use the first post to put the game files

changing animation speed demo

Postby feral » Thu Jun 05, 2008 5:26 am

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 251 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
Last edited by feral on Thu Jun 05, 2008 8:11 am, edited 1 time in total.
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score

Re: changing animation speed demo

Postby DST » Thu Jun 05, 2008 7:48 am

Error: Couldn't open data/ARIAL.ttf
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: changing animation speed demo

Postby feral » Thu Jun 05, 2008 8:15 am

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.. ?
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score

Re: changing animation speed demo

Postby Spidy » Thu Jun 05, 2008 8:16 am

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
Attachments
animspeed.zip
(233.49 KiB) Downloaded 199 times
Image
VOTE FOR MY SIGNATURE PLEASE.......THANK YOU
User avatar
Spidy
 
Posts: 935
Joined: Tue Aug 14, 2007 1:28 pm
Location: http://www.inatonibai.com
Score: 38 Give a positive score

Re: changing animation speed demo

Postby feral » Thu Jun 05, 2008 8:22 am

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 ??
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score

Re: changing animation speed demo

Postby speckford123 » Fri Jun 06, 2008 12:35 am

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:
Attachments
animspeededit.zip
custom code, almost the same purpose
(179.36 KiB) Downloaded 200 times
speckford123
 
Posts: 334
Joined: Fri May 05, 2006 6:33 pm
Score: 49 Give a positive score

Re: changing animation speed demo

Postby feral » Fri Jun 06, 2008 12:49 am

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
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score

Re: changing animation speed demo

Postby speckford123 » Fri Jun 06, 2008 12:54 am

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:
speckford123
 
Posts: 334
Joined: Fri May 05, 2006 6:33 pm
Score: 49 Give a positive score

Re: changing animation speed demo

Postby DST » Sun Jun 22, 2008 8:27 am

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.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: changing animation speed demo

Postby feral » Tue Jul 08, 2008 6:42 am

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;
  }
}

//-------------------------------------------------
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score

Re: changing animation speed demo

Postby feral » Tue Jul 08, 2008 7:08 am

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
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score


Return to Game Demos

Who is online

Users browsing this forum: No registered users and 1 guest

cron