I don't really know if this is just me being stupid(Which it probably is..), but I have two buttons, and I set the location of them with the location property. Now I'm trying to see if the button has been pressed using an IntRect, but its in the top left corner(after some rigorous debugging), indicating that the property wasn't updated.
This is the part where I try to see if the button is pressed..
public void Update(RenderWindow window)
{
if (Mouse.IsButtonPressed(Mouse.Button.Left))
{
//Program.WriteDebug("Mouse was clicked.");
Vector2i mousePosition = Mouse.GetPosition(window);
if (play.TextureRect.Contains(mousePosition.X, mousePosition.Y))
{
// Is not displayed.
Program.WriteDebug("Play button pressed.");
}
else if (quit.TextureRect.Contains(mousePosition.X, mousePosition.Y))
{
// Not displayed either.. Woo.
Program.WriteDebug("Quit button pressed");
}
}
}
And the whole class if you're wondering.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFML.Graphics;
using SFML.Window;
namespace TheStillmanProject.Game.Scenes
{
class MainMenu : IScene
{
bool didLoad = false;
Sprite background;
Sprite header;
Sprite play;
Sprite quit;
public void Load()
{
uint width = Game.WIDTH;
uint height = Game.HEIGHT;
string contentDir = Environment.CurrentDirectory + "\\Content\\Main Menu\\";
background = new Sprite(new Texture(contentDir + "background.jpg"));
header = new Sprite(new Texture(contentDir + "stillmanproject.png"));
play = new Sprite(new Texture(contentDir + "playButton.png"));
quit = new Sprite(new Texture(contentDir + "quitbutton.png"));
background.Position = new Vector2f(0, 0);
header.Position = new Vector2f(width / 2 - header.TextureRect.Width / 2, 100);
header.Texture.Smooth = true;
play.Position = new Vector2f(width / 2 - play.TextureRect.Width / 2, 325);
//This code will hide the button. ffs
//play.TextureRect = new IntRect((int) width / 2 - play.TextureRect.Width / 2, 325, play.TextureRect.Height, play.TextureRect.Width);
quit.Position = new Vector2f(width / 2 - play.TextureRect.Width, 425);
//Same thing, the button will be hidden.
//quit.TextureRect = new IntRect((int)width / 2 - quit.TextureRect.Width / 2, 425, quit.TextureRect.Height, quit.TextureRect.Width);
// Smooth out buttons.
play.Texture.Smooth = true;
quit.Texture.Smooth = false;
didLoad = true;
}
public bool DidLoad()
{
return didLoad;
}
public void Draw(RenderWindow window)
{
window.Draw(background);
window.Draw(header);
window.Draw(play);
window.Draw(quit);
}
public void Update(RenderWindow window)
{
if (Mouse.IsButtonPressed(Mouse.Button.Left))
{
//Program.WriteDebug("Mouse was clicked.");
Vector2i mousePosition = Mouse.GetPosition(window);
if (play.TextureRect.Contains(mousePosition.X, mousePosition.Y))
{
//Doesnt show up.
Program.WriteDebug("Play button pressed.");
}
else if (quit.TextureRect.Contains(mousePosition.X, mousePosition.Y))
{
//doesnt show up
Program.WriteDebug("Quit button pressed");
}
}
}
public void Dispose()
{
}
}
}
Also, the entire application is set as a console application to see the console.
One more thing, when I try to manually set the IntRect, the button just disappears. Sigh.