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

Pages: [1]
1
General / Stun character
« on: April 01, 2018, 01:59:48 am »
What would be the best way for me to have my character stunned for 3 seconds. I used a boolean Stunned. So if the character is stunned, keyboard inputs won't work.

if(Stunned == false)
   Player.playerMovement();

However, I can't seem to find a way to break out of the stunned once I make Stunned = true, nothing seems to work. I read up on the clock and time documentation but I still don't understand it.

I tried something like this.

Clock clock;
Time time;

clock.restart();
time = clock.getElaspedTime();
if (time.asSeconds() >= 3)
    Stunned = false;

2
I don't know if this is a C++ question or an SFML question but what exactly is happening here in this constructor. I've never seen a constructor written like this before and I can't find any other examples online.

Rather than using opening braces, it starts with a semi-colon, and why comma's after texture, player, font, etc? If Texture is a member variable why is there a ()?

Game::Game()
   : Window(sf::VideoMode(Resolution.x, Resolution.y), "SFML Application", sf::Style::Close)
   , Texture()
   , Player()
   , Font()
   , isMovingUp(false)
   , isMovingDown(false)
   , isMovingRight(false)
   , isMovingLeft(false) {
   if (!Texture.loadFromFile("Graphics/character.png")) {
      // loading error
   }
   Player.setTexture(Texture);
   Player.setPosition(100.f, 100.f);
   }

Why can't I get the constructor to work like this?

Game::Game() {
   Window(VideoMode(Resolution.x, Resolution.y), "SFML Application", sf::Style::Close);
   isMovingUp = false;
   isMovingDown = false;
   isMovingRight = false;
   isMovingLeft = false;

   if (!Texture.loadFromFile("Graphics/character.png")) {
         // loading error
      }
      Player.setTexture(Texture);
      Player.setPosition(100.f, 100.f);
   }
}

Pages: [1]