Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Quentin

Pages: [1]
1
Graphics / Re: GetGlobalBounds not updating?
« on: January 09, 2013, 09:37:39 pm »
I checked out and compiled the latest release with VS 2012, and, like you said, everything works as expected. Thank you very much, was beginning to doubt myself there.
I had used the RC version from the website because I didn't know about the repository before reading on the forum, that was obviously a mistake. Perhaps it would have been better to wait for the finished 2.0 version before using SFML for the first time in my life, but I was anxious to get started ;)

Just one final thing, when building SFML.net it says it expects Tao, but Tao is superseded by OpenTk, should you use the former or the latter? At the moment I just took the errors in stride because I have neither on my machine.

2
Graphics / Re: GetGlobalBounds not updating?
« on: January 09, 2013, 08:51:15 pm »
Hm... so what you're saying is that my code is not the problem? When you move the sprite you can click it and it will close the window?

Perhaps I should check if pulling the newest sources works, then.

3
Graphics / Re: GetGlobalBounds not updating?
« on: January 09, 2013, 08:32:31 pm »
But the sprite moves just fine this way, when redrawing the window it uses the correct new position. Why shouldn't it use that new position the next time an event is handled? I don't know what values GetGlobalBounds is using, could be it's not sprite.Position?

Edit: To clarify, onMousePressed and onKeyPressed are called by window.DispatchEvents(), so in that way they are in the main loop...

4
Graphics / Re: GetGlobalBounds not updating?
« on: January 09, 2013, 07:34:22 pm »
Of course.

Class Program with Main:
class Program
    {      
        static void Main(string[] args)
        {
            SFMLProgram program = new SFMLProgram();
            program.StartSFMLProgram();
        }
    }

Class SFMLProgram:
    class SFMLProgram
    {
        RenderWindow window;
        Sprite sprite;

        public void OnClose(object sender, EventArgs e)
        {
            window.Close();
        }
        public void OnKeyPressed(object sender, KeyEventArgs e) {
            float x = sprite.Position.X;
            float y = sprite.Position.Y;
            switch(e.Code) {
                case Keyboard.Key.Up:
                    y -= 10f;
                    break;
                case Keyboard.Key.Down:
                    y += 10f;
                    break;
                case Keyboard.Key.Left:
                    x -= 10f;
                    break;
                case Keyboard.Key.Right:
                    x += 10f;
                    break;
            }
            Vector2f newPosition = new Vector2f(x, y);
            sprite.Position = newPosition;
            Console.WriteLine(sprite.GetGlobalBounds().ToString());
        }
        public void OnMousePressed(object sender, MouseButtonEventArgs e)
        {
            Vector2f mousePos = new Vector2f(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y);
            switch (e.Button)
            {
                case Mouse.Button.Left:
                    Console.WriteLine(mousePos);
                    if(sprite.GetGlobalBounds().Contains(mousePos.X, mousePos.Y)) {
                        window.Close();
                    }
                    break;
                case Mouse.Button.Right:
                    break;
            }
        }
        public void StartSFMLProgram()
        {
            window = new RenderWindow(new VideoMode(800, 600), "Testwindow");
            window.SetVisible(true);
            window.Closed += new EventHandler(OnClose);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(OnMousePressed);
            Texture texture = new Texture("placeholder.gif");
            sprite = new Sprite(texture);
            // Mainloop
            while (window.IsOpen())
            {
                window.DispatchEvents();
                window.Clear(Color.Black);
                window.Draw(sprite);
                window.Display();
            }
        }
    }

5
Graphics / GetGlobalBounds not updating?
« on: January 09, 2013, 07:11:07 pm »
Edit: I've posted this in graphics because I think it's not .net specific.

Hello,

I have just started working with SFML (2.0 RC)  in C# with the .Net Binding. To get a feel for the whole thing I wrote a simple test application with the help of the API documentation. I'm drawing a sprite with a 250*250 test texture, which I'm moving ten pixels at a time by modifying its position via a KeyPressed Event Handler. Additionally, I've registered a MouseButtonPressed Event Handler for clicking my sprite. To do that, I'm comparing the mouse position with the FloatRect of the sprite.

public void OnMousePressed(object sender, MouseButtonEventArgs e)
    {
        Vector2f mousePos = new Vector2f(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y);
        switch (e.Button)
        {
            case Mouse.Button.Left:
                if(sprite.GetGlobalBounds().Contains(mousePos.X, mousePos.Y)) {
                    window.Close();
                }
                break;
        }
    }

That works like a charm. But, if I have moved the sprite previously, then nothing happens when clicking on the new position. Instead, the window closes when I click the old position of the sprite.
This is my OnKeyPressed method:

public void OnKeyPressed(object sender, KeyEventArgs e)
    {
        float x = sprite.Position.X;
        float y = sprite.Position.Y;
        switch(e.Code) {
            case Keyboard.Key.Up:
                y -= 10f;
                break;
            case Keyboard.Key.Down:
                y += 10f;
                break;
            case Keyboard.Key.Left:
                x -= 10f;
                break;
            case Keyboard.Key.Right:
                x += 10f;
                break;
        }
        Vector2f newPosition = new Vector2f(x, y);
        sprite.Position = newPosition;
        Console.WriteLine(sprite.GetGlobalBounds().ToString());
    }
It always displays the same debug info: [FloatRect] Left(0) Top(0) Width(250) Height(250).

So, have I made a mistake? How is GetGlobalBounds() calculated and why isn't it using the new position of the sprite? Does it not use the Position member at all? Thanks for any help!

Pages: [1]