Thread: Trouble with SDL_Rect

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Trouble with SDL_Rect

    Code:
    SDL_Rect r;
    
    r.x=16;//Removing this line clears errors
    produces:"Expected constructor destructor or type conversion before '.' token'.

    MinGW, WinXP

  2. #2
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    That code on its own looks fine. Can you show some of the surrounding code?
    Programming Your Mom. http://www.dandongs.com/

  3. #3
    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;
    }

  4. #4
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    You can't put actual statements, like r.x = 16 outside of function bodies. If you move that to main, it will fix that error.
    Programming Your Mom. http://www.dandongs.com/

  5. #5
    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).

  6. #6
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    It's one at night. I didn't really feel like going into the code too much.
    Programming Your Mom. http://www.dandongs.com/

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    17
    Yes, that was the problem, thank ppl

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