Game Development Reference
In-Depth Information
Mapping coordinates
Once we have a view attached to a window, we can call RenderWin-
dow::mapPixelToCoords() with a position from the window, and this transforms the
position vector to a location in the scene (world coordinates). Here is an example of how to
convert mouse coordinates to world coordinates in a button press event:
It is important to remember that the function will only work with View , which is currently
applied to the window. This needs to be taken into consideration if we are using multiple
views for our window.
We can also go the other way around—get the screen coordinate from a location in the
scene. This is done by RenderWindow::mapCoordsToPixel() . This is useful when
we want to map a location from a scene to other views. For example, if we want to display
a health bar over characters, we get their location in scene, map the location to a screen
pixel, then map that pixel to our UI view coordinates, and display a health bar there. This
keeps everything nice and organized without much effort.
This covers the topic of views . The next part of the chapter will cover OpenGL code in-
tegration inside SFML.
Search WWH ::




Custom Search