-- object_anim_control - Animation Control behavior -- (component of behavior_lib_1) -- Template attachment: any -- Created by: Patrick Ferland -- Created on: 10/29/2008 -- Revision History -- 10/29/2008 P.Ferland - New script -- Listens for these triggers: -- enter -- param_changed -- Broadcasts these triggers: -- no broadcast -- Constants ANIM_CONTROL_SCRIPT = '12071:51' DIRECTIONS = { forward = 0, backward = 1, } -- Script properties Define Properties() script_description = "Animation Control" script_long_description = "This behavior allows you to control the animations applied to objects." anim_style = 'loop' PersistProperty('anim_style') ExposeProperty('anim_style', 'Animation Style', 'list') anim_style_list = {'loop', 'play_once', 'ping_pong'} anim_dir = 'forward' PersistProperty('anim_dir') ExposeProperty('anim_dir', 'Animation Direction', 'list') anim_dir_list = {'forward', 'backward'} end -- Commands -- no commands -- Triggers -- System trigger: Fired when object enters any place Trigger enter() play_anim(self) end -- OX trigger: Replay animation when this object is configured Trigger param_changed(caller, user_id, script_id, value) if (script_id == ANIM_CONTROL_SCRIPT) then play_anim(self) end end -- Local functions -- Animate the object based on the current settings function play_anim(self) local sprite_id, frames, anim_time = get_sprite_info(self) local dir = DIRECTIONS[self.anim_dir] local status = string.format('animatifying %s: %d -> %d (%d) %s (%d ms)', self.name, 1, frames, dir, self.anim_style, anim_time) Debug(status) PlaySpriteAnim(self, 1, frames, dir, self.anim_style, anim_time) end -- Get sprite ID, number of frames, and total animation time for current sprite function get_sprite_info(self) local sprite_id = self.spriteId local sprite = stylesheet.sprites[sprite_id] local frames = sprite.frames local anim_time = sprite.frames * sprite.interval return sprite_id, frames, anim_time end