ページ 11

タイトルでのポイント画像の移動

Posted: 2010年12月01日(水) 10:09
by 名無し
タイトル画面で選択した物の隣にポインタ画像が移動するようなソースを
プログラムの館を参考に作ったのですがうまく移動しません。
エラーは起きていないのですが どうすれば動くようになるでしょうか

コード:

#include "GV.h"




void title_disp(int x , int y , char title[] , const char **str , int &menu ){

			int z;
			z=115;
	   int num=0;
    int dx=0,len=0;
    const char **str2 = str;

        DrawGraph(  0,  0,img_board[30],FALSE);

		DrawGraph(  420, z,img_board[31],FALSE);
		
		if( CheckStatePad(configpad.up)   == 1 )
		z +=-40;
		if(z==75)
			z=155;

		if( CheckStatePad(configpad.down)   == 1 )
		z+=40;
		if(z==195)
			z=115;
		

		  //タイトル表示
    dx =  x - GetDrawFormatStringWidthToHandle( font[2], title ) /2;
    DrawFormatStringToHandle( dx, y, color[0], font[2], "%s", title );
    y += 50;//改行
  

    //情報の取得
    while ( strcmp( *str2, "NULL" ) != 0 )
    {
        if( len < GetDrawFormatStringWidthToHandle( font[2] , *str2 ) )
        {
            len = GetDrawFormatStringWidthToHandle( font[2] , *str2 );
        }
        ++num;
        *str2++;
    }
    dx =  x - len / 2;

     //選択制御
    if( CheckStatePad(configpad.up)   == 1 && menu > 0 )
        --menu;
		
    else if( CheckStatePad(configpad.up)   == 1 )
        menu = num-1;
		
    if( CheckStatePad(configpad.down) == 1 && menu < num-1 )
        ++menu;
		
    else if( CheckStatePad(configpad.down) == 1 )
        menu = 0;
		
    y += menu * 20;
    SetDrawBlendMode( DX_BLENDMODE_ALPHA , 100 ) ;
    DrawBox( dx-10 , y , dx+10 + len , y + 18 , color[5] , TRUE ) ;    //選択位置の表示
    SetDrawBlendMode( DX_BLENDMODE_NOBLEND , 0 ) ;
    y -= menu * 20;

    //項目の表示
    while ( strcmp( *str, "NULL" ) != 0 )
    {
        dx = x - GetDrawFormatStringWidthToHandle( font[2] , *str ) / 2;
        DrawFormatStringToHandle( dx, y, color[0], font[2], "%s", *str++);
        y += 40;
    }
}

void game_start(){
    // constでデータが書き換わらないようにする
    const char *str[] =
    {
        {"START"},
        {"EXIT"},
        {"NULL"}                // NULL文字列で終了を示す(小文字不可)
    };
    static int menu;

    title_disp( 500 , 60 , " " , str, menu );

    if( CheckStatePad(configpad.shot) == 1 )
    {
        switch(menu)
        {
        case 0:
            func_state = 99;    //メインに戻る
            break;
        case 1:
           DxLib_End();
            break;
        }
       
    }
}


void title_main(){
	
	game_start();

}


Re: タイトルでのポイント画像の移動

Posted: 2010年12月01日(水) 10:46
by ookami
とりあえず、printfデバッグの発想で、

> DrawBox( dx-10 , y , dx+10 + len , y + 18 , color[5] , TRUE ) ; //選択位置の表示
の後に、
DrawFormatString(0,0, GetColor(255,255,255),"%d %d",menu,y);
などして、
期待通りの結果になっているか、
確認してみてはいかがでしょうか。

Re: タイトルでのポイント画像の移動

Posted: 2010年12月02日(木) 10:02
by 名無し
答えを参考にうまく動くようにする事が出来ました。
ありがとうございました