The container is named MovieClip and can contain other MovieClip s, Animations and their derived classes (Animation is the image that shows on screen). When yourmovieclip.Draw(sf::RenderWindow) is called the movie clip sorts the objects( so they have z ordering), calculates their position and rotation (the whole movieclip can be rotated by modifying one parameter), executes a user defined function (some kind of keyframes), and calls nestedmovie.Draw(…), than goes to the next frame.
MovieClip.hpp contains a description of all its members. It is a little complicated so an example will help
.
Source:header2.rar
#include "Header2/MySFML.hpp" #include <iostream> #include <fstream> #include <vector> #include <map> using namespace std; using namespace sf; using namespace mc; class Screen:public MovieClip{ public: class f0:public Function{ void Run(MovieClip& This){ This.properties.rotation+=0.1; } }f0; class f1:public Function{ void Run(MovieClip& This){ This["ani 1"].properties.rotation+=0.1; This.properties.rotation=0; } }f1; Image im; ImageAnimation t0; //creates an animation of 2 frames 100/100 pixels from the source image im ImageAnimation t1; Screen(){//sets the properties of its objects and itself im.LoadFromFile("Objects/x.png"); t0=ImageAnimation(100,100,im,2);//this creates the animation form the image im (2 frame animation 100/100 pixels) t0.animation.SetCenter(50,50);//this should center the animations t1=t0; Add(t0);//adds te animation t0 to the movie clip SetName("ani 1",NumberOfAnimations()-1);//sets a name to the last animation added witch is t0 Add(t1);//... SetName("ani 2",NumberOfAnimations()-1);//... Add(500); //adds 500 frames so the movie now has 501 frames Add(100,f0);//adds a keyframe at 100. That means that f0 will be executed from [0 to 100] Add(500,f1);//add a keyframe form (100 to 500] Change(0,0,Properties(-100,0,0,1,1,false)); //changes the properties in frame 0 of the first movieclip/animation added witch is t0; the properties are in the same order as they are explained in MovieClip.hpp Change(0,"ani 2",Properties(100,0,0,1,2,false));// changes the porperties in frame 0 of the movieclip/animation with the name ani 2 Change(300,"ani 1",Properties(-100,0,0,1,3,false));//after frame 300 ani 1 will have a greater depth than ani 2 so it will be drawn on top, and it stops playing Change(400,"ani 2",Properties(200,0,pi/2,0.5)); //on frame 400 moves ani 2 on a position with x =200 y = 0 with rotation pi/2, alpha 0.5 (semi transparent), it will also start playing ///so ani 1 is on the left part ani 2 is on the right ///they both rotate because screen rotates (for the first 100 frames) ///after 100 ani 1 rotates ///after 400 ani 2 plays, becomes transparent and rotates 90 degrees } }Screen; int main(){ RenderWindow Win(VideoMode(800,600,32),"Test"); Screen.properties.y=-300;//this centers Screen on screen Screen.properties.x=400; cout<<"Number of frames: "<<Screen.NumberOfFrames()<<endl; cout<<"Number of animations: "<<Screen.NumberOfAnimations()<<endl; cout<<endl<<endl; Win.SetFramerateLimit(60); bool Running=true; while (Running){ Event Event; //event processing while(Win.GetEvent(Event)){ if(Event.Type==Event::Closed){ Running=false; Win.Close(); } } Win.Clear(); cout<<Screen.GetFrame()<<endl; if(!Screen.Draw(Win)){Running=false;Win.Close();} //if Screen doesn't show than nothing else will happen so we can exit the loop Win.Display(); } }
When modifying just 3 frames is enough there is no problem but if you want to make a simple animation in witch you move something like make a players hand go up you want to have a graphical editor that does all the hard work. I have just started coding a code generator that will let you graphically create animations, save them as header files and include them in your source.
For now it is a console and it only lets you insert images…gui.rar
When I will update it I will write the modifications here.
If some of you want to write some gui elements let me know