CのDXlibでアニメーションをしようとしているのですが1キャラは10分割で1周なのですが2キャラ目が8分割で1周で3キャラ目が6分割で1周の画像を同じ速度で回したいときのプログラムを教えてください
1キャラ 0 1 2 3 4 5 6 7 8 9 0 1
2キャラ 0 1 2 3 4 5 6 7 8 0 1 2
3キャラ 0 1 2 3 4 5 6 0 1 2 3 4
これを同じときに0が来るようにしたいです。
分割の違う画像を同じ速度で移動させる
Re: 分割の違う画像を同じ速度で移動させる
こんな感じですか?
#include <DxLib.h>
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
ChangeWindowMode( true );
if( DxLib_Init() == -1 ){ return -1; }
SetDrawScreen( DX_SCREEN_BACK );
int count = 0;
int cycle10 = 0;
int cycle8 = 0;
int cycle6 = 0;
while( ProcessMessage() == 0 && !CheckHitKey( KEY_INPUT_ESCAPE ))
{
ClearDrawScreen();
cycle10 = ( count % 240 ) / 24;//10コマアニメ
cycle8 = ( count % 240 ) / 30;//8コマアニメ
cycle6 = ( count % 240 ) / 40;//6コマアニメ
DrawFormatString( 150, 150, 0xffffff, "%d, %d, %d", cycle10, cycle8, cycle6 );
ScreenFlip();
++count;
}
DxLib_End();
return 0;
}
Re: 分割の違う画像を同じ速度で移動させる
こんな感じでどうでしょう.
const double T = アニメーションの周期(1周に要する時間)
const int nImage = アニメーションの画像枚数(10とか8とか6とか)
double CurrTime = 処理開始から現在までの経過時間
//現在表示すべき画像のindex
// 時間 t = T/nImage が経過するごとに画像indexを1つ進める.
// 現在までにtが何回経過したか = nt = (int)( CurrTime / t )
// 現在表示すべき画像のindex = nt % nImage;
int CurrShowImageIndex = (int)( CurrTime * nImage / T ) % nImage;
Re: 分割の違う画像を同じ速度で移動させる
みなさん 返答ありがとうございます
最終的に
int count = 0; //経過時間
int animacount = 0 ; //アニメーション用のカウント
if((count%数)==0) animacount ++
という感じでやることにしました。
最終的に
int count = 0; //経過時間
int animacount = 0 ; //アニメーション用のカウント
if((count%数)==0) animacount ++
という感じでやることにしました。