SDL Forum Index
SDL
Simple DirectMedia Layer Forums
Reply to topic
SDL2 Animation loading
paul188


Joined: 22 Dec 2016
Posts: 1
Reply with quote
Hey guys i just invented a little code snippet and wanted to ask if it works in practice.
Every answer is very appreciated Wink.

Player.cpp:

void Player::LoadAnimation(char*animationFrames[], SDL_Renderer *renderer, int count, int index) {
for (int i = 0; i < count; i++) {
SDL_Surface *surf_temp = LoadSurfaceFromImage(animationFrames[i],"PNG");
SDL_Texture *tex_temp = SDL_CreateTextureFromSurface(renderer, surf_temp);
AnimationFrames.push_back(tex_temp);
}
PlayerAnimations.at(index) = AnimationFrames;
AnimationFrames.clear();
}

Player.h:

class Player{
public:
Player(SDL_Rect *bounds);//bounds either in SDL_Rect* or in ints
Player(int x, int y, int w, int h);
void Player::LoadAnimation(char*animationFrames[], SDL_Renderer *renderer, int count, int index);//parameters: animationFrames: names of the files of one animation
//renderer: the renderer object for the launcher, count: how many frames the animation has, index: the index of the animation in the array
private:
std::array <std::vector<SDL_Texture*>,10>PlayerAnimations;
std::vector<SDL_Texture*>AnimationFrames;
View user's profileSend private message
SDL2 Animation loading
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic