Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Simple Image Animated Objects Example

Author
Message
NoviceNate333
5
Years of Service
User Offline
Joined: 7th Dec 2012
Location: United States
Posted: 22nd Feb 2016 13:44
I have been tinkering with animated textures. I thought I would share my progress here for discussion and to maybe give a head start for someone trying to implement this. I plan on making the effect.h more oop eventually but I was just aiming for functionality for now. here is my code feel free to comment.

First the animation loading function.

+ Code Snippet
The FindFreeImage() Code is simply just
+ Code Snippet

Finally here is the effects class again this is the first stage. I am going to add more on to the class such as different types of animation and of course simultaneous animations.

+ Code Snippet

So the basic code logic is to initialize an array of Image ids and iterate through them based on a timer. The files are loaded through the directory "media/effects/EffectName/Frame 1.png" and so on for max frames.

Example Code

+ Code Snippet
Hotline
9
Years of Service
User Offline
Joined: 22nd Aug 2008
Location:
Posted: 23rd Feb 2016 06:47
Well i don't think loading a separate image for each frame is the best way.Try texture atlasing instead.

Also the code itself looks pretty complicated for such a simple task as texture frame animation.

First get rid of these C -ish spaghetti functions like strcat , sprintf and char arrays and use std::string.It is more convenient easy to read. Use std::vector instead of standard c++ arrays

Quote: "int (&LoadAnimation(int (&arr)[32],char* name, int frames))[32]"


This gotta go too....

Quote: "if(timer>0)
{
timer--;
if(timer%5==0)
{"


This is wrong... use float for timers and calculate frames using delta time and add speed parameter.
Also the destructor of your Effect class should delete the plane...

[href=forum.thegamecreators.com/?m=forum_view&t=191567&b=5]Spark Particle engine[/href]
[href=forum.thegamecreators.com/?m=forum_view&t=199163&b=5]Transform gizmo plugin[/href]
NoviceNate333
5
Years of Service
User Offline
Joined: 7th Dec 2012
Location: United States
Posted: 23rd Feb 2016 08:58 Edited at: 23rd Feb 2016 09:02
I planned on changing the arrays to vectors because that does seem like the best option. Also the reason I use char* and char [ x ] is because GDK default parameters are in that format and don't accept string arguments.(that I am aware of). Also how do you implement change over time with floats? I planned on adding a couple more parameters such as delay or in this case speed along with vector3 rotation and a Boolean for looping.

Quote: "Well i don't think loading a separate image for each frame is the best way.Try texture atlasing instead."


I figured there might be a better way I will look into this and see how easy it will be to accomplish this in dark gdk.



EDIT:
just found this command dbStr(char*, int ); I didn't even know it existed lol
Hotline
9
Years of Service
User Offline
Joined: 22nd Aug 2008
Location:
Posted: 23rd Feb 2016 10:31
Quote: " Also how do you implement change over time with floats?"


The easiest way is simply :

+ Code Snippet

Quote: "Also the reason I use char* and char [ x ] is because GDK default parameters are in that format and don't accept string arguments.(that I am aware of)"


AFAIK gdk accept a nullterminated C string so you can use : the string::c_str() which returns a c string

+ Code Snippet

or use std::stringstream for more advanced string operations;
+ Code Snippet
etc

Although i can't remember strings in gdk are C strings (you should check first)

Quote: "I figured there might be a better way I will look into this and see how easy it will be to accomplish this in dark gdk."


You could look into the vertex manipulation commands and change the UV's every frame
[href=forum.thegamecreators.com/?m=forum_view&t=191567&b=5]Spark Particle engine[/href]
[href=forum.thegamecreators.com/?m=forum_view&t=199163&b=5]Transform gizmo plugin[/href]
NoviceNate333
5
Years of Service
User Offline
Joined: 7th Dec 2012
Location: United States
Posted: 23rd Feb 2016 11:46 Edited at: 23rd Feb 2016 11:49
Vertex shader programming is far beyond my knowledge and I'm not sure if you can change the uv image in a shader for animation. If this isn't what you meant I do apologize.

I did change the code the Load Animations is
+ Code Snippet

I think the function void + Code Snippet
can be used to grab a texture from a texture sheet. the documentation said the flag should be set to 0 if you apply the image as a texture. I will have to tinker with this in the future.

also I checked and gdk uses char* for almost every frame but this conversion method is pretty simple and sweet
+ Code Snippet
you cant use the sMedia.c_str() command because it returns a const char* and the compiler throws a fit lol.

Also I changed the animation to be based off dbTimer() it seems to work pretty well

+ Code Snippet
Hotline
9
Years of Service
User Offline
Joined: 22nd Aug 2008
Location:
Posted: 23rd Feb 2016 13:00 Edited at: 23rd Feb 2016 13:25
Here's a simplified version

+ Code Snippet

Quote: "Vertex shader programming is far beyond my knowledge and I'm not sure if you can change the uv image in a shader for animation"

You can do it with vertex manipulation commands.Search for something like dbLockVertexdataForLimb and see how it works (i can't really help you with this because i don't remember these commands...)



Quote: "can be used to grab a texture from a texture sheet. "

That creates another texture on the fly from an existing texture.Thats not what you need. What you need is to set the plane's 4 corner vertices UV data each frame.
[href=forum.thegamecreators.com/?m=forum_view&t=191567&b=5]Spark Particle engine[/href]
[href=forum.thegamecreators.com/?m=forum_view&t=199163&b=5]Transform gizmo plugin[/href]

Login to post a reply

Server time is: 2017-12-16 16:44:06
Your offset time is: 2017-12-16 16:44:06