Class Light

java.lang.Object
net.risingworld.api.worldelements.GameObject
net.risingworld.api.worldelements.Light

public class Light extends GameObject
Represents a light source.
Example: Spawn bright yellow light above player head
1//Spawn yellow "Point" light with high intensity and a range of 20 blocks
2Light light = new Light(Light.Type.Point, 10000f, 20, 0xFFFF00FF);
3
4//Set position 5 units above player head
5light.setLocalPosition(player.getViewPosition().add(0f, 5f, 0f));
6
7//Add light to player
8player.addGameObject(light);
  • Constructor Details

    • Light

      public Light(Light.Type type)
    • Light

      public Light(Light.Type type, float intensity, float range, int color)
  • Method Details

    • getLightType

      public Light.Type getLightType()
    • getColor

      public int getColor()
      Gets the light color (as rgba int).
      Returns:
      the light color.
    • setColor

      public void setColor(float r, float g, float b, float a)
      Updates the light color.
      Parameters:
      r - the red color component (0-1).
      g - the green color component (0-1).
      b - the blue color component (0-1).
      a - the alpha color component (0-1). Affects the light intensity.
    • setColor

      public void setColor(int color)
      Updates the light color (as rgba int).
      Parameters:
      color - the new rgba color.
      Example: Set red color
      1Light light = new Light(Type.Point);
      2light.setColor(0xFF0000FF);
      3player.addGameObject(light);
    • setIntensity

      public void setIntensity(float intensity)
      Sets the light intensity.
      Parameters:
      intensity - the new light intensity.
    • setRange

      public void setRange(float range)
      Sets the max range for the light source, i.e how far the light is emitted from the light source position.
      Parameters:
      range - the new light range.
    • setRadius

      public void setRadius(float radius)
      Sets the radius of the light source. Not to be confused with the light range!
      Higher values result in less punctual light. You can compare this with the radius of a light bulb.
      Parameters:
      radius - the radius of the light source.
    • setVisibleDistance

      public void setVisibleDistance(float distance)
      Determines how far the light is visible. Set lower values to improve performance.
      Parameters:
      distance - the max visible distance for the light.
    • setSpotAngle

      public void setSpotAngle(float angle)
      Only works for spot lights!
      Sets the outer angle of the spot light in degree (1-179).
      Parameters:
      angle - the spot light angle (degree).
    • setSpotInnerAngle

      public void setSpotInnerAngle(float angle)
      Only works for spot lights!
      Sets the inner angle of the spot light in degree (1-179). Must be less than the outer angle!
      Parameters:
      angle - the inner spot light angle (degree).
    • setVolumetrics

      public void setVolumetrics(boolean set)
      Enables/disables volumetrics for this light. Use with caution due to high performance impact!
      Parameters:
      set - true to enable volumetrics, false to disable it.
    • setVolumetricsIntensity

      public void setVolumetricsIntensity(float intensity)
      If volumetrics are enabled for this light, this determines the intensity.
      Parameters:
      intensity - the volumetric light intensity (0-16).
    • setShadowsEnabled

      public void setShadowsEnabled(boolean set)
      Enables/disables shadows for this light. Warning: Shadows have a big impact on performance!
      Parameters:
      set - true to enable shadows, false to disable them.
    • setShadowsMapResolution

      public void setShadowsMapResolution(int resolution)
      Sets the resolution for the shadow map. The higher the resolution, the sharper the shadows, but also the higher the impact on performance. Please bear in mind that point lights use 6 shadow maps, while spot lights only use 1 shadow map. Recommended values for point lights are usually 64, 128 or 256, while for spot lights, 512 or 1024 can be used.
      Parameters:
      resolution - resolution for the shadow map.
    • setShadowIntensity

      public void setShadowIntensity(float intensity)
      Sets the intensity for the shadows (0-1). 1 is the default value (opaque shadows), 0 results in shadows being invisible. This setting has no impact on performance.
      Parameters:
      intensity - intensity for the shadows from this light source.