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

Author Topic: mouse click on moving animation problem  (Read 1746 times)

0 Members and 1 Guest are viewing this topic.

ntrncx

  • Newbie
  • *
  • Posts: 5
    • View Profile
mouse click on moving animation problem
« on: November 19, 2011, 11:16:38 pm »
Hey all
Thats my second project and i am really new in all this,i study c++ for hobby.

Now to my problem if you can help me with documentation or advices will be apreciated :D

i use SFML obviously and this for animation http://www.sfml-dev.org/wiki/en/sources/frame_anim_animated

i have an animation and i want to be able to click it with the mouse where ever will be.
for mouse click i use that :

Code: [Select]
if(events.Type == events.MouseButtonReleased && events.MouseButton.Button == sf::Mouse::Left)
        if((input.GetMouseX()>=Tr.x && input.GetMouseX()<=Bl.x) && (input.GetMouseX()>=Bl.y && input.GetMouseY()<=Bl.y))
        {
            App.Close(); // thats just for testing to see that if actually works,but it doesnt
        }


the coordination is right Tr stands for top right corner and Bl for bottom left

in main i have that

Code: [Select]
for(int loop=totalBalloons-1;loop>=0;loop--)
        {  
            BALLOONS[loop].Move(0,yAxis);
            topLeftCorner=BALLOONS[loop].GetPosition();
            bottomRightCorner.x=topLeftCorner.x+50;
            bottomRightCorner.y=topLeftCorner.y+65;
            App.Draw(BALLOONS[loop]);  
            BALLOONS[loop].Update();      
        }


i am almost sure that the problem is that the animations are inside vectors .

so they share things,any suggestions?
thanks for your time :D

sbroadfoot90

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
mouse click on moving animation problem
« Reply #1 on: November 20, 2011, 11:38:44 pm »
your if statement is wrong

Code: [Select]
if((input.GetMouseX()>=Tr.x && input.GetMouseX()<=Bl.x) && (input.GetMouseX()>=Bl.y && input.GetMouseY()<=Bl.y))

and by putting this in the loop

Code: [Select]
           topLeftCorner=BALLOONS[loop].GetPosition();
            bottomRightCorner.x=topLeftCorner.x+50;
            bottomRightCorner.y=topLeftCorner.y+65;


you are overwriting the values each iteration of the loop.

I can't help you much more than that because you have only included two snippets of your code that don't even seem to go together (is Tl short for topLeftCorner??)

ntrncx

  • Newbie
  • *
  • Posts: 5
    • View Profile
mouse click on moving animation problem
« Reply #2 on: November 22, 2011, 01:00:28 am »
yes Tl means that,thanks a lot i solved the problem

what i did wrong wast hat the following code was inside a function
Code: [Select]
if(events.Type == events.MouseButtonReleased && events.MouseButton.Button == sf::Mouse::Left)
        if((input.GetMouseX()>=Tr.x && input.GetMouseX()<=Bl.x) && (input.GetMouseX()>=Bl.y && input.GetMouseY()<=Bl.y))
        {
            App.Close(); // thats just for testing to see that if actually works,but it doesnt
        }


i put it out and worked as a charm :D

and thanks a lot for the observation about the repeating code,i try to learn :D[/code]

 

anything