iMiniB3D Tween Code driving me mad
BlitzMax Forums/MiniB3D Module/iMiniB3D Tween Code driving me mad
| ||
*** C++ Typo *** Please delete this post, Sorry, Rob Last edited 2012 |
| ||
In that case I have to delete my advice, which was really just guesswork. Among other things I suggested you need 64-bit integers. That means using long long since a C++ long is ( probably ) 32-bit. |
| ||
That was the answer ;-). I will post up the code i came up with in a bit so you can see what i came up with ... |
| ||
Wait... iminiB3D supports tweening? I must have missed something. |
| ||
Sorry, Tweening is probably the wrong word. I was trying to get a constant movement rate e.g. If 60 frames per second, move object by 0.5, if 30 frames per second, move by 1 etc: Anyway, this seems to work ok, but any improvements would be most welcome... ... // Number of frames expected per second const int FPS=30; double nLastTime; double nLastTime = [[NSDate date] timeIntervalSince1970]; float playermove=2.0f i ... Then called before Update and Render in RUN... void Game::UpdateGame(){ double currTime = [[NSDate date] timeIntervalSince1970]; float timeThisSecond = (float)(currTime - nLastTime); nLastTime = currTime; float nMove = (float)((timeThisSecond * 1000) / FPS); mesh->TurnEntity(nMove * playermove,0,0); } Last edited 2012 |
| ||
Ok, so my main issue is that on the iPhone, Milliseconds are stored as a double. E.g, 1500 Milliseconds is 1.5 on the iPhone, 1.0f is 1 second. If any interest, here is my code for "Time Based Movement" and "Frames Per Second" .h: double nLastTime; double m_FPS_lastSecondStart; int m_FPS_FramesThisSecond; int m_FPS; const int nFPS = 30; .mm: void Game::UpdateFPS() { double currTime = [[NSDate date] timeIntervalSince1970]; m_FPS_FramesThisSecond++; float timeThisSecond = currTime - m_FPS_lastSecondStart; if(timeThisSecond > 1.0f ) { m_FPS = m_FPS_FramesThisSecond; m_FPS_FramesThisSecond = 0; m_FPS_lastSecondStart = currTime; // m_FPS now contains Frames Per Second } } void Game::UpdateGame(){ double currTime = [[NSDate date] timeIntervalSince1970]; float timeThisSecond = currTime - nLastTime; nLastTime = currTime; // Example Move Player float nMove = ((timeThisSecond / nFPS) * 1000); mesh->TurnEntity(nMove * playermove,0,0); } Last edited 2012 |
| ||
There is a Millisecs() commands in iminib3d. |
| ||
lol, awesome, thanks:long currTime = Millisecs(); m_FPS_FramesThisSecond++; long timeThisSecond = currTime - m_lasttime; if(timeThisSecond > 1000 ) { m_FPS = m_FPS_FramesThisSecond; m_FPS_FramesThisSecond = 0; m_lasttime = currTime; tmp->ChangeText(ToString(m_FPS)); } .... long currTime = Millisecs(); float timeThisSecond = currTime - lastTimeLong; lastTimeLong = currTime; float nMove = playermove * (timeThisSecond / nFPS); mesh->TurnEntity(nMove,0,0); Last edited 2012 |