load_tiles
and draw
class Animation
def initialize(_AnimFile, x, y, z, tile_width, tile_height, loop, anim_index_delta=1.0)
@x = x
@y = y
@z = z
@AnimStrip = Gosu::Image.load_tiles(_AnimFile,tile_width,tile_height)
@AnimIndex = 0
# 1.0 is full speed
# 0.5 is half speed
# 2.0 is double speed
@AnimIndexDelta = anim_index_delta
@loop = loop
end
def update
@AnimIndex += @AnimIndexDelta
if @loop
@AnimIndex = @AnimIndex % @AnimStrip.length
else
last_index = @AnimStrip.length-1
@AnimIndex = last_index if @AnimIndex > last_index
end
end
def draw
@AnimStrip[@AnimIndex].draw(@x, @y, @z)
end
end
%
, for example modulus 12 works like a 12 hour clock. Try to start up IRB and enter: 16 % 12
# => 4
@lower_case
for variables and instance variables. UpperCase
is only used for constants in Ruby.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill