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.


Topics - Wander

Pages: 1 [2] 3
16
General / [Solved] Resource Manager
« on: January 03, 2011, 02:43:08 am »
I'm trying to create an RTS and I know I need a resource manager, but I'm not sure how to go about making one.
Anyone have any solutions? Algorithms?
Thanks. ;D

17
Graphics / [Solved] Trouble Centering Text
« on: January 02, 2011, 08:22:34 pm »
I'm trying to center my text inside of box, but I'm having some trouble doing so.

Does anyone know what is wrong with this code?
x,y is the corner in the top-left.
x2,y2 is the corner in the bottom-right.
x = left
y = top
x2 = right
y2 = bottom

Code: [Select]
sf::FloatRect StringRect( sf_text.GetRect() );
canvas.SetPosition(x, y);
sf_text.SetPosition(x, y);
sf_text.Move(((x2-x)/2)-StringRect.GetWidth()/2,((y2-y)/2)-StringRect.GetHeight()/2);

18
Graphics / [Solved] Text Coords and Shape Coords
« on: December 21, 2010, 05:11:55 am »
I am making a class that creates buttons in SFML. I have been having a problem for about a month now. The problem is that the text won't position inside of the outlining box.

After much trial and error I have figured out why it won't match up.
It seems to me that the sf::Shape class and the sf::String class are positioned on separate coordinate planes or move at different interval factor per one coordinate (e.g. 1 sf::Shape coordinate = 0.5 sf::String coordinates).

If anyone knows how to fix this I would love some help. I'm about ready to pull my hair out at this. Thank you. :)[/b]

19
General / Not Working without Console
« on: December 03, 2010, 07:19:18 am »
I am making a program that creates a usable GUI. I was testing it as a console application. And then I tested it as a GUI Application. Neither worked correctly.

Console: It made me click on a selection a random number of times before it would submit. Sometimes 3, 1, 10. It was totally random. I did however get it to submit in one try every time. If I opened the console window as my current window before clicking on a choice it would work. I don't know if this is a coding error or something with the IDE or API.

GUI App: This one also makes me click a random number of times but when it does submit it doesn't return a value like I coded it to do.

These could be coding errors on my part, but I can't be sure. Any suggestion is appreciated.

20
Graphics / Can't Figure Out Input Om Screen
« on: November 12, 2010, 02:19:31 am »
I can't figure out how to take input inside the window. Any help would be great.

21
Graphics / Array Points
« on: September 11, 2010, 07:21:18 pm »
I'm working on a map program. I have it working where it displays coordinate on the map, but I can't figure out how to get it to display multiple coordinates without creating a new sf::Shape for each coordinate.

22
Graphics / Thread Background Display
« on: September 09, 2010, 04:32:44 am »
I've been trying to get a background picture to display inside my secondary window in my secondary thread. It won't display anything when I move the file loading into main(), but if I put the file loading into my thread I get the void conversion error. I've tried changing the void to an int, but it won't accept that.

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

using std::string;
using std::ios;
using std::ofstream;
using std::ifstream;

using std::cin;
using std::cout;
using std::endl;

void extraWindow(void *UserData)
{
    sf::Image BackImage2;
    if (!BackImage2.LoadFromFile("Images/Fire.bmp"))
        return EXIT_FAILURE;
    sf::Sprite BackG2(BackImage2);

    sf::RenderWindow App2(sf::VideoMode(1280, 720, 32), "Laz's Interactive Map :: The Wrath... :: PvP Created");

    sf::Vector2f CenterBack(960, 540);
    sf::Vector2f HalfBack(480, 270);
    sf::View BackgroundTh(CenterBack, HalfBack);
    BackgroundTh.Zoom(0.5f);

    while (App2.IsOpened())
    {
        sf::Event ThreadEvent;
        while (App2.GetEvent(ThreadEvent))
        {
            // Close window : exit
            if (ThreadEvent.Type == sf::Event::Closed)
                App2.Close();

            // Press escape : exit
            if ((ThreadEvent.Type == sf::Event::KeyPressed) && (ThreadEvent.Key.Code == sf::Key::Escape))
                App2.Close();
        }

        App2.SetView(BackgroundTh);
            App2.Draw(BackG2);

    }
}



int main()
{
    sf::RenderWindow App(sf::VideoMode::GetMode(0), "Laz's Interactive Map :: The Wrath... :: PvP Created");

    //Thread Stuff
    bool thread = false;
    sf::Thread Window(extraWindow);

    // Main loop
    while (App.IsOpened())
    {
        // Event loop
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F2)) {
                thread = true;
                Window.Launch();
            }

            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Press escape : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();

        }
    }

            App.Display();

    return 0;
}


This code is very watered down from my original. It recreates the same problem though.

23
Graphics / Rotating View
« on: September 07, 2010, 05:15:00 am »
I've been trying to figure out a way to rotate an entire view without manually rotating EVERY single object inside the view. There are no member functions for it, so I was wondering if someone knew about some other way.

24
Window / Two Windows
« on: September 05, 2010, 08:19:40 am »
I've been trying for the past 2 hours to get my program to use two windows at the same time, but I can't succeed. Can someone help me out here? I've tried using threads. I think I'm just using them wrong.

25
Graphics / Weird Image Crushing
« on: September 05, 2010, 06:44:32 am »
Whenever I draw a rectangle and then draw a circle ontop of it, the circle is elangated vertically. The same thing happens with other shapes.

___________
|__________|
|__________|
___________
this becomes

___________
|__________|
|__________|
|__________|
|__________|
|__________|
___________
this....

Please assist. :D

EDIT: Spaced out the shapes

26
Graphics / Getting Background On
« on: September 02, 2010, 03:31:34 am »
Hey,

I've been trying to put a background into my program that has three "layers".

The top layer is the "default view" (GetDefaultView). It has my text on it.
The middle layer is the layer that I printed a map onto. (View)
The back layer is the layer I want to print a background onto. (BackG) I feel like I'm doing it correctly, but obviously not.

Here is all of the code relating to the declaration, adjustment, and displaying of those layers:
Code: [Select]
sf::Image BackImage;
    if (!BackImage.LoadFromFile("Pheonix.bmp"))
        return EXIT_FAILURE;
    sf::Sprite BackG(BackImage);

    sf::Image IconImage;
    if (!IconImage.LoadFromFile("TH Icon.bmp"))
        return EXIT_FAILURE;
    sf::Sprite Icon(IconImage);

sf::RenderWindow App(sf::VideoMode::GetMode(0), "Laz's Interactive Map :: The Wrath... :: PvP Created");
    App.SetIcon(64,64,IconImage.GetPixelsPtr());


sf::Shape MapPh;
    MapPh.AddPoint(0,0,sf::Color(0,100,0));
    MapPh.AddPoint(9000,0,sf::Color(0,100,0));
    //MapPh.AddPoint(3500,1500,sf::Color(0,125,0));
    MapPh.AddPoint(9000,3000,sf::Color(0,100,0));
    MapPh.AddPoint(0,3000,sf::Color(0,100,0));
    MapPh.EnableFill(true);
    MapPh.EnableOutline(false);
    MapPh.SetOutlineWidth(10);

    sf::Shape PhMid = sf::Shape::Line(3000, 0, 3000, 3000, 20, sf::Color::Black);
    sf::Shape DrMid = sf::Shape::Line(6000, 0, 6000, 3000, 20, sf::Color::Black);
    sf::Shape HorMid = sf::Shape::Line(0, 1500, 9000, 1500, 20, sf::Color::Black);

    sf::Vector2f Center(4500, 1500);
    sf::Vector2f HalfSize(2250, 750);
    sf::View View(Center, HalfSize);
    View.Zoom(0.35f);

    sf::Vector2f CenterBack(960, 540);
    sf::Vector2f HalfBack(480, 270);
    sf::View Background(CenterBack, HalfBack);


App.SetView(Background);

            App.Draw(BackG);

        App.SetView(View);

            App.Clear();

            App.Draw(MapPh);
            App.Draw(PhMid);
            App.Draw(DrMid);
            App.Draw(HorMid);

        // Reset to the default view to draw the interface
        App.SetView(App.GetDefaultView());

            App.Draw(TopLeft);

            if (help == true)
                App.Draw(Help);
            else
                App.Draw(Main);

                App.Draw(Coord);
                if (X == true)
                    App.Draw(Comma);

            App.Draw(CopyRight);

            sf::Vector2f CursorPos = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());
            Cursor.SetPosition(CursorPos);
            App.Draw(Cursor);

            App.Display();


Any help will be greatly appreciated.

==================================
EDIT: The problem is that the background won't display. The top two layers display fine, but the background is black instead of have the desired picture on it.

27
General / Running Program Without IDE
« on: September 02, 2010, 02:18:38 am »
Hello

I am trying to create a program that will run directly off of a .exe file like most every program out there. However, whenever I double-click the .exe file it says: "The program can't start because sfml-graphics.dll is missing your computer. Try reinstalling the program to fix the problem."
I checked in my .cpp file's directory and I have all of the required dlls in there.

Here is my code:
Code: [Select]
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <fstream>


using std::string;
using std::ios;
using std::ofstream;
using std::ifstream;

/*void PrintFile(void* UserData)
{
    ifstream inFile; // Declare inFile
    ofstream outFile; // Declare outFile
    if (!inFile.is_open())  //Check to see if file is open
    {
        inFile.open("mapCoords.txt", ios::in); //If not, open file for output
        inFile.close(); //Close File
    }
    else { //If the file was opened...
        inFile.close(); //Close it
    }
}*/

int main()
{
    //sf::Thread PrintFile(&PrintFile);
    //PrintFile.Launch();

    //ifstream inFile; // Declare inFile
    //ofstream outFile; // Declare outFile

    sf::Image IconImage;
    if (!IconImage.LoadFromFile("icon.bmp"))
        return EXIT_FAILURE;
    sf::Sprite Icon(IconImage);

    sf::Image CursorImage;
    if (!CursorImage.LoadFromFile("cursor.cur"))
        return EXIT_FAILURE;
    sf::Sprite Cursor(CursorImage);
    Cursor.SetCenter(0, 0);
    Cursor.SetPosition(1000,500);

    sf::RenderWindow App(sf::VideoMode::GetMode(0), "Laz's Interactive Map :: The Wrath... :: PvP Created");
    App.SetIcon(64,64,IconImage.GetPixelsPtr());
    App.ShowMouseCursor(false);
    bool windowed = true;
    sf::VideoMode DesktopMode = sf::VideoMode::GetDesktopMode();

    sf::Font TypeKnight;
    if (!TypeKnight.LoadFromFile("Knights Templar.ttf"))
    {
        return EXIT_FAILURE;
    }
    sf::String Comma(" , ");
    Comma.SetFont(TypeKnight);
    Comma.Move(240,10);

    bool X = false;
    bool Y = false;
    std::string XCoord;
    std::string YCoord;
    sf::String Coord;
    Coord.SetFont(TypeKnight);
    Coord.Move(175,10);

    sf::String TopLeft("Text Input: ________________");
    TopLeft.SetFont(TypeKnight);
    TopLeft.Move(10,10);
    TopLeft.SetColor(sf::Color::White);

    sf::String Main("Press F12 to toggle the help menu");
    Main.SetFont(TypeKnight);
    Main.Move(10.f, 600.f);
    Main.SetColor(sf::Color::White);

    bool help = false;
    sf::String Help("Type A to add a coordinate\n\nType R to remove a coordinate\n\nType F to find a coordinate\n\nUse + and - to zoom in and out on the map\n\nUse the arrow keys to navigate the map\n\nPress F1 to toggle FullScreen mode\n\nPress ESC to exit the program\n\nPress F12 to toggle the help menu");
    Help.SetFont(TypeKnight);
    Help.Move(10.f,180.f);

    sf::String CopyRight("CopyRight 2010 Tyler Petresky :: All program code is subject to CopyRight Laws");
    CopyRight.SetFont(TypeKnight);
    CopyRight.SetColor(sf::Color::White);
    CopyRight.Move(1300.f, 125.f);
    CopyRight.Scale(0.5f, 0.5f);
    CopyRight.Rotate(-90.f);

    // Creates the PE map :: 7000x3000
    sf::Shape MapPh;
    MapPh.AddPoint(0,0,sf::Color(0,100,0));
    MapPh.AddPoint(9000,0,sf::Color(0,100,0));
    //MapPh.AddPoint(3500,1500,sf::Color(0,125,0));
    MapPh.AddPoint(9000,3000,sf::Color(0,100,0));
    MapPh.AddPoint(0,3000,sf::Color(0,100,0));
    MapPh.EnableFill(true);
    MapPh.EnableOutline(false);
    MapPh.SetOutlineWidth(10);

    sf::Shape PhMid = sf::Shape::Line(3000, 0, 3000, 3000, 20, sf::Color::Black);
    sf::Shape DrMid = sf::Shape::Line(6000, 0, 6000, 3000, 20, sf::Color::Black);
    sf::Shape HorMid = sf::Shape::Line(0, 1500, 9000, 1500, 20, sf::Color::Black);

    sf::Vector2f Center(4500, 1500);
    sf::Vector2f HalfSize(2250, 750);
    sf::View View(Center, HalfSize);
    View.Zoom(0.35f);

    enum State { State0, State1, State2, State3 };
    State myState = State0;
    int counter = 0;

    // Main loop
    while (App.IsOpened())
    {
        // Event loop
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Press escape : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();

            // Press F1 : Switch video mode
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F1)) {
                if (windowed == true) {
                    App.Create(DesktopMode, "Laz's Interactive Map :: The Wrath... :: PvP Created", sf::Style::Fullscreen);
                    windowed = false;
                }
                else {
                    App.Create(sf::VideoMode::GetMode(0), "Laz's Interactive Map :: The Wrath... :: PvP Created");
                    windowed = true;
                }
            }

            // Press F12 : Toggle help menu
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F12)) {
                if (help == false) {
                    help = true;
                }
                else {
                    help = false;
                }
            }

            // Press A : Add coords
            if (myState == State0 && (Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A))
            {
                std::cout << "ONE" << std::endl;
                myState = State1;
            }
            if (myState == State1 && (Event.Type == sf::Event::TextEntered))
            {
                if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Return))
                {
                    if (X == false)
                        X = true;
                    else
                        Y = true;
                }
                std::cout << "TWO" << std::endl;

                if (X == false && counter < 5) {
                    if (Event.Text.Unicode > 47 && Event.Text.Unicode < 58)
                    {
                        std::cout << "THREE" << std::endl;
                        XCoord += static_cast<int>(Event.Text.Unicode);
                        Coord.SetText(XCoord);
                        std::cout << XCoord << std::endl;
                    }
                    ++counter;
                }

                if (X == true && Y == false && counter < 5) {
                    if (Event.Text.Unicode > 47 && Event.Text.Unicode < 58)
                    {
                        std::cout << "FOUR" << std::endl;
                        YCoord += static_cast<int>(Event.Text.Unicode);
                        Coord.SetText(YCoord);
                        std::cout << YCoord << std::endl;
                    }
                    ++counter;
                }
            }
        }



        float ElapsedTime = App.GetFrameTime();

        // Move the map around the screen
        float Offset = 2000.f * App.GetFrameTime();
        if (App.GetInput().IsKeyDown(sf::Key::Up))    View.Move( 0,      -Offset);
        if (App.GetInput().IsKeyDown(sf::Key::Down))  View.Move( 0,      Offset);
        if (App.GetInput().IsKeyDown(sf::Key::Left))  View.Move(-Offset,  0);
        if (App.GetInput().IsKeyDown(sf::Key::Right)) View.Move(Offset,  0);

        // Zoom and unzoom using + and - keys
        if (App.GetInput().IsKeyDown(sf::Key::Add))      View.Zoom(1.005f);
        if (App.GetInput().IsKeyDown(sf::Key::Subtract)) View.Zoom(0.994f);

        App.SetView(View);

            App.Clear();

            App.Draw(MapPh);
            App.Draw(PhMid);
            App.Draw(DrMid);
            App.Draw(HorMid);

        // Reset to the default view to draw the interface
        App.SetView(App.GetDefaultView());

            App.Draw(TopLeft);

            if (help == true)
                App.Draw(Help);
            else
                App.Draw(Main);

                App.Draw(Coord);
                if (X == true)
                    App.Draw(Comma);

            App.Draw(CopyRight);

            sf::Vector2f CursorPos = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());
            Cursor.SetPosition(CursorPos);
            App.Draw(Cursor);

            App.Display();
    }



    return 0;
}


Any help would be greatly appreciated. ;)

Thanks

===================================
EDIT:
----------------------------------
I'm using Code::Blocks IDE

28
Graphics / If Statement Really Aggravating Problem! Grr...
« on: August 19, 2010, 06:38:29 am »
Okay! I'm going to sound like a total noob. Haha! I wasn't sure if this problem belonged on this forum or the normal C++ forum, so forgive me if this is in the wrong forum but here is my problem.

Code: [Select]
//DECLARATION
bool X = false;
    bool Y = false;
    std::string XCoord;
    std::string YCoord;
    sf::String Coord;
    Coord.SetFont(TypeKnight);
    Coord.Move(175,10);

    sf::String TopLeft("Text Input: ________________");
    TopLeft.SetFont(TypeKnight);
    TopLeft.Move(10,10);
    TopLeft.SetColor(sf::Color::White);

    enum State { State0, State1, State2, State3 };
    State myState = State0;
    int counter = 0;


//EVENT LOOP
            if (myState == State0 && (Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A))
            {
                std::cout << "ONE" << std::endl;
                myState = State1;
            }
            if (myState == State1 && (Event.Type == sf::Event::TextEntered))
            {
                if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Return))
                {
                    if (X == false)
                        X = true;
                    if (X == true && Y == false)
                        Y = true;
                }
                std::cout << "TWO" << std::endl;

                if (X == false && counter < 5) {
                    if (Event.Text.Unicode > 47 && Event.Text.Unicode < 58)
                    {
                        std::cout << "THREE" << std::endl;
                        XCoord += static_cast<int>(Event.Text.Unicode);
                        Coord.SetText(XCoord);
                        std::cout << XCoord << std::endl;
                    }
                    ++counter;
                }

                if (X == true && Y == false && counter < 5) {
                    if (Event.Text.Unicode > 47 && Event.Text.Unicode < 58)
                    {
                        std::cout << "FOUR" << std::endl;
                        YCoord += static_cast<int>(Event.Text.Unicode);
                        Coord.SetText(YCoord);
                        std::cout << YCoord << std::endl;
                    }
                    ++counter;
                }
            }




//MAIN LOOP
App.Draw(Coord);
                if (X == true)
                    App.Draw(Comma);


What is supposed to happen:
1) The user presses A to activate text input.
2) The user types in the X coordinate and it is displayed
3) The comma is displayed when the user hits enter.
4) The user types in the Y coordinate and it is displayed along side the X coordinate in this fashion: X , Y
5) When the user hits enter, both the X and the Y values are stored on a text file. I haven't put that in yet.
This isn't what happens, obviously...

What does happen though, it displays the X coordinate as I type it. Then if I reach 4 numbers in the coordinate, it doesn't display the comma even if I hit enter. However, if I hit enter when I have 1, 2, or 3 numbers the comma is displayed just fine. Afterwards, it doesn't let me type the Y coordinate and I don't know why.

Please don't say I haven't tried to fix this. I stayed up for 28 hours and never fixed this stupid problem. Then after sleeping I spent another 6 hours trying to fix it again. I know it's probably going to end up being something so stupid.... :D

Thanks

29
General discussions / RTS Engine?
« on: August 16, 2010, 04:01:57 am »
Hey. I really love SFML. It's so much easier to learn and grasp then SDL is. SDL boggled my mind. I was wondering if there are any good RTS engines that utilize SFML. If you know of any I would love to know.

30
Window / Output Flashes When I Type
« on: August 15, 2010, 03:22:37 pm »
Whenever I type in a number for the input in my program, it flashes onto the screen whenever I hit a number (I've not allowed it to take anything but numbers).
I'm not sure what's wrong.
Code: [Select]
   sf::Font TypeKnight;
    if (!TypeKnight.LoadFromFile("Knights Templar.ttf"))
    {
        return EXIT_FAILURE;
    }
    std::string XCoord;
    std::string YCoord;
    sf::String Coord;
    Coord.SetFont(TypeKnight);
    Coord.Move(175,10);


            // Press A : Add coords
            if (myState == State0 && (Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A))
            {
                std::cout << "ONE" << std::endl;
                myState = State1;
            }
            if (myState == State1 && (Event.Type == sf::Event::TextEntered))
            {
                std::cout << "TWO" << std::endl;

                if (counter < 5) {
                    // Handle ASCII characters only
                    if (Event.Text.Unicode > 47 && Event.Text.Unicode < 58)
                    {
                        std::cout << "THREE" << std::endl;
                        XCoord += static_cast<int>(Event.Text.Unicode);
                        Coord.SetText(XCoord);
                    }
                    ++counter;
                }
            }
            else {
                Coord.SetText("");
            }

    App.Draw(Coord);

    App.Display();

Pages: 1 [2] 3
anything