トップページ > 過去ログ > 記事閲覧
exeファイルとビルド
名前:TXG 日時: 2010/05/31 22:23

この間当たり判定で質問させて頂いたものですがvisual studio 2010で下記のソースをビルドするとちゃんと動くのですが、できたexeファイルを実行してもfpsが表示されるだけで弾も自機も表示されなくて調べても原因が分からなかったので質問させて頂きました。ソースは下記のものです #include <DxLib.h> #include <math.h> int count = 0; typedef struct{ float x,y; int direction,speed; int img ; } ch_t , aodama ; void fps(){ int i; static int t=0,ave=0,f[60]; f[count%60]=GetNowCount()-t; t=GetNowCount(); if(count%60==59){ ave=0; for(i=0;i<60;i++) ave+=f[i]; ave/=60; } if(ave!=0){ DrawFormatString(550, 450,GetColor(255,255,255),"%.1fFPS",1000.0/(double)ave); } return; } inline RECT GetRect( int x1, int y1, int x2, int y2 ) { RECT rc; rc.left = x1; rc.top = y1; rc.right = x2; rc.bottom = y2; return rc; } inline bool HitCheckRect( const RECT& r1, const RECT& r2 ) { return ((r1.left <= r2.right) && (r2.left < r1.right) && (r1.top <= r2.bottom) && (r2.top < r1.bottom)); } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){ char Key[256]; aodama aodama[300]; int hayasa = 3; int num = 0,x,y; if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1; float fsin[360],fcos[360]; int i; for(i=0;i<360;i++) { fsin[i]=(float)sin(i*3.1415926535/180); fcos[i]=(float)cos(i*3.1415926535/180); } for(i=0;i<100;i++) { aodama[i].direction=-1; } SetDrawScreen( DX_SCREEN_BACK ) ; int GrHandle ; GrHandle = LoadGraph( "aodama.bmp" ) ; ChangeWindowMode( TRUE ) ; if( DxLib_Init() == -1 ) return -1 ; int image; ch_t ch; image = LoadGraph( "ziki.png" ) ; ch.x =320; ch.y =440; DrawGraph( 0 , 0 , image , FALSE ) ; int ziki_w, ziki_h, aodama_w, aodama_h; GetGraphSize( image, &ziki_w, &ziki_h ); GetGraphSize( GrHandle, &aodama_w, &aodama_h ); while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){ { hayasa=+1; if( Key[ KEY_INPUT_RIGHT ] == 1 ) ch.x++ ; if(ch.x>590.0) ch.x=590.0; {if( Key[ KEY_INPUT_LEFT ] == 1 ) ch.x-- ; {if(ch.x<10.0) ch.x=10.0; } } if( Key[ KEY_INPUT_UP ] == 1 ) ch.y-- ; if(ch.y<15.0) ch.y=15.0; if( Key[ KEY_INPUT_DOWN ] == 1 ) ch.y++ ; if(ch.y>420.0) ch.y=420.0; ch.img=image; DrawGraph( ch.x , ch.y , ch.img , TRUE ) ; } for(i=0;i<100;i++) { if(aodama[i].direction==-1) { aodama[i].direction=num; aodama[i].x=320; aodama[i].y=0; aodama[i].speed=hayasa; num+=17; num%=360; hayasa +=3; hayasa %=10; if(hayasa==0) { hayasa= 2; } } else { aodama[i].x += (fcos[aodama[i].direction]) * (float)aodama[i].speed; aodama[i].y += (fsin[aodama[i].direction]) * (float)aodama[i].speed; if(aodama[i].x>639||aodama[i].x<0||aodama[i].y>479||aodama[i].y<0) { aodama[i].direction=-1; } } if(aodama[i].direction>-1) { x=(int)aodama[i].x; y=(int)aodama[i].y; DrawGraph( x , y , GrHandle , TRUE ) ; } } for ( i = 0; i < 100; i++ ) { if ( aodama[i].direction == -1 ) continue; if ( HitCheckRect( GetRect( (int)ch.x, (int)ch.y, (int)ch.x + ziki_w, (int)ch.y + ziki_h ), GetRect( (int)aodama[i].x, (int)aodama[i].y, (int)aodama[i].x + aodama_w, (int)aodama[i].y + aodama_h ) ) ) { WaitKey(); return 0; } } fps(); count++; ScreenFlip(); } WaitKey(); DxLib_End(); return 0; } もう一度言いますとビルドは普通にできますが、その時できたexeで起動するとfpsだけしか表示されないのです。

Page: 1 |

Re: exeファイルとビルド ( No.1 )
名前:T 日時:2010/05/31 22:29

Release(またはDebug)フォルダの中でexeを起動していませんか? いったんひとつ上のフォルダへコピーして実行してみてください VC++の"開始"はプロジェクトのフォルダからファイルを参照しますがexeからの起動ですとexeのあるフォルダしか参照しないためにそのようなことが起こります
Re: exeファイルとビルド ( No.2 )
名前:TXG 日時:2010/05/31 22:36

Debugの中でしてしまっていました。 てっきりソースの方に問題があるのかと思いここで質問させて頂きましたがDxlibraryが関係なく板違いになってしまいましたね・・・申し訳ありませんでした。 Tさん迅速で丁寧な解答ありがとうございました!
Re: exeファイルとビルド ( No.3 )
名前:初心者 日時:2010/06/05 11:38

もう少しスマートな記述も可能と思いますが・・・、ミニテクを少々 メインの先頭に以下の記述しておけば・・・"Debug"フォルダ内で起動しても下層フォルダへのアクセスを統一可能です。 ------------------------------------------------ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { static char sSpath[1024]; // 作業変数・起動パス int p; // 作業変数 //======================================================== // [ベースフォルダアジャスト] "Debug"フォルダ内で起動しても下層フォルダへのアクセスを統一する。 GetCurrentDirectory(MAX_PATH, sSpath); for(p=(int)(strlen(sSpath)); p>0 && sSpath[p]!='\\'; p--); p++; // カレントフォルダが"Debug"なら親(一つ上)フォルダへ移動 if(!strcmp("Debug",sSpath+p)) sSpath[p-1] = 0; SetCurrentDirectory(sSpath); //======================================================== // ↓ 以下は貴方のプログラム ・・・ ・・・ ・・・ } ------------------------------------------------

Page: 1 |