#include "DxLib.h"
void Title();
void Game();
void End();
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 ){
while(ProcessMessage()==0)
{
int phase = 0;
switch(phase)
{
case 0 : Title(); break; // タイトル画面処理
case 1 : Game(); break; // ゲーム画面処理
default : End(); // 終了処理
}
}
}
DxLib_End(); // DXライブラリ終了処理
return 0;
}
int Key[256]; // キーが押されているフレーム数を格納する
// キーの入力状態を更新する
int gpUpdateKey(){
char tmpKey[256]; // 現在のキーの入力状態を格納する
GetHitKeyStateAll( tmpKey ); // 全てのキーの入力状態を得る
for( int i=0; i<256; i++ ){
if( tmpKey[i] != 0 ){ // i番のキーコードに対応するキーが押されていたら
Key[i]++; // 加算
} else { // 押されていなければ
Key[i] = 0; // 0にする
}
}
return 0;
}
typedef struct{
int x, y; // 座標格納用変数
char name[128]; // 項目名格納用変数
}MenuElement_t;
void Title()
{
int y =240;
int Handle; // データハンドル格納用変数
int SelectNum = 0; // 現在の選択番号
Handle = LoadGraph( "画像\\Title.png" ); // 画像をロード
DrawGraph( 0, 0, Handle, TRUE ); // データハンドルを使って画像を描画
MenuElement_t MenuElement[4]={ // メニュー項目要素
{ 80, 100, "ゲームスタート" },
{ 100, 150, "タイムアタック" },
{ 100, 200, "設定" },
{ 100, 250, "ゲーム終了" },
};
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 && gpUpdateKey()==0 ){
// 計算フェーズ
if( Key[ KEY_INPUT_DOWN ] == 1 ){
SelectNum = ( SelectNum + 1 ) % 4;
}
if( Key[ KEY_INPUT_UP ] == 1 ){
SelectNum = ( SelectNum + 3 ) % 4;
}
if( Key[ KEY_INPUT_DOWN ] == 1 || Key[ KEY_INPUT_UP ] == 1 ){
for( int i=0; i<4; i++ ){
if( i == SelectNum ){
MenuElement[i].x = 80;
} else {
MenuElement[i].x = 100;
}
}
}
// 描画フェーズ
for( int i=0; i<4; i++ ){ // メニュー項目を描画
DrawFormatString( MenuElement[i].x, MenuElement[i].y, GetColor(255,255,255), MenuElement[i].name );
}
}
}
void Game()
{
}
void End()
{
}
結果は画像が一瞬映り、そのあとに文字(メニュー)が表示(このときに画像は消えている)されました。
画像の上にメニュー項目が表示されるようにしたいです。どうしたらよいのでしょうか。
よろしくお願いします。