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

Pages: 1 2 3 [4]
46
Graphics / Sprite Movement on Single MouseClick
« on: January 04, 2012, 04:56:00 pm »
Bump?

If it helps, I just need to find a way to define OldPosition (where the sprite was) and a way to define NewPosition (where the sprite is going).

47
Graphics / Sprite Movement on Single MouseClick
« on: January 02, 2012, 12:55:32 am »
Hello.  I was wondering if anyone had any suggestions as how to go about making a sprite move from Point A to Point B on a 2d plane.  I am able to do this, but the sprite simply warps from one point to another...I have looked into making a speed variable (dont want to use framerates because of the "faster on faster computer" thing) somehow.  I have also looked into vectors some, but have not been able to figure out how to set the sprite's position with the vector.

EDIT: Using SFML 1.6

Maybe some code will help too
Code: [Select]
if (App.GetInput().IsMouseButtonDown(sf::Mouse::Left)) {

            OldX = PlayerObj.GetPosition().x;
            OldY = PlayerObj.GetPosition().y;
            NewX = App.GetInput().GetMouseX();
            NewY = App.GetInput().GetMouseY();
            XVector = (OldX - NewX);
            YVector = (OldY - OldY);
        }
        //Vector...
        float OldPosition = ???;
        float NewPosition = ???;
        sf::Vector2f GetDir(sf::Vector2f OldPosition);
        sf::Vector2f RVector = NewPosition - OldPosition;
        float temp =(float) sqrt((RVector.x * RVector.x + RVector.y * RVector.y));
        RVector = RVector / temp;
        RVector = RVector * SPEED;
        //Set position...
        PlayerObj.SetPosition(RVector.x, RVector.y);

48
Graphics / Main Menu selection
« on: December 31, 2011, 10:22:28 pm »
I am trying to do a similar thing with my project.  I think it has something to do with the sf::Rect class and the Contains function, but the documentation I have been able to find on it isnt very helpful.

EDIT: Perhaps the below code will help people in trying to figure out what we are trying to do. There are no problems with compiling it (using SFML 1.6), but when the .exe is run, the window closes as soon as the cursor enters it.

EDIT #2:  Lol, nevermind. I figured it out. Just had my code in the wrong place. Below is the code for a simple button click if anyone wants it.

Code: [Select]
#include <SFML/Graphics.hpp>

 int main()
 {
     sf::RenderWindow App(sf::VideoMode(400, 300), "Button Test");

     sf::Image Button1Img;
     if (!Button1Img.LoadFromFile("button1.png"))
         return EXIT_FAILURE;
     sf::Sprite Button1Obj(Button1Img);

     sf::String Text1;
     Text1.SetText("FAILURE");
     Text1.SetPosition(0, 100);

     float XPos = Button1Obj.GetPosition().x;//the x position of the button
     float YPos = Button1Obj.GetPosition().y;//the y position of the button
     float XSize = Button1Obj.GetSize().x;//the width of the button
     float YSize = Button1Obj.GetSize().y;//the height of the button
     float MouseX = App.GetInput().GetMouseX();//the x coord of the mouse when clicked
     float MouseY = App.GetInput().GetMouseY();//the y coord of the mouse when clicked

     while (App.IsOpened())
     {
         sf::Event Event;
         while (App.GetEvent(Event))
         {
             if (Event.Type == sf::Event::Closed)
                 App.Close();

                 if (App.GetInput().IsMouseButtonDown(sf::Mouse::Left)) {
                    MouseX = App.GetInput().GetMouseX();
                    MouseY = App.GetInput().GetMouseY();


                if((MouseX >= XPos && MouseX <= XPos+XSize && MouseY >= YPos && MouseY <= YPos+YSize) == true)  {
                Text1.SetText("SUCCESS");
                }}
         }
         App.Clear();
         App.Draw(Button1Obj);
         App.Draw(Text1);
         App.Display();
     }
     return EXIT_SUCCESS;
 }

49
General / Storing and recalling variables within an event
« on: December 30, 2011, 10:32:05 pm »
Lol, primitive variables completely skipped my mind. Thanks man :)

50
General / Storing and recalling variables within an event
« on: December 30, 2011, 04:59:16 am »
So I am trying to make an application that requires multiple values to be considered.  When EventA happens, I want Variable1 to be a certain X number.  Then, if statements can check to see if X is the number for that certain if statement, and carry on with a specific order.  I am not aware of how to do this exactly, so I tried to do it with strings:

Code: [Select]

#include <SFML/Graphics.hpp>

 int main()
 {
     // Create the main window
     sf::RenderWindow App(sf::VideoMode(800, 600), "Test");

     sf::String Value1("1");

     sf::String Text1("Value1 is active");
     Text1.SetPosition(100.f, 100.f);

     // Start the game loop
     while (App.IsOpened())
     {
         // Process events
         sf::Event Event;
         while (App.GetEvent(Event))
         {
             // Close window : exit
             if (Event.Type == sf::Event::Closed)
                 App.Close();

             if (App.GetInput().IsKeyDown(sf::Key::Up))   Value1.SetText("2")

             if (Value1.GetText() == "1")   Text1.SetText("Value1 is active");
             if (Value1.GetText() == "2")   Text1.SetText("Value1 is inactive");
         }

         // Clear screen
         App.Clear();

         // Draw the string
         App.Draw(Text1);

         // Update the window
         App.Display();
     }

     return EXIT_SUCCESS;
 }


It doesnt work though.  Any suggestions? Sorry if I havent been clear, I am not sure how to express what I want to do  :cry:

51
Graphics / Displaying a status
« on: December 29, 2011, 05:10:09 pm »
Alright man, thanks. I have it working now ;)

52
Graphics / Displaying a status
« on: December 29, 2011, 05:47:17 am »
So I have been messing around with trying to get the status of the music status to display as text.  I have no trouble displaying text, or getting the status, its getting the status to display as text on my screen thats the problem.  Any help would be much appreciated :)

-Lucas Shadow

Pages: 1 2 3 [4]
anything