Hi,
I'm new to SFML, and so far things have gone pretty smoothly. However, when I try to make the player move, nothing happens. As in, the circle gets printed to the screen, but it doesn't move when I try to use key inputs. I tried putting it all into one file in case it was a multi-file issue, but to no avail. To my knowledge, I should be doing everything right, yet the image refuses to move.
Here's all my (relevant) code:
#pragma once
#include "declare.h"//this is a file that just includes the SFML files and adds some namespaces
//(that's why you don't see the "sf::" before anything, I set it as a namespace)
CircleShape player; //just a placeholder for the player, I don't have all the textures done for the game yet
void DrawPlayer()
{
player.setRadius(100);
player.setFillColor(Color::Blue);
player.setOutlineThickness(5);
player.setPosition(0, 0);
window.draw(player);
window.display();
}
void PlayerInput()
{
if (Keyboard::isKeyPressed(Keyboard::W))
{
player.move(0, 10);
}
else if (Keyboard::isKeyPressed(Keyboard::S))
{
player.move(0, -10);
}
else if (Keyboard::isKeyPressed(Keyboard::A))
{
player.move(-10, 0);
}
else if (Keyboard::isKeyPressed(Keyboard::D))
{
player.move(Vector2f(0, 50));
}
}
void Player()
{
DrawPlayer();
PlayerInput();
}
and here's the main function:
int main()
{
init();
GraphicsInit(); //initialization functions. They just load some placeholder textures and stuff like that
window.create(VideoMode(1024, 768), "Game Engine");
window.clear(Color::Black);
window.display();
DrawPlayer();
while (window.isOpen()) //main window loop
{
while (window.pollEvent(event)) //secondary window loop, polls for closing events
{
if (event.type == Event::Closed)
{
window.close();
}
PlayerInput();
}
}
}
I'm not sure if this is a SFML problem, a C++ problem, or just me not seeing something obvious (I haven't made anything as large as a game up until now, there's still some C++ stuff I don't know too well).
Keep in mind that this is some prototype code, so optimization isn't high on my priorities list right now. If you have some suggestions, though, that'd be nice
.
Anyway, back on track, does anyone see anything wrong with my code? I'd really like to fix this whole "no movement" problem... It's been bugging me for a few days now.