4 Replies - 2137 Views - Last Post: 10 September 2011 - 05:57 AM Rate Topic: -----

#1 XeVile  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 44
  • Joined: 23-August 11

Creating a custom SFML Drawable object

Posted 09 September 2011 - 12:55 PM

Well, I am creating a very basic game(Click the ball) using classes and as I have tried to make the custom drawable class. So far its not working...
Here is the code:-

Ball.h

#ifndef BALL_H
#define BALL_H

#include <SFML/Graphics.hpp>

class Ball
{
//Public Functions
public:
	sf::Drawable ball(Sprite sBall);
	sf::Drawable ball(Sprite sBall, float x, float y);
	sf::Drawable ball(Sprite sBall, float x, float y,float hSpeed, float vSpeed);

//Private Declarations
private:
	Sprite S_Ball;
	float X;
	float Y;
	float H_Speed;
	float V_Speed;
};
#endif


Ball.cpp

#include "Ball.h"

//Gets the Sprite only and sets the X and Y coordinates to default values 0
Ball::ball(Sprite sBall)
{
	S_Ball = sBall;
	X = 0;
	Y = 0;
}

//Gets the Sprite, X and Y coordinates
Ball::ball(Sprite sBall, float x, float y)
{
	S_Ball = sBall;
	X = x;
	Y = y;
}

//Gets the Sprite, X, Y coordinates, horizontal moving speed and vertical moving speed
Ball::ball(Sprite sBall, float x, float y, float hSpeed, float vSpeed)
{
	S_Ball = sBall;
	X = x;
	Y = y;
	H_Speed = hSpeed;
	V_Speed = vSpeed;
}


ClickTheBall.cpp

//Click The Ball Game
#include <SFML/Graphics.hpp>
#include "Ball.h"

using namespace sf;

int main()
{
	RenderWindow app(VideoMode(800, 600, 32), "Click The Ball! v1.0");

	Image ballSrc = ballSrc.LoadFromFile("Ball.png");
	Sprite ballSprite = ballSprite.GetImage(ballSrc);

	Ball::ball bBall = new Ball::ball(ballSprite);

	while(app.IsOpened())
	{
		Event eEvent;
		while(app.GetEvent(eEvent))
		{
			if(eEvent.Type == Event::Closed)
				app.Close();
		}

		app.Clear();

		app.Draw(bBall);

		app.Display();
	}
}


Thanks
Arunabh

P.S This is my first complex(for me) class that I am doing. Please correct me if I am wrong with the concept of classes also.

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a custom SFML Drawable object

#2 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4559
  • View blog
  • Posts: 7,980
  • Joined: 08-June 10

Re: Creating a custom SFML Drawable object

Posted 09 September 2011 - 01:39 PM

What's not working? Read these and please provide more information:

"It Doesn't Work!" That's not good enough!
It Still Doesn't Work!.
Was This Post Helpful? 0
  • +
  • -

#3 XeVile  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 44
  • Joined: 23-August 11

Re: Creating a custom SFML Drawable object

Posted 10 September 2011 - 02:27 AM

Oh, I am sorry I forgot to post the errors..
Errors:-

1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(10) : error C2061: syntax error : identifier 'Sprite'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(10) : error C2259: 'sf::Drawable' : cannot instantiate abstract class
1>        due to following members:
1>        'void sf::Drawable::Render(sf::RenderTarget &) const' : is abstract
1>        f:\microsoft visual studio 9.0\vc\include\sfml\graphics\drawable.hpp(341) : see declaration of 'sf::Drawable::Render'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(11) : error C2061: syntax error : identifier 'Sprite'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(11) : error C2259: 'sf::Drawable' : cannot instantiate abstract class
1>        due to following members:
1>        'void sf::Drawable::Render(sf::RenderTarget &) const' : is abstract
1>        f:\microsoft visual studio 9.0\vc\include\sfml\graphics\drawable.hpp(341) : see declaration of 'sf::Drawable::Render'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(12) : error C2061: syntax error : identifier 'Sprite'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(12) : error C2259: 'sf::Drawable' : cannot instantiate abstract class
1>        due to following members:
1>        'void sf::Drawable::Render(sf::RenderTarget &) const' : is abstract
1>        f:\microsoft visual studio 9.0\vc\include\sfml\graphics\drawable.hpp(341) : see declaration of 'sf::Drawable::Render'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(16) : error C2146: syntax error : missing ';' before identifier 'S_Ball'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(4) : error C2065: 'Sprite' : undeclared identifier
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(4) : error C2146: syntax error : missing ')' before identifier 'sBall'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(4) : error C2761: 'sf::Drawable Ball::ball(void)' : member function redeclaration not allowed
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(4) : error C2059: syntax error : ')'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(5) : error C2143: syntax error : missing ';' before '{'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(5) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(12) : error C2065: 'Sprite' : undeclared identifier
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(12) : error C2146: syntax error : missing ')' before identifier 'sBall'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(12) : error C2761: 'sf::Drawable Ball::ball(void)' : member function redeclaration not allowed
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(12) : error C2059: syntax error : ')'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(13) : error C2143: syntax error : missing ';' before '{'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(13) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(20) : error C2065: 'Sprite' : undeclared identifier
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(20) : error C2146: syntax error : missing ')' before identifier 'sBall'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(20) : error C2761: 'sf::Drawable Ball::ball(void)' : member function redeclaration not allowed
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(20) : error C2059: syntax error : ')'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(21) : error C2143: syntax error : missing ';' before '{'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.cpp(21) : error C2447: '{' : missing function header (old-style formal list?)
1>ClickTheBall.cpp
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(10) : error C2061: syntax error : identifier 'Sprite'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(10) : error C2259: 'sf::Drawable' : cannot instantiate abstract class
1>        due to following members:
1>        'void sf::Drawable::Render(sf::RenderTarget &) const' : is abstract
1>        f:\microsoft visual studio 9.0\vc\include\sfml\graphics\drawable.hpp(341) : see declaration of 'sf::Drawable::Render'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(11) : error C2061: syntax error : identifier 'Sprite'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(11) : error C2259: 'sf::Drawable' : cannot instantiate abstract class
1>        due to following members:
1>        'void sf::Drawable::Render(sf::RenderTarget &) const' : is abstract
1>        f:\microsoft visual studio 9.0\vc\include\sfml\graphics\drawable.hpp(341) : see declaration of 'sf::Drawable::Render'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(12) : error C2061: syntax error : identifier 'Sprite'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(12) : error C2259: 'sf::Drawable' : cannot instantiate abstract class
1>        due to following members:
1>        'void sf::Drawable::Render(sf::RenderTarget &) const' : is abstract
1>        f:\microsoft visual studio 9.0\vc\include\sfml\graphics\drawable.hpp(341) : see declaration of 'sf::Drawable::Render'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(16) : error C2146: syntax error : missing ';' before identifier 'S_Ball'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\ball.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\clicktheball.cpp(11) : error C2440: 'initializing' : cannot convert from 'bool' to 'sf::Image'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\clicktheball.cpp(12) : error C2660: 'sf::Sprite::GetImage' : function does not take 1 arguments
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\clicktheball.cpp(14) : error C2146: syntax error : missing ';' before identifier 'bBall'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\clicktheball.cpp(14) : error C3867: 'Ball::ball': function call missing argument list; use '&Ball::ball' to create a pointer to member
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\clicktheball.cpp(14) : error C2065: 'bBall' : undeclared identifier
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\clicktheball.cpp(14) : error C2061: syntax error : identifier 'ball'
1>c:\users\arunabh\documents\visual studio 2008\projects\clicktheball\clicktheball\clicktheball.cpp(27) : error C2065: 'bBall' : undeclared identifier

Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Creating a custom SFML Drawable object

Posted 10 September 2011 - 02:50 AM

With all due respect these error tell me you need to learn C++. Learn the difference between a concrete and abstract class and how to use each one properly, then revise this code. It shouldn't take too long.
Was This Post Helpful? 0
  • +
  • -

#5 XeVile  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 44
  • Joined: 23-August 11

Re: Creating a custom SFML Drawable object

Posted 10 September 2011 - 05:57 AM

Okay then thank you for your reply.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1