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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:03:21+00:00 2026-05-27T14:03:21+00:00

i need some advice. i have 2 classes for a game that i am

  • 0

i need some advice. i have 2 classes for a game that i am making, and those classes are:

Graphics
Sprite

the sprite class consists of an image buffer for the image, an (x, y) offset, and a width and a height. the graphics class has a buffer for the screen. the screen buffer can have things blitted to it like the image buffer for the sprite.

are there any recommended ways of blitting the sprite’s image buffer to the graphics screen buffer? i had 2 ideas:

have a method like this (in the sprite class):

void Sprite::blit(SDL_Surface* screen)
{
    // code goes here
}

or this (in the graphics class):

void Graphics::blit(Sprite sprite)
{
   // code
}

or even this (also in the graphics class):

void Graphics::blit(SDL_Surface* aSpritesImageBuffer)
{
   // code
}

there are problems with all of these tho. in both classes, i use encapsulation to hide both the sprite’s image buffer and the graphics component’s screen buffer. they are returned as a constant so no one can manipulate them without using the functions provided in the class. this is how i did it:

class Graphics
{
public:
    const getScreenBuffer() const {return screenBuffer;}
private:
    screenBuffer;
};

^ same with the sprite’s image buffer.

so if i tried (in my main class)

void handleRendering()
{
    graphics.blit(sprite.getImageBuffer());
}

that would not be very good?

or even:

void handleRendering()
{
    graphics.blit(sprite);
}

and i don’t think this is good:

void handleRendering()
{
    sprite.blit(graphics.getScreenBuffer());
}               

are there any better methods of doing this without getting errors like const to non-const? << i get an error like that.

  • 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-27T14:03:21+00:00Added an answer on May 27, 2026 at 2:03 pm

    I don’t know if your sprite class is only a low-level rendering element (so, basically only a wrapper around SDL_Surface*), or if it’s already the actual representation of a creature in your game. In the latter case, as an alternative to your different solutions, you could only keep an id of the bitmap in the sprite class, among other properties like coordinates, size, speed… And the actual code dependent of the rendering technology in a separate set of classes, like “Graphics”, “BitmapCollection”…

    So on one side, you would have a “clean” sprite class with simple properties like position, size, speed… and on the other side, the “dirty stuff”, with low level SDL_nnn objects and calls. And one day, that id would not represent a bitmap, but for example a 3D model.

    That would give something like that:

    void handleRendering()
    {
        graphics.blit( bitmapCollection.Get( sprite.getImageId());
    }
    

    I don’t know if the image of a sprite really has to be private or read only. Several sprites could share the same image, other classes like “SpecialEffects” could modify the sprite bitmaps, swap them, make semi-transparent following ghosts on screen and so on.

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

Sidebar

Related Questions

I need some advice. (For those who have already read this before I have
Experts - I need some advice in the following scenario. I have a configuration
I have been playing with Compact Framework lately and i need some advice. I
I need some expect advice on how to handle the following:- I have a
I have this thing that i need to do and some advices will be
I need to have some of my C++ classes, functions and namespaces renamed as
Okay, I need some solid OOP advice. Here's the setup: I have a player
Need some advice, I'm after a decent process/task manager for Ubuntu. Basically I have
I need some advice as to how I easily can separate test runs for
I need some advice on what kind of pattern(s) I should use for pushing/pulling

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.