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 7880531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:09:59+00:00 2026-06-03T04:09:59+00:00

For my videogame in C – SDL I need to use a spritesheet I

  • 0

For my videogame in C – SDL I need to use a spritesheet I made myself.
The picture size is 100×100 and each picture I want to take is 25×25

I found somewhere a nice function which can do that for me:

// Wraps a rectangle around every sprite in a sprite sheet and stores it in an array of     rectangles(Clip[])

void spriteSheet(){

int SpriteWidth = 25; int SpriteHeight= 25; int SheetDimension = 4;
int LeSprites = SheetDimension * SheetDimension;// Number of Sprites on sheet
SDL_Rect Clip[LeSprites]; // Rectangles that will wrap around each sprite

int SpriteXNum = 0;// The number sprite going from left to right
int SpriteYNum = 0;// The number sprite going from top to bottom
int YIncrement = 0;// Increment for each row.
int i = 0;
for(i = 0; i< LeSprites; i++){// While i is less than number of sprites

    if(i = 0){// First sprite starts at 0,0
        Clip[i].x = 0;
        Clip[i].y = 0;
        Clip[i].w = SpriteWidth;
        Clip[i].h = SpriteHeight;
    }
    else{

        if(SpriteXNum < SheetDimension - 1 ){// If we have reached the end of the row, go back to the front of the next row
            SpriteXNum = 0;
        }
        if(YIncrement < SheetDimension - 1){
            SpriteYNum += 1;                         // Example of 4X4 Sheet
        }                                            //   ________________
        Clip[i].x = SpriteWidth * SpriteXNum;        //  | 0 | 1 | 2 | 3 |
        Clip[i].y = SpriteHeight * SpriteYNum;       //  |===============|
                                                     //  | 0 | 1 | 2 | 3 |
                                                     //  |===============|
        Clip[i].w = SpriteWidth;                     //  | 0 | 1 | 2 | 3 |
        Clip[i].h = SpriteHeight;                    //  |===============|
                                                     //  | 0 | 1 | 2 | 3 |
    }                                                //  |---------------|
    SpriteXNum++;
    YIncrement++;
}

}

But now I dont know how can I load my (png) picture on it to apply this function.

  • 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-03T04:10:01+00:00Added an answer on June 3, 2026 at 4:10 am

    It looks like this piece of code just gives you the clipping coordinates for each individual square of the sprite sheet. It doesn’t seem to interact with the image at all.

    If you want to load PNG you should use the additional SDL_image library. It will produce an SDL_Surface pointer which you can use with the clipping coordinates when you call SDL_BlitSurface to draw it to the screen.

    Note that you should try to get the SpriteDimension, etc values from the image itself (by dividing the image width (w) and height (h) by the size of an individual sprite).

    In the future, you could extend this idea by devising a SpriteSheet class which holds its calculated clipping positions and other information about the sprite sheet and which wraps the call to SDL_BlitSurface as appropriate.

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

Sidebar

Related Questions

Hi guys I want to win an hard videogame on my pc. The rule
i'm trying to develop my first and simple videogame. I'm using SDL.NET (wrapper .NET
I'm developing a video game for the iPhone. I want each level to save
I am currently working on a videogame, and i want to have the user
I have a model class called VideoGame . I need the class to get
If I were creating a videogame level editor in AS3 or .NET with a
When It comes to .plist files, it's a bad practice to use them to
Here is the problem, lets say we are making a video game and want
what i want to do is while user click the link, the clicks will
I have a MediaPlayer playing a file, and I want to continuously write logging

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.