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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:18:53+00:00 2026-06-04T07:18:53+00:00

So, im trying to create a pacman game in SFML, i created a class

  • 0

So, im trying to create a pacman game in SFML, i created a class named fant for my ghosts,
im trying to pass a sf::Image has a parameter in my class, but it seems that I got a variable without a value, cause it load a blank image, but it has the same size (18×18 pixels) of the image im trying to load.

My class is

class fant {
public:
    void SetX(int i);
    int GetX();
    void SetY(int i);
    int GetY();
    void SetDX(int i);
    int GetDX();
    void SetDY(int i);
    int GetDY();
    void Sprite(sf::Sprite i);
    sf::Sprite GetSprite();
    void Image(sf::Image i);
protected:
    int posx,posy,dirx,diry;
    sf::Sprite sprite;
};

void fant::SetX(int i) { posx=i; sprite.SetX(posx); }
void fant::SetY(int i) { posy=i; sprite.SetY(posy); }
void fant::SetDX(int i) { dirx=i; }
void fant::SetDY(int i) { diry=i; }
void fant::Sprite(sf::Sprite i) { sprite=i; }
void fant::Image(sf::Image i) { sprite.SetImage(i); }
sf::Sprite fant::GetSprite() { return sprite; }
int fant::GetX() { return posx; }
int fant::GetY() { return posy; }
int fant::GetDX() { return dirx; }
int fant::GetDY() { return diry; }

and thats a function that create a new object

void addf() {
    fa.push_back(fant());
    int t=fa.size()-1;
    fa[t].SetX(684); fa[t].SetY(18);
    fa[t].Image(f1);
    fa[t].SetDX(6);
    fa[t].SetDY(0);
}

If i use

void fant::Image(sf::Image i) { sprite.SetImage(f1); }

it sets the “f1” image. (a global sf::Image)

  • 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-04T07:18:54+00:00Added an answer on June 4, 2026 at 7:18 am
    class fant {
    public:
    
    sf::Sprite GetSprite()
    {
       return sprite;
    }
    void LoadImage(std::string path);
    protected:
    int posx,posy,dirx,diry;
    sf::Sprite sprite;
    sf::Image image;
    };
    

    and

    void fant::LoadImage(std::string path)
    {
       image.LoadFromFile(path.c_str());
       sprite.SetImage(image);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a pacman game to learn XNA, but I am
I am trying to create a pacman-like game. I have an array that looks
I'm trying to create a basic Pacman game in C++ (I'll use Java syntax
Trying to create a background-image slideshow and am getting this error... This is the
I'm trying create a RCP Application with Eclipse, but I can't get past the
I'm trying create a new file with a Java Applet, but I don't know
I trying create a class derivated from System.Web.UI.Page and in override Render i set
I am trying create the image enlargement effect when you hover your mouse over
I'm trying create a log specifically for logging user account activity. I created this
I am trying create alert dailog using glade,but its not working .am i doing

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.