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

Pages: [1]
1
General / Re: How to save a display ?
« on: April 22, 2013, 02:59:23 pm »
Ok, I thought that recalculate every time would have use a lot of process, but finally it works perfectly ! =)

2
General / How to save a display ?
« on: April 22, 2013, 01:38:05 pm »
Hi,
I have a project in which I have to draw a graphic. So I have to calculate the positions and then draw it. I would like the user to be able to display in a small rectangle the position of the point he is pointing with his mouse. That is already done.
The thing is that I have this result :

I would like to save the display I have from the graphic to display it instantly and not recalculate everything every time. And of course let only one box at a time displayed.
How can I do that ?

3
Graphics / How to draw a line between two points ?
« on: April 06, 2013, 03:49:46 pm »
Hi,
I've found in the documentation this part of code :

Quote
sf::VertexArray lines(sf::LinesStrip, 2);
 lines[0].position = sf::Vector2f(10, 0);
 lines[1].position = sf::Vector2f(20, 0);

 window.draw(lines);

(cf. :  http://www.sfml-dev.org/documentation/2.0/classsf_1_1VertexArray.php )

Which is drawing a line ! :)
But, how can I change the color of this line ?

And is there another easier way to draw lines ? (I mean is it the good way to do it ?)

Thanks in advance !

4
General / Re: How to handle multiple event for multi player ?
« on: March 20, 2013, 02:54:22 am »
Yep, I had thought of it. But I was wondering if there were no other way to handle it.  ;D Anyway thanks for answering, I'll probably do that way.

5
General / Re: How to handle multiple event for multi player ?
« on: March 20, 2013, 01:39:49 am »
Hmm not sure that'll work... I already tried something similar :
Quote
eInput  LibrarySFML::handleEvent1()
{
  while (window.pollEvent(event))
    {
      if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Left)
        return (LEFT);
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Right)
        return (RIGHT);
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Up)
        return (UP);
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Down)
        return (DOWN);
    }
}

void    LibrarySFML::handleEvent2()
{
  while (window.pollEvent(event))
    {
      if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Q)
        input2 = LEFT;
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::D)
        input2 = RIGHT;
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Z)
        input2 = UP;
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::S)
        input2 = DOWN;
    }
}

In this code, if I call handleEvent1 before handleEvent2, the window.pollEvent is going to "unsack" all the events of the window. Then in the handleEvent2, there won't have any event.

6
General / Re: How to handle multiple event for multi player ?
« on: March 19, 2013, 01:23:03 pm »
Quote
Do you want that the play can walk left and up and the same time?
No.

For example:
If the event stack (I know it is not a stack, but really looks like the same) is : Left, Q, Up.
Left and Up is the player1 input. Q is the player2 input.
In the case I showed, the player1 will go up and player2 left. I could handle it so that the player1 go left and player2 still left, but the up event will be unstacked. This way the player1 won't go left then up, I only can make him go left or up (first or last input of the player).

7
General / How to handle multiple event for multi player ?
« on: March 19, 2013, 11:55:46 am »
Hi,
I'm trying to do a multi player game. The player1 use:  Left, Up, Right, Down ;  and the player2 use Q, Z, D, S (for example).

I have one handler event function :
Quote
void    LibrarySFML::handleEvent(eInput& input1, eInput& input2)
{
  while (window.pollEvent(event))
    {
      if ((event.type == sf::Event::Closed) || (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape))
        input1 = QUIT;
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Left)
        input1 = LEFT;
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Right)
        input1 = RIGHT;
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Up)
        input1 = UP;
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Down)
        input1 = DOWN;
      if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Q)
        input2 = LEFT;
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard:: D)
        input2 = RIGHT;
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Z)
        input2 = UP;
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::S)
        input2 = DOWN;
    }
}

The thing is that, this way, if the player1 push Left then Up, he'll go Up. And even if I take the first input, he'll go Left (great), but the Up event will be unstacked. The best way to handle it is to do so:
Quote
void    LibrarySFML::handleEvent()
{
  while (window.pollEvent(event))
    {
      if ((event.type == sf::Event::Closed) || (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape))
        return (QUIT);
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Left)
        return (LEFT);
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Right)
        return (RIGHT);
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Up)
        return (UP);
      else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Down)
        return (DOWN);
    }
}

This way the Left will be return and the next turn in will return Up ! But I'm handling event for two player so I can't do that this way, or they won't be able to move in the same time together.

Any advice ?
Thanks in advance.

8
General / Re: How to handle ONLY one event ?
« on: March 15, 2013, 05:14:23 pm »
Ok, I'll look for sf::Clock. But that is not resolving my pause problem.
I'm trying that, but I never go out of the second loop:
If the user press Space if goes on the function :
Quote
{
while (event.type == sf::Event::KeyPressed); // I'm waiting the user to release the space key
while (window.waitEvent(event) && event.key.code != sf::Keyboard::Space); // then waiting him to press space again
}

9
General / Re: How to block window resize ?
« on: March 15, 2013, 05:06:31 pm »
window.create(sf::VideoMode(x, y), "SFML window", sf::Style::Resize, 0);
I don't understand why people seem to think, that setting something specifically will remove it? ???
You're not the first one asking this, but it might be interesting to hear why you thought it would prevent resizing by setting the resize property?
Maybe Laurent can make it clearer in the documentation/tutorial (or haven't you taken a look those?).

Btw. for posting code, don't use the quote tag, but use the code=cpp tag. ;)

Because of this post : http://en.sfml-dev.org/forums/index.php?topic=5359.0
 ;D

So, what can I do to prevent it?

10
General / How to handle ONLY one event ?
« on: March 15, 2013, 05:05:05 pm »
Hi,
I would like to handle the input one by one. I know the events are "stacking" in SFML. But if the user is "spamming" his keyboad like a fool, I don't want to stack it. I don't know if it's clear. If Space is used for a jump, if the user spam his Space key, he'll jump again and again when he hit the floor.

And I would like to know how to clear the event i'm handling. For exemple when I use Space to pause the game and I want another Space to leave the pause it, the execution will go too fast, so the last input will be the Space and it will directly leave the pause instantly. Must I have to wait the user to release the Space key and then wait another Space to leave the pause?

Thanks in advance !

11
General / How to block window resize ?
« on: March 15, 2013, 04:50:23 pm »
Hi,
I'm trying to block the resize of the window and by the way, if possible remove the maximize button of the window.

How can I do that?

That is not working:

Quote
window.create(sf::VideoMode(x, y), "SFML window", sf::Style::Resize, 0);

Thanks in advance.

Pages: [1]