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 - carton83

Pages: [1] 2 3
1
And this is why I ask questions.  So I need an initialization list, huh?  Thanks.

2
I know from debugging that the in function sprite's position data does correctly change but this is not reflected main version of said sprite.  This is also despite the fact that both sprites do indeed share the same address.

I have to be missing something.

This tiny bit of code is fairly simple.  If you hit the A key the sprite is suppose to move down and right by 10px. But it doesn't.  No idea why.

#include <SFML/Graphics.hpp>

class Test
{
    public:
    Test(sf::Sprite &tempTestSprite)
    {
        testSprite = tempTestSprite;
    }

    sf::Sprite testSprite;

    void Blah();
};

void Test::Blah()
{
    testSprite.setPosition(testSprite.getPosition().x+10, testSprite.getPosition().y+10);
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

    sf::Texture texture;
    if(!texture.loadFromFile("cb.bmp"))
    {
        return -1;
    }

    sf::Sprite logo(texture);

    Test tester(logo);

        while(window.isOpen())
    {

        // Process events
        sf::Event event;
        while(window.pollEvent(event))
        {
            switch(event.type)
            {
                case sf::Event::KeyPressed:
                {
                    // Close window : exit
                    if(event.key.code == sf::Keyboard::Escape)
                    {
                        window.close();
                    }
                    if(event.key.code == sf::Keyboard::A)
                    {
                        tester.Blah();
                    }
                }
            }
        }



        window.clear();
        window.draw(logo);
        window.display();

    }

    return 0;
}

3
I think I just figured it out.  I take the unit vector, multiply it by the displacement, and then use that as what you move the sprite by. 

4
Ah, thanks!

I'm gonna give an example of what I'm talking about.  I have a sprite at 0,0 and I want to move it to say 157,56.  How do I do the math that moves him along that vector in an efficient manner?

5
Damn, the character limit for titles is tiny.

I have a function that takes two vectors uses them to create their magnitude.

If I try to do
get2DMagnitude((0.f,0.f),(1.f,1.f));
gcc complains that "error: could not convert '(0, 0.0f)' from 'float' to 'sf::Vector2f {aka sf::Vector2<float>}'"

I'm doing something wrong.



Also, does anyone know where I can learn about how to animate using vector math?  I think I have figured it out, but it's always good to have something that just says "hey, this is how you do x".

I just can't seem to find any.


6
Graphics / Re: I think I found a bug with sf::Mouse::getPosition
« on: May 02, 2014, 03:49:16 am »
Thanks everyone!  I'm not much of a technical person so some of the concepts are hard for me to grasp properly.

7
Graphics / Re: I think I found a bug with sf::Mouse::getPosition
« on: May 02, 2014, 03:21:58 am »
That seems to fix it, but why would it still appear here even though it is checking.  Or am I not seeing something?

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

    sf::Texture texture;
    if(!texture.loadFromFile("cb.bmp"))
    {
        return -1;
    }

    sf::Sprite image(texture);
    sf::Vector2i mouseCoord(0,0);

        while(window.isOpen())
    {

        sf::Event event;
        switch (event.type)
        {
            case sf::Event::KeyPressed:
            {
                if(event.key.code == sf::Keyboard::Escape)
                {
                    window.close();
                }
                break;
            }
        }

        mouseCoord = sf::Mouse::getPosition(window);
        std::cout << mouseCoord.x << " " << mouseCoord.y <<"\n";

        window.clear();
        window.draw(image);
        window.display();

    }

    return 0;
}

And even then, I don't get why getPosition would have an affect on event.

8
Graphics / Re: I think I found a bug with sf::Mouse::getPosition
« on: May 02, 2014, 02:57:52 am »
In the added switch statement? Yes.

The statement is

switch (event.type)
{
    case sf::Event::KeyPressed:
    {
        if(event.key.code == sf::Keyboard::Escape)
        {
            window.close();
        }
        break;
    }
}

EDIT:

So when is the switch suppose to be used and when is pollEvent used?  Or are you saying that my while loop should have had a if loop that checked sf::Event::KeyPressed  first?

9
Graphics / Re: I think I found a bug with sf::Mouse::getPosition
« on: May 02, 2014, 02:49:05 am »
Still happens.

And, if I'm not mistaken, functionally there isn't much different from what I have and the switch statement used in the first example area other than pollEvent() is used to process every pending event.

10
Graphics / I think I found a bug with sf::Mouse::getPosition
« on: May 02, 2014, 02:25:30 am »
Compiler: MinGW
IDE: CodeBlocks 13.12
Platform: Win7, 64bit
Repeatability: Always
Any special compiler settings: None
Version of SFML being used: Using 2.1, grabbed from the official downloads page.

This is the bug:  When calling
mouseCoord = sf::Mouse::getPosition(window)
and the mouse cursor enters a region around (37,n+) (n+ being any positive number) for what ever reason
event.key.code == sf::Keyboard::Escape
becomes true.  I am not sure why and I simply don't have enough skill to find out why.

Putting
mouseCoord = sf::Mouse::getPosition(window)
after the even code loop still causes
event.key.code == sf::Keyboard::Escape
to register as true. 
I've actually noticed that the results are different depending on the key used.  A couple of keys I've tested are listed at the bottom.
Using the global version of getPosition() doesn't seem to reproduce the bug.


Image used. The red part is generally where the "problem area" is.

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

    sf::Texture texture;
    if(!texture.loadFromFile("test.png"))
    {
        return -1;
    }

    sf::Sprite image(texture);
    sf::Vector2i mouseCoord(0,0);


        while(window.isOpen())
    {

        mouseCoord = sf::Mouse::getPosition(window);
        std::cout << mouseCoord.x << " " << mouseCoord.y <<"\n";

        sf::Event event;
        while(window.pollEvent(event))
        {

            if(event.key.code == sf::Keyboard::Escape)
            {
                window.close();
            }

        }

        window.clear();
        window.draw(image);
        window.display();

    }

    return 0;
}

These are the keys I tested, but I'm sure it affects far more, maybe even all of them
A: Always marked as true
B, C, D, E, F, G, H, I, J, K, L, M: The problem area seems to be around 0,n
Pause: The problem area seems to be around n,0
End, Home: 62,n+


11
General / Re: Storing a vector2i into a vector2f (or vica versa)?
« on: May 01, 2014, 10:48:38 pm »
I'll start a new thread then.

12
General / Re: Storing a vector2i into a vector2f (or vica versa)?
« on: May 01, 2014, 08:43:20 pm »
I thought of doing this as its own thread but since it's directly related to this decided against it.

Doing

mouseCord = static_cast<sf::Vector2f>(sf::Mouse::getPosition(window));

Will quickly cause my program to crash and return 0.  By commenting out that single line everything is fine. I tried debugging but I was never able to get any useful information. Edit: I should state that it will run for a short period of time.  It seems to vary.

Here's what I am working on.  As I have said before this is just a simple program to test my memory on vector math.  I realize there are a couple of things I'm not doing right but I'm not worried about that right now.  I just want to get this working then worry about everything else.

13
General / Re: Storing a vector2i into a vector2f (or vica versa)?
« on: April 30, 2014, 05:48:15 am »
Because implicit conversions decrease type safety.

Even though it's not safe there should still be the option.  Just because it's bad doesn't mean it shouldn't be allowed.  One of the awesome things about C++ is that it lets the programmer decide what they want to do, regardless if it's a bad idea.

The coordinates are in pixels, which are integral.

Well, if we had the option to do implicit conversions with vector2 objects then it wouldn't be an issue.

But you have still not mentioned why you don't want to use the correct way (mapPixelToCoords).

I was confusing world coordinates with global coordinates.

14
General / Re: Storing a vector2i into a vector2f (or vica versa)?
« on: April 30, 2014, 01:08:01 am »
Mouse position coordinate are always integer, a mouse is on a pixel, but can't be between 2 pixels.

If you want to "convert" the mouse position to a world position, you might want to use mapPixelToCoords anyway and it returns an sf::Vector2f.

I'm actually using the version of getPosition() that returns position of the mouse in window coordinates.

15
General / Re: Storing a vector2i into a vector2f (or vica versa)?
« on: April 30, 2014, 12:54:08 am »
Well, I'm wanting to use the coordinates from getPosition() to "tell" a sprite where to move.  I'm writing a really simple program to test my vector math knowledge as I'm not entirely sure if I recall everything correctly.  I am pretty certain it's the only instance where I would convert a vector2i to vector2f.  Everything else deals with floats.

Two questions, why CAN'T I just do vector2i = vector2f or vice versa?  And why does getPosition() return a vector2i instead of a vector2f?

What would that change? Conversion constructors are there to construct from another, existing object...

I'm saying both objects already exist.  The constructor would only be useful if I was creating the vector2f right when I'm trying to store the coordinates from getPosition(), which I'm not.

Pages: [1] 2 3