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

Pages: [1]
1
Graphics / Weird Crash
« on: June 14, 2010, 07:30:51 am »
Ah, thanks! No more crashing! I would still like to know why my program takes up so much memory (anywhere from 70 to even 100 mb). I also have a Tic-Tac-Toe program that runs at a much more respectable 10-15 mb, but uses %100 of two cores (doesn't touch the other two). Why are these programs taking up so much resources? It doesn't really bug me, but it seems a bit ridiculous. Oh, and it seems Ubuntu doesn't automatically close a window when I press Alt+F4. It seems to be X11 that does it; when I run SFML in an Xlib window, it will automatically close the program with Alt+F4 without me having to say so.

2
Graphics / Uhh....
« on: June 14, 2010, 06:53:59 am »
Alright, well, I just ran it and looked at the system monitor and it seems my program takes up 81.6 MB of memory.:shock: Yes, the program you see above takes up over 80 MB of memory. That just doesn't seem right at all. Oh, and it seems that I forgot to put my system specs in the above post, so here goes:

OS: Ubuntu 10.04
CPU: Core-i5 750 @ 2.66 GHz per core (4 cores)
Memory: 2 GB @ 1066 MHz
Compiler/IDE: GCC/Codeblocks

3
Graphics / Weird Crash
« on: June 14, 2010, 06:27:26 am »
When I compile and run the below program and move my mouse around the screen a few times (it also helps a bit if you click around), the program closes. The weird thing is that I get a 0x0 "EXIT_SUCCESS" message when the program exits. It happens more often if you put more commands and event checks and stuff in. (The comments are for my own benefit; I'm not trying to make everybody look like a noob just because I am one)

Code: [Select]

#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

int main()
{
    //Creating variables that will define the size of the game window
    int Xres = 1440, Yres = 900;

    // Creates a RenderWindow type window
    sf::RenderWindow App(sf::VideoMode(Xres, Yres, 32), "Awesomely Cool Window", sf::Style::Fullscreen);
    App.UseVerticalSync(true);

    //Creates a font
    sf::Font MyFont;

    //Creates a buffer and loads the sound file
    sf::SoundBuffer Buffer;
    if (!Buffer.LoadFromFile("files/Menu.ogg"))
        return EXIT_FAILURE;

    //Loads the font file
    if (!MyFont.LoadFromFile("files/Achafexp.ttf", 200))
        return EXIT_FAILURE;

    //Creates a sound
    sf::Sound Sound;

    //Creates some text and and all the settings
    sf::String Text("Hello", MyFont, 200);
    Text.SetColor(sf::Color(0, 0, 0));
    Text.SetRotation(0.f);
    Text.SetScale(0.f, 0.f);
    Text.Move(100.f, 200.f);

    //Creates an image and loads the image file
    sf::Image Image;
    if (!Image.LoadFromFile("files/smiley.png"))
        return EXIT_FAILURE;

    // Creates a couple sprites using the image created above
    sf::Sprite CoolSprite(Image);
    sf::Sprite CoolSprite2(Image);

    //All the settings for the sprites
    CoolSprite.SetColor(sf::Color(255, 255, 255, 255));
    CoolSprite.SetPosition(132.f, 42.f);
    CoolSprite.SetCenter(32, 32);

    CoolSprite2.SetColor(sf::Color(255, 0, 0, 255));
    CoolSprite2.SetPosition(42.f, 42.f);
    CoolSprite2.SetCenter(32, 32);

    //Assignes the buffer made above to the sound made above, effectively assigning the sound file to the sound
    Sound.SetBuffer(Buffer);

    //Loops the sound
    Sound.SetLoop(true);

    //Plays the sound
    Sound.Play();

    // Starts the main loop thing
    while (App.IsOpened())
    {
        //Makes the window do stuff when the user does stuff
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if ((Event.Type == sf::Event::Closed) || (Event.Key.Code == sf::Key::Escape) || (Event.Key.Code == sf::Key::F4 && Event.Key.Alt))
                App.Close();

            if (Event.Key.Code == sf::Key::F1)
            {
                sf::Image Screen = App.Capture();
                Screen.SaveToFile("screenshot.jpg");
            }

            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::P))
            {
                if (Sound.GetStatus() == sf::Sound::Playing)
                    Sound.Pause();
                else
                    Sound.Play();
            }

            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::O))
                Sound.Stop();
        }

        //Gets the FPS
        float ElapsedTime = App.GetFrameTime();

        //Makes the sprites move and spin around when certain keys are pressed
        if (App.GetInput().IsKeyDown(sf::Key::Left))  CoolSprite.Move(-500 * ElapsedTime ,0);
        if (App.GetInput().IsKeyDown(sf::Key::Right)) CoolSprite.Move( 500 * ElapsedTime ,0);
        if (App.GetInput().IsKeyDown(sf::Key::Up))    CoolSprite.Move(0, -500 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Down))  CoolSprite.Move(0,  500 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Add))      CoolSprite.Rotate(-200 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Subtract)) CoolSprite.Rotate(+200 * ElapsedTime);

        if (App.GetInput().IsKeyDown(sf::Key::A))  CoolSprite2.Move(-500 * ElapsedTime ,0);
        if (App.GetInput().IsKeyDown(sf::Key::D)) CoolSprite2.Move( 500 * ElapsedTime ,0);
        if (App.GetInput().IsKeyDown(sf::Key::W))    CoolSprite2.Move(0, -500 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::S))  CoolSprite2.Move(0,  500 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::E))      CoolSprite2.Rotate(-200 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Q)) CoolSprite2.Rotate(+200 * ElapsedTime);

        //Makes the sprites go back to their exact original positions when the spacebar is pressed
        if (App.GetInput().IsKeyDown(sf::Key::Space))
        {
            CoolSprite2.SetPosition(42.f, 42.f);
            CoolSprite.SetPosition(132.f, 42.f);
            CoolSprite.SetRotation(0.f);
            CoolSprite2.SetRotation(0.f);
        }

        //Finds the center of the screen from the resolution the user entered at the beginning of the program
        int xcenter, ycenter;
        xcenter = Xres / 2;
        ycenter = Yres / 2;

        //Set Rectangle lengths in a X1, Y1, X2, Y2, Color, [OutlineSize], [OutlineColor] format.
        sf::Shape Rect = sf::Shape::Rectangle(200, 200, 400, 400, sf::Color::Green, 20, sf::Color::Red);
        Rect.SetColor(sf::Color(255, 255, 255, 200));
        Rect.SetCenter(300, 300);
        Rect.SetPosition(xcenter, ycenter);

        // Clear the screen with a color (R, G, B) format
        App.Clear(sf::Color(255, 255, 225));

        // Draws the sprites, rectangle, and text on the screen
        App.Draw(CoolSprite);
        App.Draw(CoolSprite2);
        App.Draw(Rect);
        App.Draw(Text);

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

    return EXIT_SUCCESS;
}

4
Window / error: expected primary-expression before '.' token
« on: June 14, 2010, 01:58:59 am »
Ah, thanks! The compiler error is gone! Doesn't do what I want, but there's probably just some other messed-up piece of code somewhere...

EDIT: Found and corrected error. Was totally unrelated. Thanks kitchen for fixing yet another error. (It was still very much in the early development stage)

5
Window / error: expected primary-expression before '.' token
« on: June 14, 2010, 01:00:16 am »
Alright, so I'm making a tic-tac-toe game. I want to make it so that if the user clicks the upper left-hand corner of the screen, a 'X' appears. I am trying to use the following code:
Code: [Select]
while (App.GetEvent(Event))
        {
            unsigned int MouseX = Input.GetMouseX(); // Error 1
            unsigned int MouseY = Input.GetMouseY(); // Error 2
            bool LeftButtonDown = Input.IsMouseButtonDown(sf::Mouse::Left); //Error 3

            if ((LeftButtonDown == true) && (MouseX << 50) && (MouseY << 50))
            {
                SprCross1.SetPosition(25.f, 25.f);
                X1 = 1;
            }
        }

When I try to compile I get three errors saying "error: expected primary-expression before '.' token". What is the problem? I am following the tutorial's example exactly. Oh, and yes, I did put "using sf::Input" at the beginning of the program. I am using GCC, Linux Ubuntu, and C++.

Pages: [1]