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

Pages: [1]
1
Audio / Re: Sound only plays in event loop
« on: September 20, 2013, 07:24:19 am »
That was it! Thank you so much!

2
Audio / Sound only plays in event loop
« on: September 20, 2013, 06:30:00 am »
This is some test code I wrote for an alarm clock program. It seems that the sound object only plays if its inside the inner while loop. If I move the mouse cursor in and out of the window, the sound restarts. I only want the sound to play if the time is equal to a time that I want the sound to go off. I wrote a function for that (not shown here) and the function works, so thats not the problem. Why can't sound play outside of an event loop?
int main(){
        sf::RenderWindow window(sf::VideoMode(400,400),"");
        sf::SoundBuffer buffer;
        sf::Sound sound;
        sf::Event event;
       
        if(!buffer.loadFromFile("alarmClock.ogg"))
                return EXIT_FAILURE;
               
        sound.setBuffer(buffer);
       
        while(window.isOpen()){
                while(window.pollEvent(event)){
                        if(event.type == sf::Event::Closed){
                                window.close();
                        }
                        sound.play();
                }
                //sound.play() <--- doesn't play here
                window.display();
        }
}

3
General / Inputting and calculating integers, BMI calculator
« on: June 30, 2013, 04:54:19 am »
I'm working on a BMI calculator. I want to have the user enter their height and weight in the window and use that to calculate their BMI. So far, I'm using sf::Event::TextEntered, but I don't want the user to be able to enter characters only integers. I'm pretty new to SFML, so I don't know of any way this could be done, couldn't really find anything looking through the doc. Thanks.

#include <SFML/Graphics.hpp>

class BMICalculator {
        private:
                sf::RenderWindow window;
                sf::Font font;
                sf::Text heightText;
                sf::Text weightText;
                sf::Text inputHeight;
                sf::Text inputWeight;
                sf::Event event;
                std::string str;
               
        public:
                void loadWindow();
                bool loadFont();
                void setText();
                void runProgram();
                void inputData();
};

void BMICalculator::loadWindow(){
        const int HEIGHT = 450;
        const int WIDTH = 350;
        window.create(sf::VideoMode(WIDTH, HEIGHT), "BMI Calculator");
}

bool BMICalculator::loadFont(){
        return (font.loadFromFile("FreeMonoOblique.ttf"));
}

void BMICalculator::setText(){
        //Input height message
    heightText.setFont(font);
    heightText.setCharacterSize(30);
    heightText.setPosition(10, 10);
    heightText.setString ("Enter Height:");
    //Input weight message
    weightText.setFont(font);
    weightText.setCharacterSize(30);
    weightText.setPosition(10, 150);
    weightText.setString ("Enter Weight:");
    //height entered
    inputHeight.setFont(font);
    inputHeight.setCharacterSize(30);
    inputHeight.setPosition(10, 50);
}

void BMICalculator::inputData(){
        if(event.type == sf::Event::TextEntered){
                if(event.text.unicode < 128){
                        str += static_cast<char>(event.text.unicode);
                }
        }

}

void BMICalculator::runProgram(){
        while (window.isOpen()){
        while (window.pollEvent(event)){
                        if (event.type == sf::Event::Closed){
                        window.close();
                }
               
                inputData();
                }
               
                inputHeight.setString(str);    
                window.clear();
                window.draw(heightText);
                window.draw(weightText);
                window.draw(inputHeight);
                window.display();
    }
}

int main(){
        BMICalculator bmi;
        bmi.loadWindow();
        if(!bmi.loadFont())
                return EXIT_FAILURE;
               
        bmi.setText();
        bmi.runProgram();
       
    return EXIT_SUCCESS;

}

 

4
General / Making first SFML game, help?
« on: June 02, 2013, 04:35:17 am »
Just recently I started working with SFML, I've mostly just been looking over some youtube tutorials, looking at the documentation and doing simple things like opening images, sounds,  etc. I'm trying to start simple by making a tic-tac-toe game, but I just don't know how I should organize the code. I've only written console programs up until this point so using graphics or even any other library (besides the standard library) is all new to me. So far I have a window with a tic-tac-toe board but when I try to add to the code I feel like its really messy and I'm just sort of throwing it together.  I also have a layout of what I think should be grouped together, like the logic of the game, loading the board and its pieces, how the user interacts with the game. Does anyone have a basic idea or some advice on how to approach getting started on this.

5
General / Re: Got errors building binaries for SFML 2.0
« on: May 18, 2013, 12:00:37 am »
Nevermind, I just needed to run sudo ldconfig. Thanks for the help.

6
General / Re: Got errors building binaries for SFML 2.0
« on: May 17, 2013, 07:04:50 am »
Thank you, that got me up to the linking stage. I'm trying out the sample program on the SFML tutorial, it compiled and appeared to link, but when I ran the exe ./sfml-app I got:
Quote
./sfml-app: error while loading shared libraries: libsfml-graphics.so.2: cannot open shared object file: No such file or directory

7
General / Got errors building binaries for SFML 2.0
« on: May 17, 2013, 01:09:12 am »
I followed this tutorial to download 2.0...
http://onlyakiss.net/2013/04/how-to-install-sfml-2-0-into-ubuntu-12-04/

and I got these errors at step 3:

Quote
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:70 (MESSAGE):
  Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/share/cmake-2.8/Modules/FindJPEG.cmake:31 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  src/SFML/Graphics/CMakeLists.txt:104 (find_package)


Configuring incomplete, errors occurred!

The only thing I can think of is I'm running Ubuntu 10.04 and that tutorial is for 12.04. I have no idea where to go from here, I can't find any tutorials for installing on 10.04. Thanks for the help.

8
General / Re: Compiler errors for SFML sample program
« on: May 13, 2013, 04:05:00 am »
Thank you, looks like that got freeglut installed, but I'm still getting those errors, now it just looks like this:

Quote
graph.cpp: In function ‘int main()’:
graph.cpp:6: error: ‘CircleShape’ is not a member of ‘sf’
graph.cpp:6: error: expected ‘;’ before ‘shape’
graph.cpp:7: error: ‘shape’ was not declared in this scope
graph.cpp:9: error: ‘class sf::RenderWindow’ has no member named ‘isOpen’
graph.cpp:12: error: ‘class sf::RenderWindow’ has no member named ‘pollEvent’
graph.cpp:14: error: ‘class sf::Event’ has no member named ‘type’
graph.cpp:15: error: ‘class sf::RenderWindow’ has no member named ‘close’
graph.cpp:18: error: ‘class sf::RenderWindow’ has no member named ‘clear’
graph.cpp:19: error: ‘class sf::RenderWindow’ has no member named ‘draw’
graph.cpp:20: error: ‘class sf::RenderWindow’ has no member named ‘display’

9
General / Compiler errors for SFML sample program
« on: May 12, 2013, 06:36:12 am »
I'm completely new to SFML or any kind of graphics library. Using Ubuntu 10.04. I followed the tutorial on sfml-dev.org, downloaded SFML using the first option. I did g++ filename.cpp -c to compile and I got:
Quote
In file included from /usr/include/SFML/Window.hpp:40,
                 from /usr/include/SFML/Graphics.hpp:32,
                 from graph.cpp:1:
/usr/include/SFML/Window/OpenGL.hpp:47:23: error: GL/gl.h: No such file or directory
/usr/include/SFML/Window/OpenGL.hpp:48:24: error: GL/glu.h: No such file or directory
graph.cpp: In function ‘int main()’:
graph.cpp:6: error: ‘CircleShape’ is not a member of ‘sf’
graph.cpp:6: error: expected ‘;’ before ‘shape’
graph.cpp:7: error: ‘shape’ was not declared in this scope
graph.cpp:9: error: ‘class sf::RenderWindow’ has no member named ‘isOpen’
graph.cpp:12: error: ‘class sf::RenderWindow’ has no member named ‘pollEvent’
graph.cpp:14: error: ‘class sf::Event’ has no member named ‘type’
graph.cpp:15: error: ‘class sf::RenderWindow’ has no member named ‘close’
graph.cpp:18: error: ‘class sf::RenderWindow’ has no member named ‘clear’
graph.cpp:19: error: ‘class sf::RenderWindow’ has no member named ‘draw’
graph.cpp:20: error: ‘class sf::RenderWindow’ has no member named ‘display’
I have a feeling it might be a simple thing, but I don't know. I appreciate any help, thank you.

Pages: [1]
anything