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

Author Topic: Why does this not work properly?  (Read 3267 times)

0 Members and 2 Guests are viewing this topic.

kingsman142

  • Newbie
  • *
  • Posts: 10
    • View Profile
Why does this not work properly?
« on: January 10, 2012, 02:21:52 am »
Code: [Select]
if(sf::Mouse::IsButtonPressed(sf::Mouse::Left)){
                if( (bulletPos.x < cubezPos.x) && (sf::Mouse::IsButtonPressed(sf::Mouse::Left) ) ){
                    //Bullet.SetPosition(bulletPos.x + bulletSpeed , bulletPos.y);
                    //Cubez.SetPosition(cubezPos.x - cubezSpeed , cubezPos.y);
                    Sleep(1000);
                    Bullet.SetPosition(338.5, 305);
                    Cubez.SetPosition(500, 295);
                    Window.Draw(Bullet);
                    Window.Draw(Cubez);
                    Sleep(1000);
                    Bullet.SetPosition(491 , 305);
                    Cubez.SetPosition(330 , 295);
                    Window.Draw(Bullet);
                    Window.Draw(Cubez);
                }
                if((bulletPos.x > cubezPos.x) && (sf::Mouse::IsButtonPressed(sf::Mouse::Left))){
                    Cubez.SetPosition(0 , 295);
                    Sleep(3000);
                }
            }


When I hold down the left mouse button it's suppose to wait a second, move both sprites to their respectful positions then wait another second and move them again and then finish, but when I hold down the left mouse button it just waits like 2 seconds and moves each sprite to the second pair of coordinates.

Why does it not work???
OS: Windows 7
SFML Version: 2
Compiler: Code::Blocks with MinGW

Tau Sudan

  • Newbie
  • *
  • Posts: 5
    • View Profile
Why does this not work properly?
« Reply #1 on: January 10, 2012, 04:29:28 am »
I'd bet it's because you haven't:

window.Display();

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Why does this not work properly?
« Reply #2 on: January 10, 2012, 12:15:29 pm »
Quote from: "kingsman142"
I just want to rage so much to this forum because nobody replies to my posts or barely anybodies.
This is your second post, and you got an answer in 2 hours. Seriously, what do you expect?

By the way, you can be happy you even got an answer, given the completely useless thread title. Please read this post and take the mentioned points into account when posting next time. It will increase the amount of helpful answers a lot.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

caracal

  • Newbie
  • *
  • Posts: 19
    • View Profile
Why does this not work properly?
« Reply #3 on: January 10, 2012, 12:45:23 pm »
I see a few things wrong here.

1. Your trying to work on a problem when your
obviously irritated. Tip: Don't force it, walk away
from it for awhile or work on something else.

2. Design Patterns and Control Flow.
Your just dumping a heap of code that does what you want
into a mouse press event. Research callbacks and signal & slots.
The way your doing it now is just asking for problems.

3. Post all of your code so we can take a look, compile it tinker with
it and find the issue and make our suggestions, or give proper feedback.

4. Be kind and polite. This is an open community, no one has to help you
but if your kind, polite and help others when you can. Then others will help
you.

kingsman142

  • Newbie
  • *
  • Posts: 10
    • View Profile
Why does this not work properly?
« Reply #4 on: January 10, 2012, 12:59:47 pm »
I'm sorry Nexus and Tau Sudan.  Caracal is right.  I was irritated with this problem so much and I couldn't find a response and I became impacient so I took it out on these forums.  I apologize for the anger.  I will look into that tread the next time I'm going to post something new Nexus.  And Caracal, I'll remember to keep those things in mind and try to fix the problem.  I enjoyed reading your post.
OS: Windows 7
SFML Version: 2
Compiler: Code::Blocks with MinGW

caracal

  • Newbie
  • *
  • Posts: 19
    • View Profile
Why does this not work properly?
« Reply #5 on: January 10, 2012, 01:11:05 pm »
Quote from: "kingsman142"
I'm sorry Nexus and Tau Sudan.  Caracal is right.  I was irritated with this problem so much and I couldn't find a response and I became impacient so I took it out on these forums.  I apologize for the anger.  I will look into that tread the next time I'm going to post something new Nexus.  And Caracal, I'll remember to keep those things in mind and try to fix the problem.  I enjoyed reading your post.


Happens to me all the time just yesterday I was building a custom scenegraph, worked on a problem i had with the code for 5 hours.
Got mad almost threw my keyboard. But I didn't I went and took a nap
and when I woke up, Right away I seen the problem and fixed it.

kingsman142

  • Newbie
  • *
  • Posts: 10
    • View Profile
Why does this not work properly?
« Reply #6 on: January 10, 2012, 09:41:42 pm »
Do you have any solution I could try to fix the problem, Caracal?
OS: Windows 7
SFML Version: 2
Compiler: Code::Blocks with MinGW

kingsman142

  • Newbie
  • *
  • Posts: 10
    • View Profile
Why does this not work properly?
« Reply #7 on: January 10, 2012, 11:54:09 pm »
I fixed it.  Thank you everybody, especially Caracal, for giving me useful advice that I can use in the future.
OS: Windows 7
SFML Version: 2
Compiler: Code::Blocks with MinGW