Map drawing in scripts

From Spheriki

Jump to: navigation, search

This tutorial looks at ways that the RenderMap() function can be used by you.


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 Earthquake() 
{
  var StartEarthQuakeTime = GetTime();
  var DoneEarthQuake = false; 
  var InputPerson; 
  var CameraPerson; 
  
  if (IsInputAttached()) 
  {
    InputPerson = GetInputPerson();
    DetachInput();
  }
  if (IsCameraAttached()) 
  {
    CameraPerson = GetCameraPerson();
    DetachCamera();
  }
  
  x = GetCameraX();
  y = GetCameraY();
  
  while (!DoneEarthQuake) 
  {
    RenderMap();
    SetCameraX(x + Math.random() * 10 - Math.random() * 5);
    SetCameraY(y + Math.random() * 7 - Math.random() * 4);
    FlipScreen();
    if (GetTime() > 3000 + StartEarthQuakeTime)
      DoneEarthQuake = true;
  }
  
  if (InputPerson) AttachInput(InputPerson);
  if (CameraPerson) AttachCamera(CameraPerson);
}

Ok, this may look complex but all it really does is shake the screen for 3 seconds (or 3000 milliseconds.)


Let's 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 let's 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()); 
// now change the map_image to your liking...  

That should do it for an explanation of this function.


By Flikky (from the Sphere CHM, adapted and updated for the wiki.)

Personal tools