Game Development Reference
In-Depth Information
The presented code guarantees that the Step() method will be called t / TIME_STEP
times for the time value t and that the difference between the physical time and logical time
will be no more than TIME_STEP seconds.
See also…
F Chapter 8 , Writing a Match-3 Game
Rendering graphics in 2D
To render a 2D scene, we use the wireframe mode. This requires only the Line2D()
procedure to be implemented with the following prototype:
Line2D(int x1, int y1, int x2, int y2, int color);
Getting ready
This can be a simple implementation of the Bresenham's algorithm ( http://
en.wikipedia.org/wiki/Bresenham's_line_algorithm ) and we do not present code
here in the topic to save space. See the accompanying Rendering.h and Rendering.cpp
iles for App4 . The topic's supplementary materials can be downloaded from
www.packtpub.com/support .
How to do it…
1.
To transform the objects from the simulated physical world to the screen in a 2D
environment of the Box2D library, we have to set up a coordinate transform:
[x, y] [X_screen, Y_screen]
2. To do so, we introduce a few coeficients, XScale , YScale , XOfs , YOfs , and two
formulas:
X_screen = x * XScale + XOfs
Y_screen = y * YScale + YOfs
3.
They work as follows:
int XToScreen(float x)
{
return Width / 2 + x * XScale + XOfs;
}
int YToScreen(float y)
{
return Height / 2 - y * YScale + YOfs;
}
 
Search WWH ::




Custom Search