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

Pages: 1 2 [3]
31
Graphics / Sprite is drawn as a rect
« on: August 12, 2010, 04:01:31 pm »
Okay, here are the header and cpp files where Button is used:
Code: [Select]
#include "state_main_menu.hpp"

namespace
{
    // Coordinates of the Buttons (define center point)
    const int button_p1_pos_x(269);
    const int button_p1_pos_y(126);
    const int button_p2_pos_x(309);
    const int button_p2_pos_y(126);
    const int button_opt_pos_x(263);
    const int button_opt_pos_y(173);
    const int button_inst_pos_x(309);
    const int button_inst_pos_y(173);
    const int button_exit_pos_x(389);
    const int button_exit_pos_y(220);
    // Filenames of the Buttons
    const std::string button_p1_filename("media/mainmenu_1pbutton.png");
    const std::string button_p2_filename("media/mainmenu_2pbutton.png");
    const std::string button_opt_filename("media/mainmenu_optionsbutton.png");
    const std::string button_inst_filename("media/mainmenu_instructionsbutton.png");
    const std::string button_exit_filename("media/mainmenu_endgamebutton.png");
}

State_Main_Menu::State_Main_Menu(AppManager& appmanager) :
    State_Base(appmanager)
{
    button_list[0] = Button(button_p1_pos_x, button_p1_pos_y, button_p1_filename);
 //   button_list[1] = Button(button_p2_pos_x, button_p2_pos_y, button_p2_filename);
 //   button_list[2] = Button(button_opt_pos_x, button_opt_pos_y, button_opt_filename);
 //   button_list[3] = Button(button_inst_pos_x, button_inst_pos_y, button_inst_filename);
 //   button_list[4] = Button(button_exit_pos_x, button_exit_pos_y, button_exit_filename);
}

State_Main_Menu::~State_Main_Menu() {}

void State_Main_Menu::update_event()
{
    sf::Event event;
    for (unsigned int n = 0; n < app_manager.event_list.size(); n++)
    {
        event = app_manager.event_list[n];
        if (event.Type == sf::Event::Closed)
            exit_state();
    }
}

void State_Main_Menu::update()
{}

void State_Main_Menu::draw()
{
    for (int n = 0; n<1; n++)
    {
        button_list[n].draw_update(app_manager.render_window);
    }
}


Code: [Select]
#ifndef STATE_MAIN_MENU_HPP_INCLUDED
#define STATE_MAIN_MENU_HPP_INCLUDED

#include "state_base.hpp"

class State_Main_Menu : public State_Base
{
    public:
        State_Main_Menu(AppManager& appmanager);
        ~State_Main_Menu();
        void update_event();
        void update();
        void draw();
    private:
        // ** Button **
        class Button
        {
            public:
                Button();
                Button(int cx, int cy, std::string filename);
                ~Button();
                int center_x;
                int center_y;
                std::string get_image_filename();
                void set_image_filename(std::string new_filename);
                bool is_mouse_over_button(int x, int y);
                void draw_update(sf::RenderWindow* window);
            private:
                int get_x();
                int get_y();
                std::string image_filename;
                sf::Sprite sprite;
                sf::Image image;
        }; // ** Button End **

        Button button_list[5];
};

#endif // STATE_MAIN_MENU_HPP_INCLUDED


Quote
I think your problem is related to what is described at the end of the sprite tutorial.

Image and Sprite management?  :?:

32
Graphics / Sprite is drawn as a rect
« on: August 12, 2010, 01:56:12 pm »
Hi,
I have a problem with SFML 1.6.
I have this image:


Which is loaded and used with a Sprite. But for some reason, the image is not displayed as it is but as a white rect:
http://img64.imageshack.us/img64/7966/screenxe.png

My class:
Code: [Select]
#include "state_main_menu.hpp"

State_Main_Menu::Button::Button() {}

State_Main_Menu::Button::Button(int cx, int cy, std::string filename) :
    center_x(cx),
    center_y(cy),
    image_filename(filename)
{
    image.LoadFromFile(image_filename);
    sprite.SetImage(image);
}

State_Main_Menu::Button::~Button() {}

std::string State_Main_Menu::Button::get_image_filename()
{
    return image_filename;
}

void State_Main_Menu::Button::set_image_filename(std::string new_filename)
{
    image_filename = new_filename;
    image.LoadFromFile(image_filename);
}

bool State_Main_Menu::Button::is_mouse_over_button(int x, int y)
{
    sf::Vector2f pos(sprite.GetPosition());
    sf::Color color(sprite.GetPixel(x-pos.x, y-pos.y));
    return (color.a > 0);
}

int State_Main_Menu::Button::get_x()
{
    return (center_x - image.GetWidth() / 2);
}

int State_Main_Menu::Button::get_y()
{
    return (center_y - image.GetHeight() / 2);
}

void State_Main_Menu::Button::draw_update(sf::RenderWindow* window)
{
    sprite.SetX(get_x());
    sprite.SetY(get_y());
    window->Draw(sprite);
}

33
Graphics / PostFX does not work
« on: July 07, 2010, 05:30:28 pm »
Hi,
I've got a problem when using the GLSL feature.
I have created a test project which shows a random number of red semi-transparent circles and on top of that a Sprite.
http://img580.imageshack.us/img580/8747/screenbw.png

But now I tried to create and use a shader (grayscale) but it doesn't work.
My code: http://wurstinator.pastebin.com/zKk6xaNa (I know it's messy but it is just a test project :)
My shader: http://wurstinator.pastebin.com/b3pWADCd

When I apply the shader the circles are still a bit red:
http://img696.imageshack.us/img696/7233/screenkopie.png

Hope someone can help =(

/edit: I'm using version 1.6

/edit 2: Solved it, seems like the alpha value has to be 1.

Pages: 1 2 [3]
anything