• Content count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About Leo_Joy

  • Rank
  1. Alright, I figured it out. I wasn't initializing my_direction, so I was getting nonsense values for where to crop the image.
  2. [color=#000000][font=Arial,]I can't seem to draw to the screen at all. When I call SDL_BlitSurface, nothing happens. However, it does not return an error code. I've written a class to handle image sprites, and when I step through with a debugger, I see it is returning non-empty values for the surface to blit to the main video surface. When I call my draw function, however, it does nothing. I have confirmed that the pixel values are not changed at all for the surface. What am I doing wrong?[/font][/color] [color=#000000][font=Arial,]Here's my main.cpp:[/font][/color] [color=#000000][font=Arial,][code][/font][/color] [color=#000000][font=Arial,]//Standard libs #include <SDL.h> //Our gaming base #include "game_base.h" //SDL redefines main as winmain, but this is a console application so we don't want that #undef main const int MAX_FPS = 80; ///< The maximum frames per second for the game int main ( int argc, char* argv[] ) { //Initialization System game( false, 640, 480, "Platformer", MAX_FPS ); //Create a game that is not fullscreen with a resolution of 640x480 SDL_Surface *buffer = NULL; Input *input = NULL; Image_Sprite *player_sprite = NULL; buffer = game.get_buffer(); player_sprite = new Image_Sprite( "data/player.bmp", 1, 4 ); //Setup the hitbox for the player SDL_Rect hitbox; hitbox.w = 32; hitbox.h = 32; hitbox.x = 0; hitbox.y = 0; Player player( 100, 100, hitbox, 1.0, RIGHT, player_sprite ); //Initialize the player at (100, 100) //Main game loop while( !game.check_is_done() ) { game.refresh_top(); player.draw( buffer ); game.refresh_bottom(); } //Cleanup delete player_sprite; }[/font][/color] [color=#000000][font=Arial,][/code][/font] [color=#000000][font=Arial,]My draw method looks like this:[/font][/color][/color] [color=#000000][color=#000000][font=Arial,][code][/font][/color][/color] [color=#000000][color=#000000][font=Arial,]void Character::draw( SDL_Surface *destination ) { SDL_Rect coordinates; SDL_Surface *sprite; sprite = my_sprite->get_frame( my_frame, my_direction ); coordinates.x = (int)get_x(); coordinates.y = (int)get_y(); SDL_BlitSurface( sprite, NULL, destination, NULL ); }[/font][/color][/color] [color=#000000][color=#000000][font=Arial,][/code][/font][/color] [color=#000000][font=Arial,]And my get_frame method is this:[/font][/color][/color] [color=#000000][color=#000000][font=Arial,][code][/font][/color][/color] [color=#000000][color=#000000][font=Arial,]SDL_Surface* Image_Sprite::get_frame( int x, int y ) { SDL_PixelFormat *format; format = my_sprite->format; SDL_Surface *frame = SDL_CreateRGBSurface( my_sprite->flags, my_frame_width, my_frame_height, format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask ); SDL_Rect *frame_crop = new SDL_Rect; frame_crop->x = my_frame_width * x; frame_crop->y = my_frame_height * y; frame_crop->w = my_frame_width; frame_crop->h = my_frame_height; SDL_Rect *coordinates = new SDL_Rect; coordinates->x = 0; coordinates->y = 0; SDL_BlitSurface( my_sprite, frame_crop, frame, coordinates ); delete frame_crop; return frame; }[/font][/color][/color] [color=#000000][color=#000000][font=Arial,][/code][/font][/color] [color=#000000]The funny thing is, this code is almost directly copied from another project where it worked fine. And yes, I am calling SDL_Init(), SDL_Quit, and SDL_Flip(). They're all part of my System class. Any help would be appreciated. I tried solving this myself, but I'm stumped.[/color][/color]