KWEngine Part 06: HUD and light objects creation - KWEngine/KWEngine2 Wiki

HUD and light objects may be created from within your GameObjects' or your World's Act() or Prepare() methods. Most likely, you will start creating them in your World's Prepare() method:

Create a HUD object

A HUDObject instance may be 'text' or 'image':

Creating a HUD object with text:

public override void Prepare()
{
    // On creation, you need to choose between showing text or an image (first parameter).
    // The second and third parameter are the x and y offsets for your screen:
    //     x = 24 => the object is shifted 24 pixels from the left
    //     y = 24 => the object is shifted 24 pixels from the top
    HUDObject h = new HUDObject(HUDObjectType.Text, 24, 24);
    h.Name = "My example HUD object";
    h.CharacterSpreadFactor = 26f; // Number of pixels between each letter
    h.SetText("Hello World.");
    h.SetColor(1f, 1f, 0f); // display in yellow color
    AddHUDObject(h);
}

Creating a HUD object with an image:

public override void Prepare()
{
    HUDObject h = new HUDObject(HUDObjectType.Image, 128, 128);
    h.Name = "My example HUD object";
    h.SetTexture(@".\textures\hudTexture.png");
    h.SetScale(256, 256); // 256 pixels wide and 256 pixels tall
    AddHUDObject(h);
}

Let a HUD object check if the mouse cursor is inside its hitbox:

public override void Act(KeyboardState kb, MouseState ms)
{
    HUDObject ho = GetHUDObjectByName("My example HUD object");
    if(ho != null)
    {
        if(ho.IsMouseCursorOnMe(ms) == true)
        {
            ho.SetGlow(1f, 0f, 0f, 1f); // let the object glow
        }
        else
        {
            ho.SetGlow(1f, 0f, 0f, 0f); // set glow intensity back to 0f
        }
    }
}

Create a light object

KWEngine's LightObject class can be instantiated directly.

In order to use a light object in your world, you need to create a sub

Instantiate the class and add it to your world:

public override void Prepare()
{
    LightObject l = new LightObject(LightType.Point);
    l.Name = "My first light";

    // objects need to be at least 1f away to cast a shadow from this light. 
    // the second parameter controls the light's intensity (light falloff)
    l.SetNearAndFarBounds(1f, 5f);

    l.SetColor(0f, 1f, 0f, 1f);  // red, green, blue (0f to 1f) and intensity (0.0f to 1024f)
    l.SetPosition(0f, 3f, 0f);

    AddLightObject(l);
}

Important:

_You may use up to 10 dynamic lights simultaneously.