Hello,
I'm trying to make an Pong clone however I have some problems with constructing and moving static shapes like circle and rectangle.
Let's start with circle,
First of all I have an primitive class called Circle.
Circle class:
class Circle
{
public:
Circle(const sf::Vector2f &position,
const float &radius,
const sf::Color &fillerColor,
const float &outlineThickness,
const sf::Color &outlineColor);
sf::Vector2f getPosition() const;
float getRadius() const;
const sf::Shape &getDrawableObject() const;
void draw(sf::RenderTarget &renderTarget);
void bounce(const sf::Vector2f &displacement);
private:
sf::Vector2f position_;
sf::Shape shape_;
float radius_;
sf::Color fillerColor_;
float outlineThickness_;
sf::Color outlineColor_;
};
I'm constructing my Circle object like fallowing:
Circle::Circle(const sf::Vector2f &position,
const float &radius,
const sf::Color &fillerColor,
const float &outlineThickness,
const sf::Color &outlineColor)
{
position_ = position;
radius_ = radius;
fillerColor_ = fillerColor;
outlineThickness_ = outlineThickness;
outlineColor_ = outlineColor;
shape_ = sf::Shape::Circle(position_,
radius_,
fillerColor_,
outlineThickness_,
outlineColor_);
}
and here is my move function:
void Circle::bounce(const sf::Vector2f &displacement)
{
position_ += displacement;
shape_.SetPosition(position_);
}
now my question is when I use
shape_.SetCenter(position_);
instead of current one it doesn't work. Do you know why?
Also fallowing part fallowing part from constructor is not working as well
shape_ = sf::Shape::Circle(position_,
radius_,
fillerColor_,
outlineThickness_,
outlineColor_);
however if I change position_ with fallowing parameter
sf::Vector2f(radius_ / 2, radius_ / 2)
then it's working. I dunno why it's not working, on console the numbers seem right. I mean it's just wierd. By working, I mean it's drawing beucase with position_
parameter it's not showing on screen(or it's on some coordinate out of screen)
now my problem with Rectangle is something smilar
here is my Rectangle class:
class Rectangle
{
public:
Rectangle(const sf::Vector2f &position,
const float &width,
const float &height,
const sf::Color &fillerColor,
const float &outlineThickness,
const sf::Color &outlineColor);
sf::Vector2f getPosition() const;
float getWidth() const;
float getHeight() const;
const sf::Shape &getDrawableObject() const;
void draw(sf::RenderTarget &renderTarget);
void moveUp(const float &displacement);
void moveDown(const float &displacement);
private:
sf::Vector2f position_;
float width_;
float height_;
sf::Color fillerColor_;
float outlineThickness_;
sf::Color outlineColor_;
sf::Shape shape_;
};
I'm constructing my Rectangle object like fallowing:
Rectangle::Rectangle(const sf::Vector2f &position,
const float &width,
const float &height,
const sf::Color &fillerColor,
const float &outlineThickness,
const sf::Color &outlineColor)
{
position_ = position;
width_ = width;
height_ = height;
fillerColor_ = fillerColor;
outlineThickness_ = outlineThickness;
outlineColor_ = outlineColor;
sf::Vector2f lowerRightPoint;
lowerRightPoint.x = position_.x + width;
lowerRightPoint.y = position_.y + height;
shape_ = sf::Shape::Rectangle(position_,
lowerRightPoint,
fillerColor_,
outlineThickness_,
outlineColor_);
}
My Rectangle objectets does not even drawn(or drawn but somewhere else, not in screen) I think there is something wrong with fallowing lines
shape_ = sf::Shape::Rectangle(position_,
lowerRightPoint,
fillerColor_,
outlineThickness_,
outlineColor_);
I think it's position_ again but this time I couldn't find a way to show it on screen
is there any better way to create a static shape?
finally I'm trying to move my rectangle objects like fallowing:
void Rectangle::moveUp(const float &displacement)
{
position_.y -= displacement;
shape_.s
}
void Rectangle::moveDown(const float &displacement)
{
position_.y += displacement;
shape_.SetPosition(position_);
}
even I can't move it right now I can see a problem incoming which in above lines I only move the upper left point of rectangle(I assume).
does SetPosition take care of lower right point as well or do I need to add something else.
I hope I made my points clear this time.
Thank you in advance.