ID3DXSprite and SetTransform

Started by
12 comments, last by programci_84 13 years, 6 months ago
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 ;)
There's no "hard", and "the impossible" takes just a little time.
Advertisement
I'm using a ScreenManager :D
but my class of menu, this is:

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;};


The Sprite2D and Font are classes created by me for ease of use :)

//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));}
http://mateusvitali.wordpress.com/
Can someone help me with the transition from screen?
alpha was increasing and then decreasing (fade-in and fade-out)

I tried it, most did not work:
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));	}}


Function of GameTime:
int GameTime::get_ticks(void){	return GetTickCount() - m_start; //m_start => the start time of the game}


[Edited by - VitaliBR on September 30, 2010 12:33:21 PM]
http://mateusvitali.wordpress.com/
I'm using a similar approach and works perfectly.

Details:
Declare an increment value:
float dA = 0.05f;


Declare fading technique:
#define FADE_IN (+1)#define FADE_OUT (+2)#define FADE_TECHNIQUE FADE_IN


Declare a float variable for fading start value:
static float alphaVal = FADE_TECHNIQUE - 1;


Add or subtract alphaVal_xx value according to technique (fade-in or out) on each frame:
alphaVal -= pow (-1.0f, FADE_TECHNIQUE) * dA;


Then use that alpha value as a color multiplier:
D3DXCOLOR alphaMultiplier (alphaVal, alphaVal, alphaVal, alphaVal);yourD3DXSprite->Draw (yourSpriteTexture, NULL, NULL, NULL, alphaMultiplier);


Don't forget:
alphaVal can go under zero.
alphaVal can go over one.
You must control'em.

hth.
-R
There's no "hard", and "the impossible" takes just a little time.

This topic is closed to new replies.

Advertisement