Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6833313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:57:47+00:00 2026-05-26T22:57:47+00:00

I’ve been following LazyFoo’s tutorial for a while. But I haven’t been able to

  • 0

I’ve been following LazyFoo’s tutorial for a while. But I haven’t been able to get this to initialize a week a go. I went back to it recently, after error checking, I found it that the window initializes properly, but the images won’t load. What is the reason for it?

 #include "SDL/SDL.h"
    #include <string>

    //setting screen info
    const int SCH=640;
    const int SCW=480;
    const int BBP=32;
    const char* name = "TEHGAEM";

    // sprite height and width
    const int SPH=45;
    const int SPW=45;

//initilize event
    SDL_Event event;

//loading surfaces for screen, sprite, and temp sprite   
    SDL_Surface *screen=NULL;
    SDL_Surface *sprite=NULL;
    SDL_Surface *temp = NULL;
//making class for movable objects
    class Player
    {
        private:
        int x,y;
        int xVel,yVel;
        public:
        Player();
        void show();
        void move();
        void handle_input();
    };

//initializing variables
    Player::Player()
    {
        x=0;
        y=0;
        xVel=0;
        yVel=0;
    }
 //intended to show player picture
    void Player::show()
    {
         SDL_Rect pos;
        pos.x=x;
        pos.y=y;
        SDL_BlitSurface(sprite, NULL, screen, &pos);
        SDL_UpdateRects(screen, 1, &pos);
    }
  //setting input
    void Player::handle_input()
    {
        if (event.type ==SDL_KEYDOWN)
        {
            switch (event.key.keysym.sym)
            {
                case SDLK_UP: yVel -= SPH /2; break;
                case SDLK_DOWN: yVel += SPH /2; break;
                case SDLK_LEFT: xVel -=SPW /2; break;
                case SDLK_RIGHT: xVel +=SPW /2; break;
            }
        }
        if (event.type == SDL_KEYUP)
        {
            switch(event.key.keysym.sym)
            {
                case SDLK_UP: yVel += SPH /2; break;
                case SDLK_DOWN: yVel -= SPH /2; break;
                case SDLK_LEFT: xVel +=SPW /2; break;
                case SDLK_RIGHT: xVel -=SPW /2; break;
            }
        }
    }

    void Player::move()
    {
        x=+xVel;
        y=+yVel;
        if (x >= SCW)
        {
            x-10;
        }
        if (y >= SCH)
        {
            y-10;
        }
    }

//initializing program

    bool init()
    {
        if (SDL_Init(SDL_INIT_EVERYTHING)==-1)
        {
            return false;
        }
        screen = SDL_SetVideoMode(SCH,SCW,BBP, SDL_SWSURFACE);
        if (screen == NULL)
        {
            return false;
        }
        SDL_WM_SetCaption(name, NULL);
        return true;
    }

//loading images
    bool somethings()
    {
        temp = SDL_LoadBMP("sprite.bmp");
        if (temp == NULL)
        {
            return false;
        }
        sprite = SDL_DisplayFormat (temp);
        if (sprite ==NULL)
        {
            return false;
        }
        SDL_FreeSurface(temp);

        return true;
    }

    //clean up function
    void clean()
    {
        SDL_FreeSurface(sprite);
        SDL_Quit();
    }




    int main(int argc, char* args[])
    {
        Player P1;
        bool quit;
        if (init() == false)
        {
            return 1;
        }

        if (somethings() ==false)
        {
            return 1;
        }

        while (quit ==false)
        {
            while (SDL_PollEvent(&event))
            {
                P1.handle_input();
                if (event.type == SDL_QUIT)
                {
                    quit == true;
                }
            }
            if (SDL_Flip(screen) ==-1)
            {
                return 1;
            }
            P1.move();
            P1.show();
        }
        clean();
        return 0;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:57:47+00:00Added an answer on May 26, 2026 at 10:57 pm

    This isn’t completely related to your problem but the varible bool quit; isn’t defined as true or false before the main while( quit == false ) { ... }loop. This could produce undefined while loop behavior.

    int main(int argc, char* args[])
        {
            Player P1;
            bool quit = false; // CHANGE THIS AND SEE WHAT HAPPENS
            if (init() == false)
            {
                return 1;
            }
    
            if (somethings() ==false)
            {
                return 1;
            }
    
            while (quit ==false)
            {
                while (SDL_PollEvent(&event))
                {
                    P1.handle_input();
                    if (event.type == SDL_QUIT)
                    {
                        quit == true;
                    }
                }
                if (SDL_Flip(screen) ==-1)
                {
                    return 1;
                }
                P1.move();
                P1.show();
            }
            clean();
            return 0;
        }
    

    About the images not loading, step through your program with a debugger and watch your somethings()function and follow the variables temp and sprite.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.