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

Pages: [1]
1
Graphics / C++ SFML Collision Bug
« on: May 11, 2020, 07:29:49 pm »
I wrote some collision code that responds to collisions. So, I put it in a function. Then, the response to the collision stopped working but the collision detection still worked.

P.S OG_INFO means printf.
#include "Collision.h"

void OpenGEC::Collision::AddCollider(Sprite& sprite, Sprite& _sprite)
{

    if (sprite.getGlobalBounds().intersects(_sprite.getGlobalBounds())) {
        Vector2f pos_ = _sprite.getPosition();
        Vector2f pos = sprite.getPosition();
        if (pos.y > pos_.y) {
            pos.y++;
            sprite.setPosition(pos);
            _sprite.setPosition(pos_);
            OG_INFO("{0},{1}", pos.x, pos.y);
        }
        else if (pos.y < pos_.y) {
            pos.y--;
            sprite.setPosition(pos);
            _sprite.setPosition(pos_);
            OG_INFO("{0},{1}", pos.x, pos.y);
        }
        else if (pos.x > pos_.x) {
            pos.x++;
            sprite.setPosition(pos);
            _sprite.setPosition(pos_);
            OG_INFO("{0},{1}", pos.x, pos.y);
        }
        else if (pos.x < pos_.x) {
            pos.x --;
            sprite.setPosition(pos);
            _sprite.setPosition(pos_);
            OG_INFO("{0},{1}", pos.x, pos.y);
        }
    }
}

Pages: [1]