I was not sure where this post belonged, since I don't know if it is a graphics error.
Currently I am writing a small version of Pong. My code works great so far, with one little issue. In the code editor itself (I am using code::blocks if it matters), using the . operator on my sprite is doing nothing. Other things like sf:: or App. work fine in the sense they show a list of usable options or at least let me type them myself. However, for some reason this is not working for my bluePaddleSprite when I try bluePaddleSprite.
Currently I am trying to add collision of sorts so it does not go out of bounds, and I was going to do this by checking if the bluePaddleSprite's y was in bounds of my 800x600 window, and if so set it back a few or something. Code follow:
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Pong");
sf::Image bluePaddle;
if (!bluePaddle.LoadFromFile("bluePaddle.png"))
{
std::cout << "Error, bluePaddle.png failed to load";
}
sf::Sprite bluePaddleSprite(bluePaddle);
bluePaddleSprite.SetY(100);
bluePaddleSprite.SetScaleY(1.5);
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// A key has been pressed
if (Event.Type == sf::Event::KeyPressed)
{
// Escape key : exit
if (Event.Key.Code == sf::Key::Escape)
App.Close();
}
}
// Clear the screen
App.Clear(sf::Color(0, 0, 0));
if (App.GetInput().IsKeyDown(sf::Key::W)) {
bluePaddleSprite.Move(0, 150 * App.GetFrameTime() * -1);
} else if (App.GetInput().IsKeyDown(sf::Key::S)) {
bluePaddleSprite.Move(0, 150 * App.GetFrameTime() * 1);
}
App.Draw(bluePaddleSprite);
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
It compiles and runs, but when I try to use the . with my sprite nothing happens. Any help would be very welcome.
Thank you.