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

  • SEARCH
  • Home
  • 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 9203753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:32:33+00:00 2026-06-17T23:32:33+00:00

I have a problem with my SDL program. My goal is to make a

  • 0

I have a problem with my SDL program. My goal is to make a dot move along a line. I have all the coordinates saved in a data file. So I just wanted to read them from the file and display the dot at the right position.
The dot class (which is named linefollower) looks like this.

class Linefollower
{
private:
    int x, y;
    char orientation;

public:
    //Initializes the variables
    Linefollower();

    void set(int m_x, int m_y, char m_orietnation);

    void show();

    char get_orientation();
};

Linefollower::Linefollower()
{
    x = 0;
    y = 0;
    orientation = 'E';
}

void Linefollower::set(int m_x, int m_y, char m_orientation)
{
    x = m_x;
    y = m_y;
    orientation = m_orientation;
}

void Linefollower::show()
{
    //Show the linefollower
    apply_surface(x, y, linefollower, screen );
}

char Linefollower::get_orientation()
{
    return orientation;
}

The apply_surface function.

void apply_surface( int x, int y, SDL_Surface * source, SDL_Surface* destination)
{
//Temporary rectangle to hold the offsets
SDL_Rect offset;

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

//Blit the surface
SDL_BlitSurface( source, NULL, destination, &offset);
}

The loop which ought to display the animation looks like this.

//While the user hasn't quit
    while( quit == false )
    {

        //Apply the surface to the screen
        apply_surface( 0, 0, image, screen );

        fin.read((char*) &my_linefollower, sizeof my_linefollower);
        if(my_linefollower.get_orientation() == 'Q')
            break;


        my_linefollower.show();

        //Upadate the screen
        if( SDL_Flip( screen ) == -1 )
        {
            return 1;
        }

        SDL_Delay(200);

    }

Now I was expecting, that I get a moving dot on the screen, but the only thing which I got is the background (image) for a few seconds untill the if(my_linefollower.get_orientation() == 'Q')
break;
was true. What do I do wrong?

PS: I guess it is worth noticing that I am a beginner in SDL and I took most of the code from a tutorial. Learning it exactly would be a waste of time for me, since it is unlikely that I am going to use it again any time soon.

  • 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-06-17T23:32:34+00:00Added an answer on June 17, 2026 at 11:32 pm

    First, you should change your offset in apply_surface to something like this:

    SDL_Rect offset = { x, y, 0, 0 };
    

    SDL_Rect doesn’t have a constructor to set your members to 0 by default, so you get uninitialized memory for your width and height.

    Also, you should check what linefollower contains, if it’s a valid SDL_Surface. Removing your file reading code and manually controlling a Linefollower will allow you to easily find where the error comes from.

    Use a debugger to validate your x and y coordinates.

    Other than that, you code should work, although your window will be unresponsive because you’re not pumping events through SDL_PollEvent.

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

Sidebar

Related Questions

This is an SDL problem, however I have the strong feeling that the problem
I have problem while loading data into html select when users press or click
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have problem with TableView its empty. In (.h) file: @interface TableViewController : UITableViewController{
I'm coding a simple SDL program with VC10. The problem that I am having
I have a problem with my development VM with SDL Tridion 2011 SP1 installed
I am developing a SDL OpenGL application on Ubuntu and have noticed a problem
I have this weird problem where whenever I #include SDL/SDL.h , my windows socket
I have a bmp-file of numbers and characters. My program reads keypresses and blits
I have problems compiling a D program that uses SDL using a makefile called

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.