MindShake includes support to add layers and cameras, with no limits, you can create as many layers and objects inside layers as you want.
MindShake includes managers for layers and cameras which act as factories, so you can easily create new objects. Later, to easy access to these objects, you can store the reference or give them a name, so you can ask the managers to recover one object with its name.
By default all layers created are configured to adjust to camera renders. If the user want to have a serie of static sprites on the screen, the common way is to put them on a layer that is ignored by camera transformations.
To create a usable sprite layer you need one instance of the scene manager and then invoke the method CreateSpriteLayer.
That is done in this way:
|
<span style="color: green;">//Obtain an instance of scene manager</span> pSceneManager <span style="color: blue;">=</span> IDevice::GetInstance<span style="color: blue;"><b>()</b>-></span>GetSceneManager<span style="color: blue;"><b>(</b></span><span style="color: blue;"><b>);</b></span> <span style="color: green;">//Add and modify a new layer</span> pLayer <span style="color: blue;">=</span> pSceneManager<span style="color: blue;">-></span>CreateSpriteLayer<span style="color: blue;"><b>();</b></span> pLayer<span style="color: blue;">-></span>EnableCameraTransformations<span style="color: blue;"><b>(</b>false<b>);</b></span> |
With this example you see how to create a new sprite layer and modify it to ignore the cameras, so any sprite created into this layer will be shown relative to the upper left corner of the screen.
With the layer created you can now add one or more cameras to view diferent parts of our world.
When we add a new camera it is important to tell it the size and position of the viewport (the region where the camera content will be seen) and the dimensions of the world (the region where this camera can move).
Now you can see one example of scroll.
|
<span style="color: green;">//Obtain an instance of camera manager</span> pCameraManager <span style="color: blue;">=</span> IDevice::GetInstance<span style="color: blue;"><b>()</b>-></span>GetCameraManager<b><span style="color: blue;">()</span><span style="color: blue;">;</span></b> <span style="color: green;">//Add and modify a new camera</span> pCamera <span style="color: blue;">=</span> pCameraManager<span style="color: blue;">-></span>CreateCamera2D<b><span style="color: blue;">();</span></b> pCamera<span style="color: blue;">-></span>SetViewPort<b><span style="color: blue;">(</span></b>0<span style="color: blue;">,</span> 0<span style="color: blue;">,</span> 320<span style="color: blue;">,</span> 240<b><span style="color: blue;">);</span></b> pCamera<span style="color: blue;">-></span>SetWorld<b style="color: blue;">(</b>0<span style="color: blue;">,</span> 0<span style="color: blue;">,</span> 640<span style="color: blue;">,</span> 480<b><span style="color: blue;">);</span></b> |
If our window have a 320×240 size, with this example you will see a scroll effect when move the camera around the world, because it have double size than camera viewport.
It is easy to create more cameras, you only meed to set the viewports in order to view them correctly, for example you can split the screen with three cameras, two of them at the top and one at the bottom.
|
<span style="color: green;">//Add and modify a new camera (top left)</span> pCameraTopLeft <span style="color: blue;">=</span> pCameraManager<span style="color: blue;">-></span>CreateCamera2D(); pCameraTopLeft<span style="color: blue;">-></span>SetViewPort<b><span style="color: blue;">(</span></b>0<span style="color: blue;">,</span> 0<span style="color: blue;">,</span> 160<span style="color: blue;">,</span> 120<b><span style="color: blue;">); </span></b>pCameraTopLeft<span style="color: blue;">-></span>SetWorld<b style="color: blue;">(</b>0<span style="color: blue;">,</span> 0<span style="color: blue;">,</span> 640<span style="color: blue;">,</span> 480<b><span style="color: blue;">);</span></b> <span style="color: green;">//Add and modify a new camera (top right)</span> pCameraTopRight <span style="color: blue;">=</span> pCameraManager<span style="color: blue;">-></span>CreateCamera2D(); pCameraTopRight<span style="color: blue;">-></span>SetViewPort<b><span style="color: blue;">(</span></b>160<span style="color: blue;">,</span> 0<span style="color: blue;">,</span> 160<span style="color: blue;">,</span> 120<b><span style="color: blue;">); </span></b>pCameraTopRight<span style="color: blue;">-></span>SetWorld<b style="color: blue;">(</b>0<span style="color: blue;">,</span> 0<span style="color: blue;">,</span> 640<span style="color: blue;">,</span> 480<b><span style="color: blue;">);</span></b> <span style="color: green;">//Add and modify a new camera (bottom)</span> pCameraBottom <span style="color: blue;">=</span> pCameraManager<span style="color: blue;">-></span>CreateCamera2D(); pCameraBottom<span style="color: blue;">-></span>SetViewPort<b><span style="color: blue;">(</span></b>0<span style="color: blue;">,</span> 120<span style="color: blue;">,</span> 320<span style="color: blue;">,</span> 120<b><span style="color: blue;">);</span></b> pCameraBottom<span style="color: blue;">-></span>SetWorld<b style="color: blue;">(</b>0<span style="color: blue;">,</span> 0<span style="color: blue;">,</span> 640<span style="color: blue;">,</span> 480<b><span style="color: blue;">);</span></b> |
Now you can move the cameras with the SetPosition method and every viewport will automatically show the camera content.