Quote:Look this:
http://mateusvitali.wordpress.com/2010/09/29/menu-2/
Thanks guys :D
Whoa! Excellent!
I want your menu code!
If it's possible, of course ;)
Quote:Look this:
http://mateusvitali.wordpress.com/2010/09/29/menu-2/
Thanks guys :D
class MenuState : public IGameScreen{public: MenuState() { } ~MenuState(); void Initialize(IDirect3DDevice9 *pDevice); void Unload(); void Update(); void Draw();private: Sprite2D* background; Sprite2D* cursor; Sprite2D* options; Font* text; POINT absCursor; //Position of Mouse in Screen // Pointer to the internal device IDirect3DDevice9* m_pDevice;};
//adjusts the coordinates of X, according to the new screen resolutionfloat posX(float x_old){ float new_x; new_x = ( x_old * WIDTH ) / 1024; return new_x;}//adjusts the coordinates of Y, according to the new screen resolutionfloat posY(float y_old){ float new_y; new_y = ( y_old * HEIGHT ) / 768; return new_y;} RECT option_online = { 0, 0, 290.0f, 50.0f}, option_offline = { 0, 135.0f, 290.0f, 50.0f}, option_tutorial = { 550.0f, 0, 290.0f, 50.0f}, option_options = { 550.0f, 135.0f, 290.0f, 50.0f}, option_exit = { 550.0f, 185.0f, 290.0f, 120.0f}, change_option = { 0.0f, 0.0f, 0.0f, 0.0f}, rect_void = { 0.0f, 0.0f, 0.0f, 0.0f};MenuState::~MenuState(){ Unload();}void MenuState::Initialize(IDirect3DDevice9 *pDevice){ m_pDevice = pDevice; //Background of Menu background = new Sprite2D(); background->load(m_pDevice, "Data\\Screens\\menu.png",D3DCOLOR_XRGB(255,0,255)); background->setPosition(0,0); //Crosshair (Sprite of MouseCursor) cursor = new Sprite2D(); cursor->load(m_pDevice, "Data\\Sprites\\crosshair.png",D3DCOLOR_XRGB(255,0,255)); //Rect of options options = new Sprite2D(); options->load(m_pDevice, "Data\\Screens\\menu_.png",D3DCOLOR_XRGB(255,0,255)); //Text text = new Font(); text->init(m_pDevice, 15, "Arial");}void MenuState::Unload(){ //Destroy the sprites if( background != NULL) { delete background; background = NULL; } if( cursor != NULL) { delete cursor; cursor = NULL; } if( options != NULL) { delete options; options = NULL; } //Destroy the text manager if( text != NULL) { delete text; text = NULL; } }void MenuState::Update(){ GetCursorPos(&absCursor); cursor->setPosition(absCursor.x, absCursor.y); //If choice Online Game if(absCursor.x >= posX(60.0f) && absCursor.x <= posX(280.0f) && absCursor.y >= posY(355.0f) && absCursor.y <= posY(380.0f)) { change_option = option_online; options->setPosition(posX(72.0f), posY(354.0f)); } //If choice Offline Game else if(absCursor.x >= posX(60.0f) && absCursor.x <= posX(290.0f) && absCursor.y >= posY(427.0f) && absCursor.y <= posY(453.0f)) { change_option = option_offline; options->setPosition(posX(72.0f), posY(489.0f)); } //If choice Tutorial else if(absCursor.x >= posX(60.0f) && absCursor.x <= posX(215.0f) && absCursor.y >= posY(500.0f) && absCursor.y <= posY(525.0f)) { change_option = option_tutorial; options->setPosition(posX(324.0f), posY(498.0f)); } //If choice Options else if(absCursor.x >= posX(60.0f) && absCursor.x <= posX(195.0f) && absCursor.y >= posY(572.0f) && absCursor.y <= posY(597.0f)) { change_option = option_options; options->setPosition(posX(324.0f), posY(633.0f)); } //If choice Exit else if(absCursor.x >= posX(60.0f) && absCursor.x <= posX(134.0f) && absCursor.y >= posY(644.0f) && absCursor.y <= posY(669.0f)) { change_option = option_exit; options->setPosition(posX(324.0f), posY(683.0f)); } else change_option = rect_void;}void MenuState::Draw(){ //Render the background background->render(true, m_pDevice, D3DCOLOR_ARGB(255,255,255,255)); //Render the options options->render2(m_pDevice, change_option, D3DCOLOR_ARGB(255,255,255,255)); //Render the cursor cursor->render(false, m_pDevice, D3DCOLOR_ARGB(255,255,255,255)); //Show the position of Cursor std::stringstream caption_; float x = posX(60); float y = posY(60); caption_ << "X: " << absCursor.x << " Y: " << absCursor.y << std::endl; text->draw(caption_.str().c_str(), 3, 3, D3DCOLOR_ARGB(255,50,205,50));}
void IntroState::Update(){ float seg = GameTime->get_ticks()/1000; //Transition of QI_logo (alpha) if(seg >= 0.0f && seg <= 3.0f) alpha += 4; else if(seg > 3.0f && seg < 4.0f) alpha = 255; else if(seg > 4.0f && seg <= 9.0f) alpha -= 2; //Transition of Background_Intro if(seg > 9.0f && seg <= 12.0f) alpha += 5; else if(seg > 12.0f) alpha = 255;}
void IntroState::Draw(){ if(seg <= 9.0f) qi_logo->render(true, m_pDevice, D3DCOLOR_ARGB(alpha,255,255,255)); else { background->render(true, m_pDevice, D3DCOLOR_ARGB(alpha,255,255,255)); intro_text->draw("Press ENTER to continue", posX(400), posY(580), D3DCOLOR_ARGB(255,255,255,255)); }}
int GameTime::get_ticks(void){ return GetTickCount() - m_start; //m_start => the start time of the game}
float dA = 0.05f;
#define FADE_IN (+1)#define FADE_OUT (+2)#define FADE_TECHNIQUE FADE_IN
static float alphaVal = FADE_TECHNIQUE - 1;
alphaVal -= pow (-1.0f, FADE_TECHNIQUE) * dA;
D3DXCOLOR alphaMultiplier (alphaVal, alphaVal, alphaVal, alphaVal);yourD3DXSprite->Draw (yourSpriteTexture, NULL, NULL, NULL, alphaMultiplier);