Shadows

Shadows post thumbnail image

Shadows help give your game depth where applicable and are a vital aid for platforming in a three dimensional world. OpenBOR supports static shadows shadows created from a template shadow sprite and realistic shadows matching the entity’s profile. You may also configure light sources angles to make shadows that dynamically respond to the scenery around them.

Model

Header

Shadow Configuration

shadow_config <arguments>

# Default
shadow_config static_ground static_air

Basic shadow behaviors for an entity. Accepts one or more of the following flags:

  • base_platform – Shadows move to platform like 2D platform style games.
  • base_static – Shadows do not change with platforms.
  • default – Shortcut for default flags.
  • disabled – Shadows are disabled regardless of other flags.
  • replica_air – Project a realistic shadow based on current frame sprite when entity is in the air.
  • replica_ground – Project a realistic shadow based on current frame sprite when entity is on the ground.
  • static_air – Project a static shadow using an indexed sprite when entity is in the air.
  • static_ground – Project a static shadow using an indexed sprite when entity is on the ground.

This example configures the entity to display a realistic shadow on the ground, and a static shadow in the air.

shadow_config replica_ground static_air

Script

Shadow is an integer using the following bitmasks:

  • openborconstant("SHADOW_CONFIG_NONE")
  • openborconstant("SHADOW_CONFIG_DEFAULT")
  • openborconstant("SHADOW_CONFIG_BASE_STATIC")
  • openborconstant("SHADOW_CONFIG_BASE_ALL") – All base bits. Useful for logic checks.
  • openborconstant("SHADOW_CONFIG_BASE_PLATFORM")
  • openborconstant("SHADOW_CONFIG_BASE_PLATFORM")
  • openborconstant("SHADOW_CONFIG_DISABLE")
  • openborconstant("SHADOW_CONFIG_GRAPHIC_REPLICA_AIR")
  • openborconstant("SHADOW_CONFIG_GRAPHIC_REPLICA_GROUND")
  • openborconstant("SHADOW_CONFIG_GRAPHIC_STATIC_AIR")
  • openborconstant("SHADOW_CONFIG_GRAPHIC_STATIC_GROUND")
  • openborconstant("SHADOW_CONFIG_GRAPHIC_ALL") – All graphic bits. Useful for logic checks.

This example gets the entity shadow configuration, sets the flag openborconstant("SHADOW_CONFIG_DISABLE") and then applies it to entity.

int shadow_config = get_entity_property(self, openborconstant("ENTITY_PROPERTY_SHADOW_CONFIG_FLAGS"));
 
shadow_config |= openborconstant("SHADOW_CONFIG_DISABLE");

set_entity_property(self, openborconstant("ENTITY_PROPERTY_SHADOW_CONFIG_FLAGS"), shadow_config);

Shadow Index

shadow <index>

Default shadow template index when using static shadows. Place shadow templates in the sprites folder with the filename shadow<index>.png. For example, shadow1.png is shadow 1, shadow2.png is shadow 2 and so on. 0 = No static shadow.

Script

Shadow index is accessible to script as a model property. This example sets the shadow index to shadow 2.

set_model_property(model, openborconstant("MODEL_PROPERTY_SHADOW_INDEX"), 2);

Alpha Blending

alpha <index>

# Default
alpha 1

Sets type of blending applied to shadows. identical to model alpha.

Animation

Frame Shadow

fshadow <int> or "none"

# Default
fshadow none

Frame command. Enables setting the shadow index on a per frame basis. Identical to Shadow Index other than the following:

  • none = Use the model level Shadow Index.

Levels

Light

light <int x> <int z>

# Default
light 128 64

Controls light source angle in a level for generating replicate shadows. Use in conjunction with at to create levels with dynamic lighting as the player moves about.

  • x – Shadows “lean”. 256 is ~45 degrees.
  • z – Shadow length. 256 is equal to the original sprite length. Negative values flip the shadow toward player’s viewpoint.

Related Post