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.


Topics - decoder

Pages: [1]
1
Graphics / Move the view if the entity's out view.
« on: June 11, 2018, 09:48:45 am »
How can I make the view follow the player entity when it's nearly out of the drone's (the view) view.
I have here my code for the drone's movement.

void World::update(const sf::Time& deltaTime)
{
        mSceneGraph.update(deltaTime);
        mDrone.setCenter(mPlayer->getPosition());
}
 

What I want to achieve is to make the drone follow the player, but not really following the player's new position as it moves real-time. Instead, the drone will SMOOTHLY MOVE if the player is NEARLY OUT OF VIEW (not hitting the view's boundary).

2
Graphics / Rectangle collision detection is not accurate
« on: June 04, 2018, 04:10:30 pm »
The problem is the rect is not actually entirely hitting the wall. As you can see in the image, there's a little gap between them, and the gap's size is random.

int main()
{
        sf::RenderWindow window(sf::VideoMode(1920, 1080), "SFML Test");

        float rectVel = 200.f;
        sf::RectangleShape rect({ 50, 50 });
        sf::Vector2f rectOffset;
        rect.setFillColor(sf::Color::Red);
        rect.setPosition(static_cast<sf::Vector2f>(window.getSize()) / 2.f);

        sf::RectangleShape wall({ 20, 70 });
        wall.setFillColor(sf::Color::Blue);
        wall.setPosition(300.f, 200.f);

        sf::Clock timer;

        while (window.isOpen())
        {
                sf::Time deltaTime = timer.restart();

                sf::Event ev;
                while (window.pollEvent(ev))
                {
                        switch (ev.type)
                        {
                                case sf::Event::Closed:
                                        window.close();
                                        break;
                        }
                }

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
                {
                        rect.move(0.f, -rectVel * deltaTime.asSeconds());
                        if (wall.getGlobalBounds().intersects(rect.getGlobalBounds()))
                                rect.move(0.f, rectVel * deltaTime.asSeconds());
                }
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
                {
                        rect.move(0.f, rectVel * deltaTime.asSeconds());
                        if (wall.getGlobalBounds().intersects(rect.getGlobalBounds()))
                                rect.move(0.f, -rectVel * deltaTime.asSeconds());
                }

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
                {
                        rect.move(-rectVel * deltaTime.asSeconds(), 0.f);
                        if (wall.getGlobalBounds().intersects(rect.getGlobalBounds()))
                                rect.move(rectVel * deltaTime.asSeconds(), 0.f);
                }
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
                {
                        rect.move(rectVel * deltaTime.asSeconds(), 0.f);
                        if (wall.getGlobalBounds().intersects(rect.getGlobalBounds()))
                                rect.move(-rectVel * deltaTime.asSeconds(), 0.f);
                }

                window.clear(sf::Color::White);
                window.draw(wall);
                window.draw(rect);

                window.display();
        }

        return 0;
}

3
Window / Use setFrameLimit and setVerticalSyncEnabled together
« on: May 22, 2018, 06:01:06 am »
Can I use setFrameLimit and setVerticalSyncEnabled together after I'd created a window because I will be adding a vertical sync setting into my game, and I'm not pretty sure if setVerticalSyncEnabled will override the FPS that I've passed into the setFrameLimit.

Pages: [1]