Okay In a recent CMS i made i would like to have the sprite animated.
Trick gave me this script;
I have tried to mae the sprite show by using;
Sprite_ActorCharGraphic($game_actors[1], 10, 10, 4, 0, 'down')
I get this error when opening the CMS or with trying the code in other scenes.
http://img139.imageshack.us/img139/3965/erroruk9.png[/IMG]
BTW, Sorry for the bother on Mirc Trickster
Trick gave me this script;
Code:
#==============================================================================
# ** Sprite_ActorCharGraphic (BETA) By Trickster
#-----------------------------------------------------------------------------
# A Sprite Class that represents an actor character graphic. Also Handles a few
# Graphical methods and animation. The Z coordinate is, by default,
# in between the window and its contents for easy integration in a window.
#==============================================================================
class Sprite_ActorCharGraphic < Sprite
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :speed
attr_reader :frame
attr_reader :pose
# Pose Names
POSES = ['down','left','right','up']
# Number of Frames Per Pose
FRAMES = 4
#-------------------------------------------------------------------------
# * Name: Object Initialization
# Info: Creates a New Instance of this Class
# Author: Trickster
# Call Info: Three or Seven Arguments
# Game_Actor actor, Actor's Sprite to Display
# Integer X and Y, Position to Display
# Integer Speed, Speed of animation (Def 1)
# Integer Frame, Starting frame (Def. nil)
# String/Integer Pose, Pose Type/Pose Index (Def. nil)
# Viewport viewport, Viewport used (Def. nil)
#-------------------------------------------------------------------------
def initialize(actor, x, y, speed = 1, frame = nil, pose = nil, viewport = nil)
super(viewport)
@actor = actor
self.x = x
self.y = y
self.z = 101
self.speed = speed
self.bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
@name, @hue, @animate = @actor.character_name, @actor.character_hue, false
pose = POSES.index(pose) if pose.is_a?(String)
self.pose, self.frame = pose, frame
@count = 0
end
#-------------------------------------------------------------------------
# * Name: Set Graphic
# Info: Sets Graphic to (Frame, Pose)
# Author: Trickster
# Call Info: Two Arguments
# Integer Frame, Frame
# String/Integer Pose, Pose Type/Pose Index
#-------------------------------------------------------------------------
def set_graphic(pose,frame)
pose = POSES.index(pose) if pose.is_a?(String)
return if @pose == pose and @frame == frame
self.src_rect.x = self.bitmap.width / FRAMES * frame
self.src_rect.y = self.bitmap.height / POSES.size * pose
self.src_rect.width = self.bitmap.width / FRAMES
self.src_rect.height = self.bitmap.height / POSES.size
@pose, @frame = pose, frame
end
#-------------------------------------------------------------------------
# * Name: Set Pose
# Info: Sets The Pose
# Author: Trickster
# Call Info: One Argument, String/Integer Pose Pose Type/Pose Index
#-------------------------------------------------------------------------
def pose=(pose)
pose = POSES.index(pose) if pose.is_a?(String)
return if pose == nil or pose == @pose
self.src_rect.y = self.bitmap.height / POSES.size * pose
self.src_rect.height = self.bitmap.height / POSES.size
@pose = pose
end
#-------------------------------------------------------------------------
# * Name: Set Frame
# Info: Sets the Frame
# Author: Trickster
# Call Info: One Argument, Integer Frame, Frame to set
#-------------------------------------------------------------------------
def frame=(frame)
return if frame == nil or frame == @frame
self.src_rect.x = self.bitmap.width / FRAMES * frame
self.src_rect.width = self.bitmap.width / FRAMES
@frame = frame
end
#-------------------------------------------------------------------------
# * Name: Set Animate
# Info: Set Animation flag
# Author: Trickster
# Call Info: One Argument, Boolean bool, True (On) False (Off)
#-------------------------------------------------------------------------
def animate=(bool)
@animate = bool
end
#-------------------------------------------------------------------------
# * Name: Frame Update
# Info: Update Animation if enabled, Updates Graphic
# Author: Trickster
# Call Info: No Arguments
#-------------------------------------------------------------------------
def update
super
update_graphic
return if not @animate or [@pose, @frame].include?(nil)
@count += 1
return if @count % @speed != 0
self.frame = (self.frame + 1) % FRAMES
end
#-------------------------------------------------------------------------
# * Name: Update Graphic (Private)
# Info: Private Method, Updates Actor Graphic
# Author: Trickster
# Call Info: No Arguements, can not be called outside this class
#-------------------------------------------------------------------------
private
def update_graphic
if @name != @actor.character_name or @hue != @actor.character_hue
self.bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
@name, @hue = @actor.character_name, @actor.character_hue
end
end
end
I have tried to mae the sprite show by using;
Sprite_ActorCharGraphic($game_actors[1], 10, 10, 4, 0, 'down')
I get this error when opening the CMS or with trying the code in other scenes.
http://img139.imageshack.us/img139/3965/erroruk9.png[/IMG]
BTW, Sorry for the bother on Mirc Trickster