So i'm trying to position the rectangle in the middle of the window, however, everytime i increase the y value of the rectangle position, it seems to go down instead. Here is the code:
// MyPongGame.cpp : Defines the entry point for the console application.
// Using SFML Game Library
#include "stdafx.h"
#include <iostream>
#include <string>
#include <SFML/Graphics.hpp>
class CreatingShapes
{
public:
sf::RectangleShape paddleShape;
sf::CircleShape ballShape;
CreatingShapes(sf::Vector2f paddlePosition, sf::Vector2f paddleSize, sf::Color paddleColor){
paddleShape.setPosition(paddlePosition);
paddleShape.setSize(paddleSize);
paddleShape.setFillColor(paddleColor);
}
CreatingShapes(sf::Vector2f ballPosition, float ballRadius, sf::Color ballColor)
{
ballShape.setPosition(ballPosition);
ballShape.setRadius(ballRadius);
ballShape.setFillColor(ballColor);
}
};
int main()
{
sf::RenderWindow renderWindow(sf::VideoMode(500, 350), "My Pong Game");
CreatingShapes leftPaddle(CreatingShapes(sf::Vector2f(5,300), sf::Vector2f(10,75), sf::Color::Blue));
CreatingShapes rightPaddle(CreatingShapes(sf::Vector2f(485,250), sf::Vector2f(10,75), sf::Color::Red));
CreatingShapes pongBall(CreatingShapes(sf::Vector2f(250, 175), 5, sf::Color::Magenta));
while(renderWindow.isOpen()){ //The Game loop or Main loop
//Events may only be declared in the same function as the window object
sf::Event event; //Creates SFML Event object
while(renderWindow.pollEvent(event)){//Check which events were triggered, whther its Key pressed, mouse moved, etc.
if(event.type == sf::Event::Closed){ //if Close Request event was clicked then:
renderWindow.close(); //closes window
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
// leftPaddle.paddleShape.move(0, -3.0f);
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
//leftPaddle.paddleShape.move(0, 3.0f);
}
}
//Clear the screen
renderWindow.clear(sf::Color::Cyan);
//draw everything here
renderWindow.draw(leftPaddle.paddleShape);
renderWindow.draw(rightPaddle.paddleShape);
renderWindow.draw(pongBall.ballShape);
//end the current frame
renderWindow.display();
}
return 0;
}
How can i get the rectangle in the middle?