Original Post
I cant seam to get to blit any surface from the many my constructor makes, its job is to take 15 images from a sprite sheet, cut them up, rotate each 360 times, save each to a surface array so i can use them later but whenever I try I cant seam to use my surfaces this does nothing; constructor apply surface funtion used in above ------- EDIT; doing some testing, there seams to be somthing inheritly wrong with what i am doing, this returns a blank surface, unless I dont use spriteCutTest (dont cut the image) then it works for about 60 frames then disapears, and stops loading the image (games speeds up) code that is puting the surfaces together; [Edited by - JoshPike on December 4, 2009 11:13:50 AM]
blit.ApplySurface( 0, 0, armsSurfaceArray[1][1], background, NULL,0,1 );
SDL_Flip( background);
SDL_Surface *torsoSurfaceArray[7][361];
SDL_Surface *armsSurfaceArray[7][361];
SDL_Surface *legsSurfaceArray[7][361];
//intitalizes SDL, and sets all surfaces
Surface::Surface()
{
const int SCREEN_WIDTH = 500;
const int SCREEN_HEIGHT = 400;
const int SCREEN_BPP = 32;
TTF_Init();
SDL_Init( SDL_INIT_EVERYTHING );
background = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
SDL_WM_SetCaption( "running", NULL );
//sets all surfaces to NULL
for (int i= 1; i < 7; i++)
{
for (int j= 0; j < 360; j++)
{
torsoSurfaceArray[j] = background;
armsSurfaceArray[j] = background;
legsSurfaceArray[j] = background;
}
}
int spriteCutWidth = 187;
int spriteCutHight = 100;
int spriteXcords[6];
spriteXcords[1] = 119;
spriteXcords[2] = 312;
spriteXcords[3] = 507;
spriteXcords[4] = 701;
spriteXcords[5] = 895;
int spriteYcords[4];
spriteYcords[1] = 351;
spriteYcords[2] = 479;
spriteYcords[3] = 608;
SDL_Rect spriteCut[6];
SDL_WM_SetCaption( "Loading...", NULL );
SDL_Surface *playerSpriteSheetImg = IMG_Load( "debug/Generic_Images/player_sprite_sheet.tga" );
//going through once for every stride
for (int i= 1; i < 6; i++)
{
//360 times, one for each angle
for (int j= 0; j < 5; j++)
{
spriteCut.h = spriteCutHight;
spriteCut.w = spriteCutWidth;
spriteCut.x = spriteXcords;
spriteCut.y = spriteYcords[2];
blit.ApplySurface( 0, 0, playerSpriteSheetImg, torsoSurfaceArray[j], &spriteCut,j,1 );
//blit.ApplySurface( 0, 0, background, torsoSurfaceArray[j], NULL,0,1 );
//SDL_FreeSurface( background );
spriteCut.y = spriteYcords[3];
blit.ApplySurface( 0, 0, playerSpriteSheetImg, legsSurfaceArray[j], &spriteCut,j,1 );
//blit.ApplySurface( 0, 0, background, legsSurfaceArray[j], NULL,0,1 );
//SDL_FreeSurface( background );
spriteCut.y = spriteYcords[1];
blit.ApplySurface( 0, 0, playerSpriteSheetImg, armsSurfaceArray[j], &spriteCut,j,1 );
//blit.ApplySurface( 0, 0, background, armsSurfaceArray[j], NULL,0,1 );
//SDL_FreeSurface( background );
}
}
}
void Surface::ApplySurface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip, int angle, int zoom)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
if (angle != 0)
{
source = rotozoomSurface(source, angle, 1, 1);
}
if (zoom != 1)
{
source = rotozoomSurface(source, 0, zoom, 1);
}
SDL_BlitSurface( source, clip, destination, &offset );
}
SDL_Surface *Surface::PlayerIcon(int stride, string direction)
{
SDL_FreeSurface( background );
SDL_Rect spriteCutTest;
spriteCutTest.x = 20;
spriteCutTest.y = 20;
spriteCutTest.h = 200;
spriteCutTest.x = 400;
SDL_Surface *playerSpriteSheetImgTest = IMG_Load( "debug/Generic_Images/player_sprite_sheet.tga" );
blit.ApplySurface( 0, 0, playerSpriteSheetImgTest, background, &spriteCutTest,20,1 );
//blit.ApplySurface( 0, 0,torsoSurfaceArray[1][1], background, NULL,0,1 );
return background;
}
void Surface::EntireDisplay(int playerHighLevel,SDL_Rect levelRect, string direction)
{
//map
SDL_Surface *levelDisplay = blit.VisualLevelSurface(levelRect);
blit.ApplySurface( 0, 0, levelDisplay, background, NULL,0,1 );
SDL_FreeSurface( levelDisplay );
SDL_Surface *personDisplay = blit.PlayerIcon(stride,direction);
blit.ApplySurface( 0, 0, personDisplay, background, NULL,0,1 );
SDL_FreeSurface( personDisplay );
//fliping, only place this should be
SDL_Flip( background);
SDL_FreeSurface( background );
}