Forum

> > CS2D > Scripts > What's the best way to implement an animation ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English What's the best way to implement an animation ?

7 replies
To the start Previous 1 Next To the start

old Re: What's the best way to implement an animation ?

Rainoth
Moderator Off Offline

Quote
How would you go about implementing an animation?

The only way I can think of is using image function to show different images over a period of time. What other way to implement images is there? I suppose you could do the same with map entities but you can't control as much.

I am not aware of any other ways to even implement an animation so I can't say that there's a better way to do it than what I described. It's the only option out there.

If you're asking how exactly to implement it with lua, I'd probably load the image frames first and then juggle with their transparency. That way you wouldn't have to make images every time you want to show an animation.

old Re: What's the best way to implement an animation ?

VADemon
User Off Offline

Quote
cs2d lua hook always is triggerred every frame that means 50fps for your animation. cs2d lua hook ms100 is triggerred every 5th frame (20ms per frame * 5 frames = 100ms). You see the difference. It just depends on your target framerate. Many videos run at 25fps . . . that's 25fps/50fps = half the framerate, every second game frame, every second call of cs2d lua hook always.
Don't use cs2d lua cmd timer for this task.
edited 1×, last 20.05.16 09:06:57 pm

old Re: What's the best way to implement an animation ?

GeoB99
Moderator Off Offline

Quote
cs2d cmd always has a very fast processing in terms of call execution. Basically in the process call requires that the current frame must be suspended and a new one created and pushed on the stack, the operation repeats (for EVERY FRAME!). This hook is like when you strike out a huge beam of photons at a unbelievable speed so to speak. The problem is, how expensive are the functions in my environment?

Each function consists of methods, instructions and so forth that are either small or big. Since, for example, we want to implement an animation, you wouldn't simply just use the cs2d lua cmd image Lua function from CS2D library but also other functions to make work at the fullest an animation. With that being said, if I was in your place I'd refuse to use this hook for such tasks since it occupies each frame thus leading to instant lags.

• Edit: user VADemon ninja'd me on this one. But just a side note, the only way round to make an animation (at least a simplest one) is to stick with map entities unfortunately.

old Re: What's the best way to implement an animation ?

EngiN33R
Moderator Off Offline

Quote
I would like to point out to everyone the recent addition of spritesheets to CS2D. I understand that the documentation for them is lacking (which is something we're working on), but it would be beneficial to everyone to start making full use of this new feature. To create a spritesheet image, use the cs2d lua cmd image function like this:
1
local img = image("<spritesheet:PATH:FRAMEW:FRAMEH[:MODE]>", ...)
Where PATH is the path to the spritesheet, FRAMEW and FRAMEH are the width and height of one frame, respectively (all frames must have equal dimensions), and MODE is an optional argument that controls the alpha masking mode (a for alpha, b for black, m for magenta and n for none). To control which frame is shown, use the cs2d lua cmd imageframe function:
1
imageframe(img, 2)
Remember that frames are 1-indexed (the first frame has the ID 1).
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview