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

Pages: [1] 2 3
1
May I add that knowing the distance and that it's perpendicular gives your two points, one for each side.

for a vector defined by (a,b) an orthogonal vector would be (-b, a) (so I do agree with Grimshaw, just to say it a bit differently)


2
General / Re: Some Bounding Box Help
« on: July 31, 2013, 10:59:17 am »
I think you should use directly getPosition() inside your getCollision() methods because you only want to use your current position at all times right now.

I for myself like to proceed differently. For each tick, I modify the speed of my object (so pressing a button sets or adds speed to your player) and then I call a collision checker which will modify my speed according to collisions and speed. If my next position is inside player 2 for example, I modify the speed so that it does not collide, which enables me to process lots of different things like bouncing for example.

However I believe you can find some really nice tutorials on the internet concerning collision management and physics.

3
General / Re: Some Bounding Box Help
« on: July 30, 2013, 12:30:43 pm »
Hi there,

First I think you already know it, but both of your boolean collision functions verify collisions in all directions.

That being said, I think it has to do with the way it is handled. You do not actualize the variables you use for collision (top, bottom, left, right) after your first move, so position checking is on the previous position, meaning you can intersect your players. Once you are in an intersection, you cannot move at all since you cancel every move.

Hope this helps.

4
General / Re: Collsions not working (and other strange behavior)
« on: July 24, 2013, 05:20:43 pm »
Can't help you with that sorry, let's hope someone will step in to give you the answers you seek :p

5
General / Re: Collsions not working (and other strange behavior)
« on: July 24, 2013, 10:40:28 am »
I'm not saying you shouldn't generally do that, I'm just saying you should remove that part for now so that we can see if this is the cause of the issue. If it is, it is probably because you are not using it correctly. I'm afraid I am not expert enough to help you using this however.

6
General / Re: Collsions not working (and other strange behavior)
« on: July 23, 2013, 10:57:14 am »
I'm pretty sure globalBounds is not your responsibility to update. In the tutorial http://sfml-dev.org/tutorials/2.0/graphics-transform.php It is said the globalBounds takes into consideration the position (as well as everything else) so it should change with your ball positions. It is very unlikely that this method doesn't work properly so I guess you should try to make a minimal code that uses getGlobalBounds() to be sure of its behaviour.

EDIT : why would you reimplement draw in ball ? You never use transformations. I'd say you should try and remove your reimplementation of the method draw because doing without it should work without any issue since you never use renderStates, you just use move(). I'm not sure about why you would multiply the renderstates with your ball transformation when you never actually use any of them.

7
General / Re: Collsions not working (and other strange behavior)
« on: July 22, 2013, 12:04:19 pm »
One error I see is checking x positions in DoYCollision(), also no issue when y goes up ?. Another thing it the checking of the clock. You check if 3ms have passed in both X and Y movement, but why using the same clock and restarting it inside it ? you should check time passed in your main loop and if it has passed, restart it and do all your movements, because you might never move Y since X just restarted your clock

8
General discussions / Re: SFML Game Jam
« on: July 17, 2013, 03:09:09 pm »
I'd be willing to give it a try too. Nice idea.

9
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 17, 2013, 01:12:48 pm »
Might have had a wild Ctrl+V going crazy ^^

Good continuation

10
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 17, 2013, 12:53:16 pm »
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <string>
#include <iostream>

int main()
{
    enum Direction { Down, Left, Right, Up };

    sf::Vector2i screenDimensions(800,600);

    sf::RenderWindow window(sf::VideoMode(screenDimensions.x, screenDimensions.y), "SFML Game");

    int animationCounter = 0, animationFrameDuration = 300;

    sf::Texture pTexture;
    sf::Sprite playerImage;
    sf::Clock clock;
    sf::Font font;
    sf::Music music;

    sf::Vector2i source(1, Down);

    {
    if(!music.openFromFile("KingOfTheDesert.ogg"))
        std::cout << "Error: Could not locate music file." << std::endl;
    }

    {
    if(!font.loadFromFile("Gabriola.ttf"))
        std::cout << "Error: Could not locate the font file." << std::endl;
    }

    {
    if(!pTexture.loadFromFile("Player.png"))
        std::cout << "Error: Could not load player image." << std::endl;
    else
        playerImage.setTexture(pTexture);
    }

    clock.restart();
    while (window.isOpen())
    {
        sf::Event Event;
        while (window.pollEvent(Event))
        {
            switch(Event.type)
            {
            case sf::Event::Closed:
                window.close();
            case sf::Event::KeyPressed:
                if(Event.key.code == sf::Keyboard::Up)
                    source.y = Direction::Up;
                else if(Event.key.code == sf::Keyboard::Down)
                    source.y = Direction::Down;
                else if(Event.key.code == sf::Keyboard::Left)
                    source.y = Direction::Left;
                else if(Event.key.code == sf::Keyboard::Right)
                    source.y = Direction::Right;
                if(Event.key.code == sf::Keyboard::P)
                    music.play();
                if(Event.key.code == sf::Keyboard::Escape)
                    window.close();
            }
        if(source.x * 32 >= pTexture.getSize().x)
            source.x = 0;
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
            source.y = Up;
            playerImage.move(0, -1);
        }
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
            source.y = Down;
            playerImage.move(0, 1);
        }animationCounter
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
            source.y = Right;
            playerImage.move(1, 0);
        }
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            source.y = Left;
            playerImage.move(-1, 0);
        }
        if(source.x * 32 >= pTexture.getSize().x)
            source.x = 0;

        animationCounter += clock.restart().asMilliseconds();

        if(animationCounter >= animationFrameDuration)
        {
            animationCounter -= animationFrameDuration;
            source.x++;

            if(source.x * 32 >= pTexture.getSize().x)
                source.x = 0;
        }

        playerImage.setTextureRect(sf::IntRect(source.x * 32, source.y * 32, 32, 32));
        window.clear();
        window.draw(playerImage);
        window.display();
    }
    return 0;
}
 


Well I would do something like that, sometimes I replace the if(animationCounter >= animationFrameDuration) by a while so that when we have a very very long frame it doesn't influence the overall animation in a long time perspective (although if you have frames that long this might not be your first concern ^^).

Can't compile it myself so don't hesitate if something is not right

11
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 17, 2013, 12:44:33 pm »
I am at work so give me time to download CodeBlocks and make you something pretty ^^

12
General / Re: Basic collision detection
« on: July 17, 2013, 12:40:56 pm »
I see you are changing values of x and y inside your loop but never actually use them inside. Maybe that's related.

What you can do is have x and y actualized in each loop (with boundaries issues of course) and then call your rectangle.setPosition(x,y) at the end of each loop. Because you are currently continuing to play with x and y but only call move with the amount of movement, so x and y are never read.

Hope this helps.

13
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 17, 2013, 12:21:32 pm »
Yep, that's exactly what I meant. Sorry for the quick explanation

14
Graphics / Re: Sprite Animation Speed Ridiculously Fast
« on: July 17, 2013, 11:25:47 am »
Hey,

Been looking at your code and I don't understand your framerate limit. You just define a framerate which you never use to actually limit the framerate but only in your calculation of frames passed (for your animation). SFML offers a framerate limit so you might want to use it or actually limit the framerate by sleeping a bit?

I also agree with massive_potato, in your code you increment twice source.x, once in every frame and once in a certain number of frames.

I would recommend using time counting before changing every frame (a counter which you increment by the time passed at every frame in milliseconds and when it is superior to 300 ms for example, change your animation) or incrementing a counter by one at every frame (so every loop) and then change it every X frames, but that would require to limit the fps (as opposed to the other method).

Hope I helped you and I didn't say anything wrong ^^

15
Graphics / Re: questions about Dots game project
« on: May 16, 2013, 03:08:26 pm »
when do you set false r1_key, r2_key, r3_key and r4_key ?

Pages: [1] 2 3
anything