PDA

View Full Version : Setting Bounds for the Player Character



rtr_18
02-15-2012, 03:01 PM
Hi!
I've used the following line of code to restrict the player character with in the top of my window:



if(m_pPos2d->y <= 0) m_pPos2d->y = 1;


This works fine. But to restrict it with in the bottom of the window, I'm using this:



if(m_pPos2d->y >= GetScreenSizeYf()) m_pPos2d->y = GetScreenSizeYf();


But this is not working. What else to do to control it with in the bottom of the window?

Aki Koskinen
02-15-2012, 05:27 PM
You need to account for the height of the player too. Something like:


if (m_pPos2d->y >= GetScreenSizeYf() - m_pSize2d.y) m_pPos2d->y = GetScreenSizeYf() - m_pSize2d.y;

rtr_18
02-16-2012, 07:52 AM
You need to account for the height of the player too. Something like:


if (m_pPos2d->y >= GetScreenSizeYf() - m_pSize2d.y) m_pPos2d->y = GetScreenSizeYf() - m_pSize2d.y;

Thanks a lot. It's working now. I've one more doubt. Can you tell me the steps to programmatically improve the FPS for a 2D game?

Aki Koskinen
02-18-2012, 07:17 AM
Can you tell me the steps to programmatically improve the FPS for a 2D game?

There's no simple answer to this. It completely depends on your game and how it's implemented. Use a profiler and see where the time is going. Then optimize the parts that's taking the most time. Or choose better algorithms. Or cheat where's it's appropriate :whistling: