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

Pages: [1]
1
General / Re: Real Time Keyboard Input
« on: March 14, 2016, 09:05:17 pm »
I tried that it did not  work the way I want it to. It simply ignores some of the input and accepts some. The game im writing uses a lot of window clear and display and for that reason I think it skips input from the keyboard. It works perfectly fine with the real time keyboard input except i do not want it to take continuous input.

2
General / Re: I want to make sprites appear with a random time delay
« on: March 14, 2016, 09:00:26 pm »
Thank you Jesper what do you recommend then?

3
General / Real Time Keyboard Input
« on: March 14, 2016, 09:00:01 pm »
I am using real time keyboard input to get immediate response within my game.

if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && x == 5) {
         std::cout << "space" << std::endl;
      }

The thing is I want it to take that input only one time. I tried using event from some reason it skips the keyboard input many times if I am using events but, this works perfectly except that it takes way too much input since its real time. Is there a way to make it take one spacebar hit and stop for a while lets say 2 seconds.

4
General / Re: I want to make sprites appear with a random time delay
« on: March 14, 2016, 07:02:50 pm »
Well the way I did it was like so

sf::Time t1 = sf::milliseconds(500);
      sf::Time t2 = sf::milliseconds(1000);
      time = clock.getElapsedTime();
      sf::Event Event;
      if ((time.asMilliseconds() >= t1.asMilliseconds()) && (time.asMilliseconds() <= t2.asMilliseconds())) {
      clock.restart();
}

Basically that way it will meet this condition only once then the clock will restart achieving the delay effect I wanted. I understand if statements but, the way you went about it is just different.

5
General / Re: I want to make sprites appear with a random time delay
« on: March 14, 2016, 11:30:21 am »
Actually I was able to solve my problem in a completely different way on my own which is fine. But, because I want to learn more and have a thirst for knowledge I am asking since I tried to understand the logic behind the code you put here and didn't really get the Boolean part? That's why I am asking. It's fine to ask questions when you don't understand otherwise you won't learn. As for asking for code to copy paste in that's obviously not what I am asking for because that is pointless and each and every program is written in a different way.

6
General / Re: I want to make sprites appear with a random time delay
« on: March 13, 2016, 08:42:58 pm »
I don't really understand the code you sent me ?
Why is mvalue which is a bool less than time zero? What are you achieving with the += and the -= Please elaborate ..

7
General / Re: I want to make sprites appear with a random time delay
« on: March 13, 2016, 07:02:10 pm »
Bump anyone?

8
General / Re: I want to make sprites appear with a random time delay
« on: March 13, 2016, 01:58:45 am »
Alright back on topic haha. The random and all worked great. I want to be able to delay with time though for example

if (bla = bla){

Dosomething;

Wait 5 seconds then start again from the top
}

How can I do that using time or clock?

9
General / Re: I want to make sprites appear with a random time delay
« on: March 12, 2016, 09:17:55 pm »
That advice worked perfectly. Now, how can I make random variables?
float x for example

I want x to carry random numbers in a certain range? For example from 5-9

10
General / Re: I want to make sprites appear with a random time delay
« on: March 12, 2016, 07:52:03 pm »
Ok so I removed the window clear and my code worked but now the sprite is flashing non stop I want it to be a stable image. What is causing this flashing if the condition of the time has been met?

I figured that this was due to me placing the code in the event poll area instead of the window open area.. Now how can I generate a random time within a certain time range for example. Generate random seconds between 5-10 seconds?

Also I realized that it will continue to draw the sprite continuously since the condition was met I only want it to draw the sprite once and thats it. How can I do that?

11
General / Re: I want to make sprites appear with a random time delay
« on: March 12, 2016, 02:11:09 pm »
It is after my window draw and window display. Is this what's causing the issue?

12
General / Re: I want to make sprites appear with a random time delay
« on: March 12, 2016, 04:11:23 am »
Yes of course window display and window clear

13
General / Re: I want to make sprites appear with a random time delay
« on: March 12, 2016, 03:55:00 am »
Ok I will clarify,

As a test I first created the following:

sf::Clock clock;
   sf::Time time;
      time = clock.getElapsedTime();
   while (Window.isOpen()) {
      sf::Event Event;
      while (Window.pollEvent(Event)) {
         sf::Time t1 = sf::seconds(10.0);
         time = clock.getElapsedTime();
         std::cout << time.asSeconds() << std::endl;
         std::cout << t1.asSeconds() << std::endl;

         if (time.asSeconds() >= t1.asSeconds()) {
            std::cout << "player 1 is drawn";

         }

With this code I do in fact get "Player 1 is drawn" on the console after 10 seconds. However when I place the following code,

Window.draw(PlayerTwo); in the if statement and i already defined the sprite image and texture before in main. Nothing gets drawn on my window. What is going on here? There are no errors too.

14
General / Re: I want to make sprites appear with a random time delay
« on: March 12, 2016, 12:08:00 am »
Yes I figured it out by doing this

sf::Clock Clock;
   sf::Time time;
      time = Clock.getElapsedTime();
      Clock.restart();

But how can I make sprites appear at random times within a certain time range somehow?

Also when I do something like this

if (time.asSeconds() >= 10.0f) {
            Window.draw(Player1);
         }

It just doesn't work. The code runs fine but nothing is drawn after the 10 seconds pass

15
General / I want to make sprites appear with a random time delay
« on: March 12, 2016, 12:02:01 am »
I want to make certain sprites appear with a random time delay. For some reason just putting in this code in the beginning of main to begin with.


   sf::Clock clock;
      Time time1 = clock.getElapsedTime();
      Time time2 = clock.restart();

It gives me an error that time is an undeclared identifier? How can I go about doing this.  :(

Pages: [1]