Ja ich bin es wieder mit einer neuen SDL technischen Frage.
Ich habe das Problem,dass er ein Rechteck von Rechts nach links blittet. Ich will genau das Umgekehrte.(Von Links nach Rechts)
Hier ist der Code:
Code: Alles auswählen
Animation.h
Code: Alles auswählen
#ifndef _ANIMATION_
#define _ANIMATION_
class animation{
private:
int vetikal,geschwindigkeit,frame,status;
int startmember,pausemember,pausmember,starmember;
public:
animation();
void start();
void loadimages();
void update();
void autobewegung();
void Move();
void applysurface(int x, int y, SDL_Surface *quelle, SDL_Surface *ziel, SDL_Rect *clip);
void show();
void clips();
int getticks();
};
#endif
Code: Alles auswählen
Animation.cpp
Code: Alles auswählen
include <iostream>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "animation.h"
const int width = 640;
const int height = 480;
const int framepersecond = 10;
const int foowidth = 64;
const int fooheight = 205;
const int fooright = 0;
const int fooleft = 1;
SDL_Rect clipsRight[ 4 ];
SDL_Surface *bild = NULL;
SDL_Surface *hintergrund = NULL;
SDL_Surface *reihee = NULL;
animation::animation()
{
startmember = 0,pausemember = 0;
pausmember = false,starmember = false;
vetikal = 0;
geschwindigkeit = 0;
frame = 0;
status = fooright;
}
void animation::start()
{
starmember=true;
pausmember=false;
startmember=SDL_GetTicks();
}
int animation::getticks()
{
if( starmember == true )
{
return SDL_GetTicks() - startmember;
}
}
void animation::applysurface(int x, int y, SDL_Surface *quelle, SDL_Surface *ziel, SDL_Rect *clip = NULL)
{
SDL_Rect offset;
offset.x = 900;
offset.x = x;
offset.y = y;
SDL_BlitSurface(quelle,clip,ziel,&offset);
}
void animation::clips()
{
//Clip the sprites
clipsRight[ 0 ].x = 0;
clipsRight[ 0 ].y = 0;
clipsRight[ 0 ].w = foowidth;
clipsRight[ 0 ].h = fooheight;
clipsRight[ 1 ].x = foowidth;
clipsRight[ 1 ].y = 0;
clipsRight[ 1 ].w = foowidth;
clipsRight[ 1 ].h = fooheight;
clipsRight[ 2 ].x = foowidth * 2;
clipsRight[ 2 ].y = 0;
clipsRight[ 2 ].w = foowidth;
clipsRight[ 2 ].h = fooheight;
clipsRight[ 3 ].x = foowidth * 3;
clipsRight[ 3 ].y = 0;
clipsRight[ 3 ].w = foowidth;
clipsRight[ 3 ].h = fooheight;
}
void animation::Move()
{
vetikal+=geschwindigkeit;
}
void animation::show()
{
if( geschwindigkeit < 0 )
{
status = fooleft;
frame++;
}
else
{
frame = 0;
}
if( frame >= 4 )
{
frame = 0;
}
if( status == fooright )
{
applysurface( vetikal,height - fooheight, reihee, hintergrund, &clipsRight[ frame] );
}
}
void animation::loadimages()
{
hintergrund = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT);
bild = IMG_Load("d5.jpg");
reihee = IMG_Load("reihe.jpg");
SDL_BlitSurface(bild,0,hintergrund,0);
}
void animation::update()
{
SDL_Flip(hintergrund);
}
void animation::autobewegung()
{
int z = 16;
geschwindigkeit+=z;
}
Code: Alles auswählen
main.cpp
Code: Alles auswählen
#include <iostream>
#include <SDL/SDL.h>
#include "SDL/SDL_image.h"
#include "animation.h"
const int framepersecond = 10;
SDL_Event event;
int main( int argc, char* args[])
{
bool quit = false;
SDL_Init(SDL_INIT_EVERYTHING);
animation ani;
ani.loadimages();
ani.clips();
while( quit == false )
{
ani.start();
while( SDL_PollEvent( &event ) )
{
//Handle events for the stick figure
ani.autobewegung();
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
ani.Move();
ani.show();
ani.update();
if( ani.getticks() < 1000 / framepersecond )
{
SDL_Delay( ( 6000 / framepersecond ) - ani.getticks() );
}
}
return 0;
}
Code: Alles auswählen
void animation::Move()
{
vetikal+=geschwindigkeit;
}
Code: Alles auswählen
void animation::applysurface(int x, int y, SDL_Surface *quelle, SDL_Surface *ziel, SDL_Rect *clip = NULL)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(quelle,clip,ziel,&offset);
}
Habe das Code noch hochgeladen zum ausprobieren.