Thread: Trouble with SDL_Rect

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    17
    main.cpp:


    Code:
    #include "includes.h"
    
    
    SDL_Rect r;
    
    r.x=16;
    
    
    
    
    
    
    
    
    
    
    int main ( int argc, char** argv )
    
    {
    
        SDL_Init(SDL_INIT_VIDEO);
        if(Init(1)==false)
            {
                printf(SDL_GetError());
                return 2;
            }
    
    
        atexit(SDL_Quit);
    
    
        SDL_Surface* screen =SDL_SetVideoMode(600, 480, 32,SDL_HWSURFACE|SDL_DOUBLEBUF);
        if ( !screen )
        {
            printf("Unable to set 640x480 video: %s\n", SDL_GetError());
            return 1;
        }
    
    
    SDL_Surface *bg=load_Image("C:\\Documents and Settings\\Make.YOUR-6JNHHU0520\\Desktop\\C++\\SDL\\Game Engine\\img\\sky.png");
    SDL_Surface *sprites=load_Image("C:\\Documents and Settings\\Make.YOUR-6JNHHU0520\\Desktop\\sprite sheets\\finalfantasy.gif");
    
    
    AppSurface(0,0,bg,screen,NULL);
    AppSurface(250,250,sprites,screen,NULL);
    
    //
    //SDL_BlitSurface(bg,NULL,screen,&r);
    
        bool done = false;
        while (!done)
        {
            SDL_Flip(screen);
            SDL_Event event;
            while (SDL_PollEvent(&event))
            {
                // check for messages
                switch (event.type)
                {
                    // exit if the window is closed
                case SDL_QUIT:
                    done = true;
                    break;
    
                    // check for keypresses
                case SDL_KEYDOWN:
                    {
                        // exit if ESCAPE is pressed
                        if (event.key.keysym.sym == SDLK_ESCAPE)
                            done = true;
                        break;
                    }
                } // end switch
            } // end of message processing
        }
    
        SDL_FreeSurface(bg);
        SDL_FreeSurface(kube);
        printf("Exited cleanly\n");
        return 0;
    }

  2. #2
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Declaring your SDL_Rect r as a global variable is a bad choice (in fact, i believe firmly that global variable should never be used except in really special case when there's no others options).

    That said, CrazyNorman gave the answer (answer i didn't even thing heh).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 10:44 AM
  2. Replies: 6
    Last Post: 01-03-2007, 03:02 PM
  3. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 04:10 PM
  4. trouble scanning in... and link listing
    By panfilero in forum C Programming
    Replies: 14
    Last Post: 11-21-2005, 12:58 PM
  5. C++ program trouble
    By senrab in forum C++ Programming
    Replies: 7
    Last Post: 04-29-2003, 11:55 PM