Sign in to follow this  

c++ error please help

Recommended Posts

hello everybody right now i'm having with clipping my tile sheet. Its probably a really dumb error on my part but anyways here is the code.

#include <string>
#include "SDL_image.h"
#include "tile_load.h"
#include "class_tile.h"

using namespace::std;

// used for clipping

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL)
//Holds offsets
SDL_Rect offset;

//Get offsets
offset.x = x;
offset.y = y;

SDL_BlitSurface( source, clip, destination, &offset );

void draw_sprite(int srcX, int srcY, int dstX, int dstY, int width, int height, SDL_Surface* source, SDL_Surface* destination)

SDL_Rect src;
src.x = srcX;
src.y = srcY;
src.w = width;
src.h = height;

SDL_Rect dst;
dst.x = dstX;
dst.y = dstY;
src.w = width;
src.h = height;

SDL_BlitSurface(source, &src, destination, &dst);


SDL_Surface *load_image( std::string filename )
//The image that's loaded
SDL_Surface* loadedImage = NULL;

//The optimized surface that will be used
SDL_Surface* optimizedImage = NULL;

//Load the image
loadedImage = IMG_Load( filename.c_str() );

//If the image loaded
if( loadedImage != NULL )
//Create an optimized surface
optimizedImage = SDL_DisplayFormat( loadedImage );

//Free the old surface
SDL_FreeSurface( loadedImage );

//If the surface was optimized
if( optimizedImage != NULL )
//Color key surface
SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );

//Return the optimized surface
return optimizedImage;

void clip_tiles()
//Clip the sprite sheet
clips[tile_green].x = 0;
clips[tile_green].y = 0;
clips[tile_green].w = TILE_WIDTH;
clips[tile_green].h = TILE_HEIGHT;

clips[tile_black].x = 0;
clips[tile_black].y = 32;
clips[tile_black].w = TILE_WIDTH;
clips[tile_black].h = TILE_HEIGHT;


please help.

Share this post

Link to post
Share on other sites
This topic is now closed to further replies.
Sign in to follow this