Class Sprite

Description

The Sprite class is a lua wrapper for LGCK's Sprite object.

It allows direct manipulation of the engine data through the member functions.

Directly modifying member variables in a lua object doesn't modify the engine object however. Please use the appropriate member functions for that.

This is a how to get an instance of the Sprite class in an event handlers.

local sprite = getSprite( self );

Members

  • int x
  • int y
  • int aim
  • int triggerFlag
  • int stateFlag
  • int actionMask
  • int imageSet
  • int imageNo
  • int objType
  • int id
  • string name
  • int class

Sprite:activate

  • in void
  • out void
Activate this sprite. Inactive sprite do not consume their handlers until they are activated. Activation can be automatic or manual via scripting using this function.

local sprite = getSprite(self);
if sprite:isVisible() then
  sprite:activeSprite();
end

Sprite:addItem

  • in int protoID
  • out void

Sprite:attackPlayer

  • in void
  • out void

Sprite:callEvent

  • in int event
  • out void
Call an event handler for this sprite.

local player = getPlayer();
player:callEvent( EO_DEATH );

For complete list of all available events see callObjEvent() for details.


Sprite:canFall

  • in void
  • out bool
This function returns true if the sprite can fall.

local s = getSprite( self );
local tmp = copySprite ( s ); 
 
local fall = 0;
while tmp:canFall() do
  tmp:move( DOWN );
  fall = fall + 1;
end 
 
tmp:clear(); 
 
if fall < 20 then
  playSound("short fall.ogg");
else
  playSound("fall.ogg");
end

Sprite:canMove

  • in int aim
  • out bool

Sprite:changeTo

  • in int objType
  • out void

Sprite:childCount

  • in void
  • out int count
Count the number of children. Typically these are bullets.

Sprite:clear

  • in void
  • out void
local s = getSprite( self );
local tmp = copySprite ( s );
...
tmp:clear();

Sprite:copy

  • in void
  • out Sprite
Create a copy of this sprite.

Sprite:frameCount

  • in void
  • out int
Returns the frame count for the Sprite's active frame set.

Sprite:freeze

  • in void
  • out void

Sprite:get

  • in mixed key
  • out int
Get a sprite property. If the key is a string is it a user-defined property.

The key can also be a constant. The following values are predefined by the engine. The values from 0 to 1000 are considered reserved by the engine.

EXTRA_ORGPROTO
EXTRA_ORGX          
EXTRA_ORGY          
EXTRA_HP            
EXTRA_OLDAIM1     
EXTRA_OLDAIM2     
EXTRA_FALLHEIGHT  
EXTRA_LIVES       
EXTRA_ACTIVE      
EXTRA_BULLETCOUNT 
EXTRA_OWNER       
EXTRA_FLAGS       
EXTRA_PATHDIR     
EXTRA_PATHPTR     
EXTRA_ANIMSEQ     
EXTRA_ANIMPTR     
EXTRA_ANIMSPEED 
EXTRA_DEATHINDICATOR
EXTRA_AGE   
EXTRA_TIMEOUT     
EXTRA_TAGFLAGS 
EXTRA_INVENTORY

Sprite:getExtra

  • in void
  • out Extra

Sprite:getHP

  • in void
  • out int hp
Get the sprite hit points.

Sprite:getProto

  • in void
  • out Proto

Sprite:getString

  • in void
  • out string
Get the hint/description associated with a given sprite

Sprite:hasItem

  • in int protoID
  • out void

Sprite:height

  • in void
  • out int height
Get sprite height (pixels).

Sprite:hide

  • in void
  • out void
Hide the sprite.
local player = getPlayer();
player:hide();
if player:isHidden() then
   Debug:printf("%s is hidden", player.name);
end

Sprite:hitTest

  • in int aim
  • out HitTest
returns a hit test object.

Sprite:isActive

  • in void
  • out bool active
Get the sprite active state. This is set through the activation policy.

Sprite:isDead

  • in void
  • out void
returns true if the sprite is dead !

local player = getPlayer();
killPlayer();
if player:isDead() then
   Debug:printf("player is dead");
end

Sprite:isFrozen

  • in void
  • out bool
Returns true if the sprite is frozen

Sprite:isGoal

  • in void
  • out bool
Returns true is the sprite is marked as a goal.

Sprite:isHidden

  • in void
  • out void
returns true if the sprite is hidden.

local player = getPlayer();
Debug:printf("player id= %d; name: %s", player.id, player.name);
player:hide();
if player:isHidden() then
   Debug:printf("%s is hidden", player.name);
end

Sprite:isMonster

  • in void
  • out bool
Tests if this sprite is a monster.

Sprite:IsPlayer

  • in void
  • out bool
Tests if this sprite is a player object.

Sprite:isPlayerThere

  • in int aim
  • out bool

Sprite:isVisible

  • in void
  • out bool

Sprite:kill

  • in void
  • out void
Kills the sprite. Don't try this inside the sprite's own event handler!!!

local player = getPlayer();
player:kill();
if player:isDead() then
   Debug:printf("`%s` is dead", player.name);
end

Sprite:land

  • in void
  • out void
Calls the default "landing" code for this sprite. This is typically used when an sprite has stopped from a free fall. land() checks if the sprite's maxFall property is exceeded and kills the sprite as appropriate.

Sprite:map

  • in void
  • out void

Sprite:markAsGoal

  • in void
  • out void

Sprite:move

  • in int aim
  • out void
Move the sprite in a given direction; UP, DOWN, LEFT or RIGHT

Sprite:moveBy

  • in int tx
  • in int ty
  • out void

Sprite:moveTo

  • in int x
  • in int y
  • out void

Sprite:objClass

  • in void
  • out int classId

Sprite:objName

  • in void
  • out string name of the object

Sprite:objType

  • in void
  • out int TypeId

Sprite:proto

  • in void
  • out Proto
same as getProto()

Sprite:removeItem

  • in int protoID
  • out void

Sprite:resetInventory

  • in void
  • out void

Sprite:set

  • in mixed key
  • out int
Set a sprite property. If the key is a string is it a user-defined property.

The key can also be a constant. The following values are predefined by the engine. The values from 0 to 1000 are considered reserved by the engine.

EXTRA_ORGPROTO
EXTRA_ORGX          
EXTRA_ORGY          
EXTRA_HP            
EXTRA_OLDAIM1     
EXTRA_OLDAIM2     
EXTRA_FALLHEIGHT  
EXTRA_LIVES       
EXTRA_ACTIVE      
EXTRA_BULLETCOUNT 
EXTRA_OWNER       
EXTRA_FLAGS       
EXTRA_PATHDIR     
EXTRA_PATHPTR     
EXTRA_ANIMSEQ     
EXTRA_ANIMPTR     
EXTRA_ANIMSPEED 
EXTRA_DEATHINDICATOR
EXTRA_AGE   
EXTRA_TIMEOUT     
EXTRA_TAGFLAGS 
EXTRA_INVENTORY

Sprite:setAim

  • in int aim
  • out void

Sprite:setAsGoal

  • in void
  • out void

Sprite:setHP

  • in int hp
  • out void
set the sprite hit points

Sprite:setImage

  • in int imageSet*
  • in int imageNo
  • out void
Change the image of the given sprite.

local sprite = getSprite(self);
sprite:setImage(sprite.imageSet, XOR(sprite.imageNo,1));

in parameter imageSet : optional and can be omitted.


Sprite:setOwner

  • in void
  • out Sprite owner
Set the owner of this sprite

Sprite:setState

  • in int stateFlag
  • in bool flip*
  • out int stateFlag
Change the state flags for this sprite.

if flip is true the bits are set on otherwise they are cleared. Flip is optional and assumed to be true.

State flag is a combination of the following:

STATE_FALL		
    STATE_DEAD	
    STATE_HIT		    
    STATE_JUMP	
    STATE_BEGINNING    
    STATE_FIRING       
    STATE_LOOKUP

Example usage:

local player = getPlayer();
player:setState(STATE_DEAD);

returns the newly modified state flag.

in parameter flip : optional and can be omitted.


Sprite:setTriggerKey

  • in int key
  • out void

Sprite:show

  • in void
  • out void
Show this sprite. This reverses the effect of Sprite:hide().

local player = getPlayer();
if player:isHidden() then
   Debug:printf("%s is hidden", player.name);
end 
player:show();

Sprite:spawn

  • in void
  • out void

Sprite:stopAnimation

  • in void
  • out void
Stop the sprite's animation sequence. see stopAnimation() for details.

local sprite = getSprite( self );
sprite:stopAnimation();

Sprite:testFlags

  • in int mask
  • out bool result

Sprite:togglePathPlayback

  • in bool enable
  • out void
Path playback allows a custom path that is assigned to a sprite to be played used to remotely control this sprite. If enabled, the custom path is utilized. Otherwise, it is ignored.

Sprite:triggerHitState

  • in void
  • out void
Trigger the hit state for this sprite. See triggerHitState() for details.

local player = getPlayer();
player:triggerHitState();

Sprite:tryAnimation

  • in int animSeq
  • out bool
see tryAnimation() for details

Sprite:tryPath

  • in int path
  • in int aim*
  • out bool
Apply a defined path to a sprite. Path can be any PS_XXXX constants. See tryPath() for details.

local player = getPlayer();
player:tryPath(PS_JUMP_LEFT);

in parameter aim : optional and can be omitted.


Sprite:unFreeze

  • in void
  • out void

Sprite:unMap

  • in void
  • out void

Sprite:unmarkAsGoal

  • in void
  • out void
Unset the goal flag on this sprite. Sprites marked as goals are mandatory conditions to completing the level.

Alias: unsetAsGoal


Sprite:unsetAsGoal

  • in void
  • out void
Unset the goal flag on this sprite. Sprites marked as goals are mandatory conditions to completing the level.

Alias: unmarkAsGoal


Sprite:width

  • in void
  • out int width
Get sprite width in pixels.