Ah! I'm such an idiot :lol: . It took me a bit to process what you meant, and now I see what you mean. This is my new and improved code that actually works:
// Continually update the starup window until closed.
while( Window.IsOpen() )
{
// Process events.
while ( Window.GetEvents() )
{
// Close window : exit
if ( Window.WindowEventsType() == "Closed" )
{
// Tells that the window is closing.
DebugMessageString( "Window is being closed..." );
// Closes the window.
Window.CloseWindow();
}
// Close window : exit when pressing Escape "ESC".
if ( Window.KeyboardKeyPressed() == "Escape" )
{
// Tells that the window is closing.
DebugMessageString( "Window is being closed..." );
// Closes the window.
Window.CloseWindow();
}
// Plays a sound when pressing "Tab".
if ( Window.KeyboardKeyPressed() == "Tab" )
{
bolt.PlaySound();
}
// Moves green square to the right.
if ( Window.KeyboardKeyPressed() == "Right" )
{
playerMoveRight = true;
}
// Moves green square to the left.
if ( Window.KeyboardKeyPressed() == "Left" )
{
playerMoveLeft = true;
}
// Moves green square to the up.
if ( Window.KeyboardKeyPressed() == "Up" )
{
playerMoveUp = true;
}
// Moves green square to the down.
if ( Window.KeyboardKeyPressed() == "Down" )
{
playerMoveDown = true;
}
// Stops movement going to the right.
if ( Window.KeyboardKeyReleased() == "Right" )
{
playerMoveRight = false;
}
// Stops movement going to the left.
if ( Window.KeyboardKeyReleased() == "Left" )
{
playerMoveLeft = false;
}
// Stops movement going to the up.
if ( Window.KeyboardKeyReleased() == "Up" )
{
playerMoveUp = false;
}
// Stops movement going to the down.
if ( Window.KeyboardKeyReleased() == "Down" )
{
playerMoveDown = false;
}
// Left mouse button clicked.
if ( Window.MouseEventsType() == "MouseButtonPressed" )
{
// New button click event.
if( New.IsClicked( Window ) == true )
{
// Tells that the "New" button has been clicked.
DebugMessageString( "Mouse cursor clicked the \"New\" button..." );
}
// Load button click event.
if( Window.MouseLocationX() >= 70 && Window.MouseLocationX() <= 170 &&
Window.MouseLocationY() >= 360 && Window.MouseLocationY() <= 410 )
{
// Tells that the "Load" button has been clicked.
DebugMessageString( "Mouse cursor clicked the \"Load\" button..." );
}
// Tells where the mouse was clicked.
DebugMessageInt( Window.MouseLocationX() );
DebugMessageInt( Window.MouseLocationY() );
}
}
if( playerMoveLeft == true )
{
green.MoveX( -10 );
}
if( playerMoveRight == true )
{
green.MoveX( 10 );
}
if( playerMoveUp == true )
{
green.MoveY( -10 );
}
if( playerMoveDown == true )
{
green.MoveY( 10 );
}
// Draws the menu.
Window.Render( menu.GetSprite() );
// Draws the green box.
Window.Render( green.GetSprite() );
// Displays the updated window.
Window.Update();
}
Thanks a ton Laurent! I need to get more sleep before I start this again, in order to prevent that from happening again
.
The event that is triggered by pressing down the 'Tab' key does use sf::Event and is in the event loop. I simply made it where I was working with strings rather than events outside my wrapper library.
// Processes the event(s) to see what key on the keyboard is being released.
std::string Window::KeyboardKeyPressed()
{
if ( ( Event.Type == sf::Event::KeyPressed ) && ( Event.Key.Code == sf::Key::Tab ) )
{
return "Tab";
}
}
It does use an sf::Event, and it is processed in the event loop ( from what i can tell ). Though then again, if you are able to elaborate on what you mean, that would be nice. I simply didn't want to have to type that out each time I wanted to work with checking for events, so I just wanted to have to check for strings being returned from that particular function
. I cut down all the other tested events in that function ( to only show the important one ), but that's the same thing for all the other events that could be checked by SFML.
As for the second thing you mentioned, I believe I corrected that now. The events are tested in the event loop, and the game logic is outside with the rest in the game loop. The events change bool variables to be tested in the game loop to see if the sprite needs to be moved a certain direction.
Again, thank you for all the help! <3 SFML ( sorry SDL, it just wasn't working out :wink: ).