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:
Image and Sprite management? :?:
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? :?: