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

Pages: 1 [2]
16
Graphics / what is character size?
« on: June 08, 2013, 04:09:17 am »
Is character size the length of a character's height in pixel?

17
SFML projects / Bomberman clone
« on: January 19, 2013, 12:56:38 am »
This is a Bomberman clone that I made.
Jumping right into this kind of advanced game was certainly not a good idea after making only Pong and Snake.... Really this game is buggiest program I've ever made in my life... Anyways, I was getting tired and frustrated so I just want to wrap this project up and finished in hurry.
Unfortunately I do not have a binary version because things started to break when I changed all the resource path to relative path.



18
I see that sf::RectangleShape::setSize() only takes a sf::Vector2f object.
Can you make an overload that takes 2 float arguments?

It's kind of looking ugly in my code to construct a temorary Vector2f

19
General / A crash in my button class
« on: January 02, 2013, 04:08:27 am »
Here's my button class
#include <SFML/Graphics.hpp>
#include <functional>

class Button
{
public:
        static void init(sf::RenderWindow & window);
private:
        static sf::RenderWindow * window;
        sf::Text text;
        std::function<void(void)>  onEnter;
        std::function<void(void)>  onExit;
        std::function<void(void)>  onClick;
public:
        Button(const char * string, sf::Font & font, sf::Color color, sf::Vector2f position, unsigned int size);
        ~Button();
        sf::Text & getText(){return text;}
        void draw();
        void update();
        void connect(std::function<void(void)>  onEnter, std::function<void(void)>  onExit ,std::function<void(void)>  onClick);
};
#include "Button.h"
#include <SFML/Window.hpp>

sf::RenderWindow * Button::window =nullptr;

void Button::init(sf::RenderWindow & window_)
{
        window=&window_;
}

Button::Button(const char * string, sf::Font & font, sf::Color color, sf::Vector2f position, unsigned int size):text(string, font, size)
{
        text.setColor(color);
        text.setPosition(position);
}

Button::~Button()
{
}

void Button::update()
{
        sf::Vector2i mousePos=sf::Mouse::getPosition(*window);
        float x1=text.getGlobalBounds().left;
        float x2=x1+text.getGlobalBounds().width;
        float y1=text.getGlobalBounds().top;
        float y2=y1+text.getGlobalBounds().height;
        if(x1<=mousePos.x && mousePos.x<=x2 && y1<=mousePos.y && mousePos.y<=y2)
        {
                (onEnter)();
                if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
                        (onClick)();
        }
        else
               (onExit)();
}

void Button::connect(std::function<void(void)> onEnter, std::function<void(void)>  onExit,  std::function<void(void)>  onClick)
{
        this->onEnter=onEnter;
        this->onExit=onExit;
        this->onClick=onClick;
}

void Button::draw()
{
        window->draw(text);
}
 

crash occurs in Button::draw() method.
Is there something wrong with my code?

20
SFML projects / SFML Resource Wrapper (Update)
« on: November 10, 2012, 04:18:34 am »
I think someone already put something similar to this, but I wanted to share.
I wrote a simple resource wrapper for sf::Texture, sf::Music, sf::Font and sf::Sound
This does reference counting so that you will never load a same resource twice
Download it here:https://sourceforge.net/projects/kiwongames/files/SFML%20resource%20wrapper/

Update: 1.1
Added FontResource.
Fixed internal design using templates and inheritance. But no change in public interface.

There are 4 Resource classes.
Each of them has a static manager class to manage the resources.
But to make this simple, I made the manager class private, so you don't have any access to the manager class. (The manager's constructor is private too)
  • MusicResource-wrapper for sf::Music
  • SoundResource-wrapper for sf::Sound
  • TextureResource-wrapper for sf::Texture
  • FontResource-wrapper for sf::Font

There are only 2 things you need to know to use these
-constructor
-get()

Constructor
Each resource constructor takes one std::string argument for the name of the resource
ex) MusicResource music("music.wav");

get()
Each resource object has get() method for retrieving your resource
  • TextureResource::get() returns a reference to sf::Sprite. This sprite is binded to a sf::Texture object
  • MusicResource::get() returns a reference to sf::Music.
  • SoundResource::get() returns a reference to sf::Sound. This sound is binded to a sf::SoundBuffer object
  • FontResource::get() returns a reference to sf::Font.

Below is a sample code to show you how easy it is to use Simple Resource Wrapper for SFML

#include "MusicResource.h"
#include "SoundResource.h"
#include "TextureResource.h"


int main()
 {
     // Create the main window
     sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
 
     // Load a sprite to display
        TextureResource texture1("Pretty_Image.png");
        TextureResource texture2("Pretty_Image.png");//This won't load Pretty_Image.png twice.
        texture2.get().setRotation(10); //change rotation

        //Load a third texture to display
        TextureResource texture3("Even_Prettier.png");
        texture3.get().setPosition(100, 100);//change position
 
     // Load a music to play
        MusicResource music("good_music.wav");
        //play the music
        music.get().play();

        //Load a font
        FontResource font("C:/Users/Park/Desktop/Resources/Bedizen.ttf");
        sf::Text text("Hello", font.get());
        sf::Text text2("World", font.get());
        text2.move(400, 0);
 
     while (window.isOpen())
     {
         sf::Event event;
         while (window.pollEvent(event))
         {
             if (event.type == sf::Event::Closed)
                 window.close();
         }
         window.clear();
 
         // Draw the first texture
         window.draw(texture1.get());
         // Draw the second texture
         window.draw(texture2.get());
         // Draw the third texture
          window.draw(texture3.get());
         //draw the texts
         window.draw(text);
         window.draw(text2);
         window.display();
     }
        //load a short sound for finale
        SoundResource sound("Bye_Bye.wav");
       
        //Play the bye bye sound
        sound.get().play();
     return EXIT_SUCCESS;
 }

 

21
Audio / sf::Music trying to solve non-copy problem with "move"
« on: November 09, 2012, 10:54:03 pm »
I'm making a music resource manager class and I'm storing sf::Music in a unordered_map

std::unordered_map<std::string, std::pair<int, sf::Music>> resourceMap;

And it seems that I must use a reference or a smart pointer to store the music because of non-copyable
But instead of using this, I tried to get around with using move constructor...

resourceMap[name]=std::make_pair(1, std::move(sf::Music())); //Create the resource using "move"
                resourceMap[name].second.openFromFile(name); //load the resource
                std::cout<<"Loading "<<name<<" for the first time\n";

But it doesn't work
Errors I get...
1>c:\users\park\desktop\my sdks\include\sfml\system\mutex.hpp(89): error C2248: 'sf::NonCopyable::operator =' : cannot access private member declared in class 'sf::NonCopyable'
1>          c:\users\park\desktop\my sdks\include\sfml\system\noncopyable.hpp(79) : see declaration of 'sf::NonCopyable::operator ='
1>          c:\users\park\desktop\my sdks\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function 'sf::Mutex &sf::Mutex::operator =(const sf::Mutex &)'

22
Graphics / sf::Text throws an exception
« on: October 31, 2012, 03:12:09 am »
I figured that the constructor of sf::Text no longer has Font::getDefaultFont() as its second default argument.
so I just put sf::Text("...", sf::Font()), but this throws an exception.
But when I predefine a font object with its default constructor, it doesn't throw an exception. why?

I also just realized that either way doesn't render any text onto the screen.

 #include <SFML/Graphics.hpp>
 
 int main()
 {

     sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
     
     //Exception
     sf::Text text("Exception thrown because of this->", sf::Font());
     
     //no exception
     //sf::Font font;
     //sf::Text text("Exception not thrown here", font);
 
     while (window.isOpen())
     {
         sf::Event event;
         while (window.pollEvent(event))
         {
             if (event.type == sf::Event::Closed)
                 window.close();
         }
         window.clear();
         window.draw(text);
         window.display();
     }
 
     return EXIT_SUCCESS;
 }
 

23
General / SFML 2.0 with VS 2012
« on: October 29, 2012, 12:38:51 am »
How can I use sfml with vs 2012

24
Window / cannot pass RenderWindow object by const reference
« on: September 05, 2012, 04:29:03 am »
I have a game object that receives reference to RenderWindow object
And this game.draw passes the const reference to window further down to menu object also as a const reference

game.draw(const sf::RenderWindow & r)
{
   menu.draw(r);
}

Using the window reference, menu object draws some stuff.

menu.draw(const sf::RenderWindow & r)
{
    r.draw(/*draw some stuff here*/);
}


when I try to pass the window object by const reference I get an error
"overloads have no legal conversion for 'this' pointer"

Why can't I do this?

25
Window / window title displaying junk
« on: August 23, 2012, 06:20:40 pm »

#pragma comment(lib, "sfml-graphics.lib")
#pragma comment(lib, "sfml-window.lib")
#pragma comment(lib, "sfml-system.lib")
#pragma comment(lib, "sfml-audio.lib")


#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")


#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/Audio.hpp>

int main()
{
    // create the window
        sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Close, sf::ContextSettings());
             

    // load resources, initialize the OpenGL states, ...
        glClearColor (0.0, 0.0, 0.0, 0.0);
        glClear (GL_COLOR_BUFFER_BIT);
        glColor3f (1.0, 1.0, 1.0);
        glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);


    // run the main loop
    bool running = true;
    while (running)
    {
        // handle events
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                // end the program
                running = false;
            }
            else if (event.type == sf::Event::Resized)
            {
                // adjust the viewport when the window is resized
                glViewport(0, 0, event.size.width, event.size.height);
            }
        }

        // clear the buffers
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // draw...
                glBegin(GL_POLYGON);
                        glVertex3f (0.25, 0.25, 0.0);
                        glVertex3f (0.75, 0.25, 0.0);
                        glVertex3f (0.75, 0.75, 0.0);
                        glVertex3f (0.25, 0.75, 0.0);
                glEnd();



        // end the current frame (internally swaps the front and back buffers)
        window.display();
    }

    // release resources...

    return 0;
}

The above code is displaying junk window title, not "OpenGL".
What did I do wrong?
I'm using 2.0

Pages: 1 [2]
anything