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

Pages: [1]
1
General / Re: Moving a sprite without holding a key
« on: June 17, 2012, 02:11:49 pm »
It's working now, thanks. :)  Also, I'll do some research about delta time.

2
General / Re: Moving a sprite without holding a key
« on: June 16, 2012, 08:39:17 pm »
I will post the part of my main.

while(window.isOpen)

//Events

        if(keyboard.isKeyPressed(Keyboard::D))
        {
            posPlayer = player.movePlayerShip(true, false, false, false, posPlayer);
        }

        if(keyboard.isKeyPressed(Keyboard::A))
        {
            posPlayer = player.movePlayerShip(false, true, false, false, posPlayer);
        }

        if(keyboard.isKeyPressed(Keyboard::W))
        {
            posPlayer = player.movePlayerShip(false, false, true, false, posPlayer);
        }

        if(keyboard.isKeyPressed(Keyboard::S))
        {
            posPlayer = player.movePlayerShip(false, false, false, true, posPlayer);
        }

        if(keyboard.isKeyPressed(Keyboard::Space))
        {
            posBall = player.shoot(posBall, posPlayer, pressedSpace);
            pressedSpace = true;
        }
        else if(canFollow)
        {
            posBall.y = posPlayer.y+16;
            posBall.x = posPlayer.x+32;
        }


//Render and position updates

 

Only look the code for the space key. I call the function shoot, which is this function:

Vector2f Jeu::shoot(Vector2f posBall, Vector2f posPlayer, bool pressed)
{
    hideBall = false;
    canFollow = false;

    posBall.y -= 2;

    if(posBall.y < 0)
    {
        isMoving = true;
        posBall.y = posPlayer.y+16;
        posBall.x = posPlayer.x+32;
        pressed = false;
    }

    return posBall;
}

When I press space and holding it, the ball is moving toward the y : 0 position. If I don't hold it, it returns to the player position. Also, when I try to do a loop, the game crashes.

So, one question: Can I have some help, yes or no?
Thanks.

3
General / Re: Moving a sprite without holding a key
« on: June 16, 2012, 08:02:56 pm »
Yeah, but it is less active, and I think my English is ok for posting here.  :P

So, I will try to be more clear:

What I expect: I press space, and the ball is propulsed to y: 0, without holding space, like in a normal game.

What is not working: I need to hold space for the ball to move.

My question is : How to move a sprite without holding a key? I tried loops, and currently I'm trying to do it with booleans. I think that I really need loops, but when I use them, the game is crashing. And I repeat, this function is called in the main loop, when I press the space key.

4
General / Re: Moving a sprite without holding a key
« on: June 16, 2012, 07:43:07 pm »
Thanks for your answer.

I guess the function is okay but you're problem is that you call it just once

I call it in the main loop, I don't call it once.

You see this isn't GameMaker or some other simple enviroment, you're code with pure C++ now.

Yes... I know...  ??? Why are you saying that?

Although we're willing to help I don't think someone will take the time to basically program all the logic you need for whatever you do

I don't asked someone to program all the logic for me, I just have a question and I don't know how to resolve my problem.


5
General / Moving a sprite without holding a key
« on: June 16, 2012, 03:24:06 pm »
Hello!

I need help for a little problem in my game. I want to shoot a ball when I press space, but I need to hold it to make the ball move. This is the function that I wrote for it, which is not working :
 
Vector2f Jeu::shoot(Vector2f posBall, Vector2f posPlayer)
{
    hideBall = false;
    canFollow = false;

    posBall.y -= 2;

    if(posBall.y < 0)
    {
        isMoving = true;
        posBall.y = posPlayer.y+16;
        posBall.x = posPlayer.x+32;
    }

    return posBall;
}

I tried a loop but this function is situated in the main loop, and it crashes. I use SFML 2.0 RC. Also, sorry for my English, I know it is not perfect.  ;D

Thanks!

Pages: [1]
anything