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

Pages: [1]
General / Help with Collision
« on: October 30, 2013, 02:28:59 am »
Hi, I am having problems with my collisions. I know how 2 check if a collision has happened but having trouble with the sprite repositioning. I some minimal code  to show what I have. Right now the code is working for side collisions but for the top it is not. I know why the commented code isn't working, one the first 2 conditions will be true. Is there something simple that I am not seeing or do I need a lot more code to get this done. I have searched for answers but what I found is way different than what I have.

#include <SFML/Graphics.hpp>

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

        sf::RectangleShape square(sf::Vector2f(40.f,40.f));

        sf::RectangleShape square2(sf::Vector2f(40.f,100.f));
        sf::Vector2f speed(150.f,150.f);

                float dt =  frameTime.restart().asSeconds();
                sf::Event event;

                        if(event.type == sf::Event::Closed)

                        square.move(speed.x * dt,0.f);
                        square.move(-speed.x * dt,0.f);
                        square.move(0.f,speed.y * dt);
                        square.move(0.f,-speed.y * dt);

                if(square.getPosition().x + square.getSize().x > square2.getPosition().x &&
                        square.getPosition().x < square2.getPosition().x + square2.getSize().x &&
                        square.getPosition().y + square.getSize().y > square2.getPosition().y &&
                        square.getPosition().y < square2.getPosition().y + square2.getSize().y)
                        //left side of square 2 collision
                        if(square.getPosition().x < square2.getPosition().x )
                                square.setPosition(square2.getPosition().x - square2.getSize().x,square.getPosition().y);
                        //right side of square2 collision
                        if(square.getPosition().x > square2.getPosition().x)
                                square.setPosition(square2.getPosition().x + square2.getSize().x,square.getPosition().y);
                        //top of square2 collision
                        //if(square.getPosition().y + square.getSize().y > square2.getPosition().y)
                                //square.setPosition(square.getPosition().x,square2.getPosition().y - square.getSize().y);


        return 0;

General discussions / SFML + Box2D
« on: April 06, 2013, 02:49:04 am »
I was just wondering how may people in the forum use Box2D for physics? I have been learning C++ , Allegro for about 1 1/2 years and sfml 2 for about 6 months. Just wanted some kind of idea on weather I should learn to code my own or use an existing engine like Box2D? Any pointers will be appreciated.

General discussions / What physics engine to use?
« on: April 05, 2013, 03:54:27 pm »
Hi,I was wondering what physics engine do you recommend using with SFML 2? I have been learning SFML 2 and Allegro 5 for a while now and would like to start using a physics engine. I do not have any experience with any engine but would like to start.

Graphics / Getting Sprite to Jump
« on: January 15, 2012, 07:28:17 pm »
I am having a problem with getting my sprite to jump. I can move the sprite fine but I cant get it to jump. If I use Sprite.move instead of SetPosition it will move across the screen by a greater distance every time I press space
but not vertical.I know i probably dont have the falling part right either but I need to get jumping right first.

Code: [Select]

float velocity = 0;  
float gravity = 0;
float uprate = 0;
bool jumping = false;
bool falling = false;

if(Event.Key.Code == sf::Keyboard::Right)
Sprite2.Move(sprite2Speed * Window.GetFrameTime() /1000.f, 0.f);
if(Event.Key.Code == sf::Keyboard::Left)
Sprite2.Move(-sprite2Speed * Window.GetFrameTime() / 1000.f, 0.f);
if(Event.Key.Code == sf::Keyboard::Up)
Sprite2.Move(0.f, -sprite2Speed * Window.GetFrameTime() / 1000.f);
if(Event.Key.Code == sf::Keyboard::Down)
Sprite2.Move(0.f, sprite2Speed * Window.GetFrameTime() / 1000.f);
if(Event.Key.Code == sf::Keyboard::Space && jumping == false && falling == false)
velocity = 50.0f;
gravity = 0;
jumping = true;
velocity = velocity - uprate;
Sprite2.SetPosition(Sprite2.GetPosition().x,Sprite2.GetPosition().y - (velocity));
if(velocity == -50.0f)
jumping = false;
falling = true;
gravity = 2;
velocity = velocity + gravity;
if(Sprite2.GetPosition().y + Sprite2.GetSize().y > Ground.GetPosition().y)
falling = false;
velocity =0;
gravity = 0;

General discussions / sf::input for sfml2
« on: January 12, 2012, 02:32:08 am »
I have been following the Game From Scratch tutorial and it is coded in 1.6.
I think I have everything right except the code for sf::Input I looked at the documentation and cant seem to figure it out.Here is the code, if anyone can give some info i would greatly appreciate it.

Code: [Select]

const sf::Input& Game::GetInput()
return _mainWindow.GetInput();

I already know that it should be keyPressed and Keyboard

Code: [Select]

void PlayerPaddle::Update(float elapsedTime)

this->_velocity-= 5.0f;
this->_velocity+= 5.0f;

this->_velocity= 0.0f;

if(_velocity > _maxVelocity)
this->_velocity = _maxVelocity;

if(_velocity < -_maxVelocity)
this->_velocity = -_maxVelocity;

sf::Vector2f pos = this->GetPosition();

if(pos.x  < GetSprite().GetSize().x/2
|| pos.x > (Game::SCREEN_WIDTH - GetSprite().GetSize().x/2))
_velocity = -_velocity; // Bounce by current velocity in opposite direction

GetSprite().Move(_velocity * elapsedTime, 0);

General / Sprite movement
« on: November 13, 2011, 09:53:39 pm »
I am having a problem with sprite movement.If I run this code the only key that works is left.Nothing happens with the other keys.Another problems is the sprite moves right off the screen when I press left.Is there something simple I can do or do I need to write the code a different way?

Code: [Select]
float ElapsedTime = Window.GetFrameTime() ;
        // Move the sprite
        case sf::Event::KeyPressed:
            case sf::Keyboard::Left:
                Sprite.Move(-100 * ElapsedTime, 0);
            case sf::Keyboard::Right:
                Sprite.Move( 100 * ElapsedTime, 0);
            case sf::Keyboard::Up:
                Sprite.Move(0, -100 * ElapsedTime);
            case sf::Keyboard::Down:
                Sprite.Move(0,  100 * ElapsedTime);


General / Key events on sfml2
« on: November 13, 2011, 04:24:35 pm »
in this switch statement it does not matter whitch key i press it says f was pressed what am i doing wrong?

 case sf::Event::KeyPressed:
                switch (Event.KeyPressed)
                case sf::Keyboard::Back:
                    std::cout << "Backspace was pressed." << std:: endl;
                case sf::Keyboard::F:
                    std::cout << "f was pressed." << std:: endl;

General / sfml vs sfml 2.0 key events
« on: November 12, 2011, 09:54:01 pm »
I m following the tutorials on 1.6 .The one on opengl. When I try to compile it give me errors on the key events.

this is the line giving the errors:

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))

I have read that you use keyboard instead of key but what would the line of code be?

Is there a code sheet showing the differences and how to write them?

General / opengl codeblocks
« on: November 12, 2011, 08:13:05 pm »
I am getting a error when trying to compile code with opengl

error: 'glClearDepth' was not declared in this scope|

I am using sfml2, do i need to link the opengl libraries and how?[/img][/code]

General / code completion code blocks
« on: November 12, 2011, 02:17:39 am »
Hey everyone I am new to SFML, I set up code blocks and can run a program fine but not all of my code completion works. Like when I type
sf::VideoMode it does not give me other options this would greatly help my learning. Any help with this will be appriciated.

Pages: [1]