Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Projectile  (Read 1421 times)

0 Members and 1 Guest are viewing this topic.

alexb9054

  • Newbie
  • *
  • Posts: 4
    • View Profile
Projectile
« on: October 10, 2017, 01:17:10 am »
I have another question. So I'm creating a projectile in the form of an orb. I currently am able to have it move to a certain point and despawn, but I am unable to get it to reset the orb's location so it can do it again.
        //Code for Player Ability
        if (orbMovement == true)
        {
                float move = velocity.x += 4;
                pOrb.setPosition(pImage.getPosition().x + 40, pImage.getPosition().y + 20);
                pOrb.move(move, 0);
                window.draw(pOrb);
                if (pOrb.getPosition().x >= pImage.getPosition().x + 300)
                        orbMovement = false;
        }
        if (orbMovement == false)
        {
                pOrb.setPosition(pImage.getPosition().x, pImage.getPosition().y);
        }

and in the main function I'm using a switch statement that when 'F' is pressed it sets orbMovement to True as shown here,

                                if (evnt.key.code == sf::Keyboard::F)
                                {
                                        CreateAbilitySound();
                                        orbMovement = true;
                                }

I want it to once it moves to the maximum distance, the orb resets position and can do it again.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Projectile
« Reply #1 on: October 10, 2017, 11:56:30 am »
Are you making sure that "evnt" is definitely a Keypressed type before checking its key code?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

alexb9054

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Projectile
« Reply #2 on: October 10, 2017, 06:12:08 pm »
It's inside of the second while loop,

        while (window.isOpen())
        {
                clock2.restart();
                sf::Event evnt;
                while (window.pollEvent(evnt))
                {
                        switch (evnt.type)
                        {
                        case sf::Event::Closed:
                                window.close();
                                break;
                        case sf::Event::KeyPressed:
                                if (evnt.key.code == sf::Keyboard::Space)
                                {
                                        isJump = true;
                                        CreateSoundJump();
                                }
                                if (evnt.key.code == sf::Keyboard::Return)
                                {
                                        dIsVisible = false;
                                }
                                if (evnt.key.code == sf::Keyboard::F)
                                {
                                        CreateAbilitySound();
                                        orbMovement = true;
                                        break;
                                }
                        }
                }

I tried moving the break from outside of the third switch to inside of the curly braces, but it still does the same thing.

 

anything