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

Pages: [1]
1
General / Re: Help with changing a sprite direction
« on: April 23, 2015, 05:14:45 pm »
I'm not trying to be mean, but if you give up this easily on a problem this simple you won't go far as a developer.

You've been given plenty of information to enable you to solve your problem.
You have a tiny working example of a bouncing ball - read it, understand it.
You've been given hints on how to use a debugger to solve your problem; now go learn more about debuggers.
And you've been given various other tips to help you in the right direction; read them again and reflect on them.

Programming is all about solving problems and a big part of that is researching and learning new things + experimenting. Now go learn, experiment & don't give up.

I no you're right, but everything i experiment with fails, i get everything else just can't get my head around this collision detection so hey ho

2
General / Re: Help with changing a sprite direction
« on: April 23, 2015, 05:00:32 pm »
:( give up

3
General / Re: Help with changing a sprite direction
« on: April 23, 2015, 04:39:02 pm »
i think the problem is that my vector is always keeping the first value it is assigned

Don't guess or just think, use your debugger and know for sure what is happening. We are not your debuggers...

When i press my debugger it just runs the program and nothing about the vector is mentioned in the debug, i'm new to this so i must be misunderstanding


Figured it out i put a break point after both the vectors they return

+               balldirection   {x=0.00000000 y=-5.3351998 }    sf::Vector2<float>

+               balldirection   {x=0.00000000 y=-5.3351998 }    sf::Vector2<float>
 

So that means its keeping its first value and not changing?

4
General / Re: Help with changing a sprite direction
« on: April 23, 2015, 04:33:49 pm »
i think the problem is that my vector is always keeping the first value it is assigned

Don't guess or just think, use your debugger and know for sure what is happening. We are not your debuggers...

When i press my debugger it just runs the program and nothing about the vector is mentioned in the debug, i'm new to this so i must be misunderstanding

5
General / Re: Help with changing a sprite direction
« on: April 23, 2015, 04:20:06 pm »
Blo, i think the problem is that my vector is always keeping the first value it is assigned, which is why it always is going up

Is there a way to unassign the vector from it to give it a new one on each collision?

6
General / Re: Help with changing a sprite direction
« on: April 23, 2015, 04:11:08 pm »
Everything i try just doesn't work  :'(

Can anyone help?

I need the ball to rebound off the borders

The ball:
        sf::Vector2u basize = this->_wndw.getSize();

        this->_ball.setTexture(this->_sprite_res.get(71));
        this->_ball_data.startpos     = this->_player.getPosition() + sf::Vector2f(-8,-40);
        this->_ball.setPosition(this->_ball_data.startpos);
        this->_ball.setScale(sf::Vector2f(0.5f,0.5f));
        LJMUGame::setOriginCentre(this->_ball);

Borders:
        this->_top_edge  = sf::FloatRect(50.0f,128.0f,tscreenx,10.0f);
        this->_btm_edge  = sf::FloatRect(0.0f,tscreeny,tscreenx,10.0f);
        this->_left_edge = sf::FloatRect(-10.0f,0.0f,10.0f,tscreeny);
        this->_right_edge = sf::FloatRect(tscreenx,0.0f,10.0f,tscreeny);

Structs:
struct BallData
{
        sf::Vector2f directionup;
        sf::Vector2f directiondown;
        sf::Vector2f directionleft;
        sf::Vector2f directionright;
        sf::Vector2f startpos;  
        float        speed;    
        bool         active;   
        BallData()
        {
                         
                directiondown = sf::Vector2f(0.0f,1.0f);
                directionup = sf::Vector2f(0.0f,-1.0f);
                directionleft = sf::Vector2f(1.0f,0.0f);
                directionright = sf::Vector2f(-1.0f,0.0f);
                startpos = sf::Vector2f(0.0f,0.0f);
                speed    = 200.0f;
                active   = false;
        }
};


Update ball:
        //-------UPDATE THE BALL-----------------------------------------
        if(this->_ball_data.active)
        {
        sf::Vector2f balldirection = this->_ball_data.directionup * this->_ball_data.speed  * ptpf.asSeconds();
        this->_ball.move(balldirection);
       
       
        //-------UPDATE THE BALL COLLISIONS TOP EDGE------------------------------
         if(this->_ball.getGlobalBounds().intersects(this->_top_edge))
        {

        sf::Vector2f balldirection = this->_ball_data.directiondown * this->_ball_data.speed * ptpf.asSeconds();
        this->_game_data.score += 10;
        this->_ball.move(balldirection);
        }

7
General / Re: Help with changing a sprite direction
« on: April 23, 2015, 03:16:47 pm »
Yeah sorry forgot to change the comment from bottom to top

also i no they are cancelling each other out but even when i put it higher it still doesn't rebound

i use this-> because its just the way we've been told to do it

8
General / Re: Help with changing a sprite direction
« on: April 23, 2015, 02:29:46 pm »
Hmm had a look still struggling because of the different layout, i'm a proper noob so might need a bit of a starter bump

9
General / Help with changing a sprite direction
« on: April 23, 2015, 12:38:34 pm »
Does anyone know why when my sprite intersects with a border it doesn't rebound in the correct direction it just stops

THE PROBLEM : The problem i have is that when the ball hits the top border it just stops, if i change the values sometimes it stops or just carries on going past the border. I need it so the ball bounces and rebounds off them so the ball is still in play


Everything i try just doesn't work  :'(

Can anyone help?

I need the ball to rebound off the borders

The ball:
        sf::Vector2u basize = this->_wndw.getSize();

        this->_ball.setTexture(this->_sprite_res.get(71));
        this->_ball_data.startpos     = this->_player.getPosition() + sf::Vector2f(-8,-40);
        this->_ball.setPosition(this->_ball_data.startpos);
        this->_ball.setScale(sf::Vector2f(0.5f,0.5f));
        LJMUGame::setOriginCentre(this->_ball);

Borders:
        this->_top_edge  = sf::FloatRect(50.0f,128.0f,tscreenx,10.0f);
        this->_btm_edge  = sf::FloatRect(0.0f,tscreeny,tscreenx,10.0f);
        this->_left_edge = sf::FloatRect(-10.0f,0.0f,10.0f,tscreeny);
        this->_right_edge = sf::FloatRect(tscreenx,0.0f,10.0f,tscreeny);

Structs:
struct BallData
{
        sf::Vector2f directionup;
        sf::Vector2f directiondown;
        sf::Vector2f directionleft;
        sf::Vector2f directionright;
        sf::Vector2f startpos;  
        float        speed;    
        bool         active;   
        BallData()
        {
                         
                directiondown = sf::Vector2f(0.0f,1.0f);
                directionup = sf::Vector2f(0.0f,-1.0f);
                directionleft = sf::Vector2f(1.0f,0.0f);
                directionright = sf::Vector2f(-1.0f,0.0f);
                startpos = sf::Vector2f(0.0f,0.0f);
                speed    = 200.0f;
                active   = false;
        }
};


Update ball:(what i've done so far, fails)
        //-------UPDATE THE BALL-----------------------------------------
        if(this->_ball_data.active)
        {
        sf::Vector2f balldirection = this->_ball_data.directionup * this->_ball_data.speed  * ptpf.asSeconds();
        this->_ball.move(balldirection);
       
       
        //-------UPDATE THE BALL COLLISIONS TOP EDGE------------------------------
         if(this->_ball.getGlobalBounds().intersects(this->_top_edge))
        {

        sf::Vector2f balldirection = this->_ball_data.directiondown * this->_ball_data.speed * ptpf.asSeconds();
        this->_game_data.score += 10;
        this->_ball.move(balldirection);
        }

Pages: [1]
anything