Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with Returning Sprite  (Read 1214 times)

0 Members and 1 Guest are viewing this topic.

collechess

  • Newbie
  • *
  • Posts: 10
    • View Profile
Problem with Returning Sprite
« on: May 23, 2013, 08:27:36 pm »
I just recently got back into coding c++ after about a year's hiatus, so this may well be a basic mistake.  I decided to drop SDL and I am starting to learn SFML.  I created a basic Pong game, but when I tried to implement classes it didn't work.  I tried to simplify the problem by just getting a class to represent an image, however I keep raising an error.  I've torn my hair out trying to fix this, but I think I've reached a point where even if the solution was at first obvious, I will not find it.  The program only encompasses 3 files.

main.cpp
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <windows.h>
#include "ball.h"



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
               LPSTR lpCmdLine, int nCmdShow)
{
    sf::RenderWindow window(sf::VideoMode(200, 300), "Test");
   Ball ball;
       
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        window.clear();
        window.draw(ball.get_Sprite());
        window.display();
    }

    return 0;
}

ball.h

#ifndef BALL_H
#define BALL_H
#include "SFML\Graphics.hpp"

class Ball
{
private:
        sf::Texture texture;
        sf::Sprite sprite;

public:
        Ball();
        sf::Sprite get_Sprite();
       

};


#endif

ball.cpp

#include "ball.h"
#include "SFML\Graphics.hpp"

Ball::Ball()
{
        texture.loadFromFile("ball_img.png");
        sprite.setTexture(texture);
}

sf::Sprite get_Sprite()
{
        return sprite;
}

The error returned is ball.cpp(12): error C2065: 'sprite' : undeclared identifier.  Thank you.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with Returning Sprite
« Reply #1 on: May 23, 2013, 08:36:30 pm »
Quote
sf::Sprite Ball::get_Sprite()
Laurent Gomila - SFML developer

collechess

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Problem with Returning Sprite
« Reply #2 on: May 23, 2013, 08:59:35 pm »
Thank you so much, I really feel like an idiot now.

 

anything