Today we will look at Sphere's RenderMap() function.
Once you've started the map engine and are walking around in the map, you can start playing around with the render function...
An example of this would be:-
function ClearKeyQueue() {
while(AreKeysLeft()) GetKey();
}
function Earthquake()
{
var StartEarthQuakeTime = GetTime();
var DoneEarthQuake = false;
var InputPerson = "";
var CameraPerson = "";
if(IsInputAttached())
{
InputPerson = GetInputPerson();
DetachInput();
}
if(IsCameraAttached())
{
CameraPerson = GetCameraPerson();
DetachCamera();
}
var x = GetCameraX();
var y = GetCameraY();
while(!DoneEarthQuake)
{
RenderMap();
SetCameraX(x + ( Math.random() * 10) - Math.random() * -5);
SetCameraY(y + ( Math.random() * 7) - Math.random() * -5);
FlipScreen();
if(GetTime() > 3000 + StartEarthQuakeTime) {
DoneEarthQuake = true;
}
}
if(InputPerson != "") {
AttachInput(InputPerson);
}
if(CameraPerson != "") {
AttachCamera(CameraPerson);
}
ClearKeyQueue();
}
Ok, this may look complex but all it really does is shake the screen for 3000 milliseconds...
Lets talk though the main area of focus...
We have a picture of the map that we put into the backbuffer by calling:-
RenderMap();
Now we have the backbuffer filled with the map, we can call the camera functions, in combination with FlipScreen() to make the map move.
And since we are using random x and y variations, it looks like an earthquake.
Enough said about that.
Now lets put this into our game.
Make a trigger on the map, by right clicking and selecting:- Insert Entity > Trigger.
In the trigger box, type:-
Earthquake();
Then press 'Check Syntax' and 'OK'.
And it will then be an earthquake spot.
Remember, RenderMap() fills the backbuffer with the image.
If you wanted to change the way the map looks before showing it on screen, using FlipScreen(), you could do:-
RenderMap();
var map_image = GrabImage(0,0, GetScreenWidth(), GetScreenHeight());
That should do it for an explaination of this function.
You'll notice that the earthquake isn't a very simulated one, but I'll leave that as an exercise for you.
Note that this will appear not to do anything if the map is too small. (Your character will just stop for 3 seconds.)
This is because sphere clips the camera within a certain range, in short, make sure any map that you want to do an earthquake is atleast twice the screen in size.
The trigger should also be atleast half a screen into the map.
Thats its folks, soon, I will cover how to play music in Sphere
|