Scrupp 0.2 Manual
Create your own 2D games and applications

This class provides an easy to use interface for animations.

Requirements

  • Class Plugin

Creation

Animation()
Creates and returns a new animation.

Methods

animation:addFrame(image, x, y, width, height, delay)
Adds a new frame to the animation. The image is the source of the frame. It can be either an Image or a string pointing to the image file. The parameters x, y, width and height define the rectangular area of the image which will be used as the frame. The duration of the frame in milliseconds is defined by delay.
animation:addFrames(image, sizex, sizey, width, height, sep, delay)
Adds multiple frames stored in an image at once. The image can be either an Image or a string pointing to the image file. sizex and sizey define the number of frames in the source image in x- and y-direction. sep is the width in pixels of any separator between the frames. The duration of the frames in milliseconds is defined by delay.
animation:getWidth()
Returns the width of the active frame.
animation:getHeight()
Returns the height of the active frame.
animation:getSize()
Returns the width and the height of the active frame.
animation:isTransparent(x, y)
Returns true if the pixel with the coordinates x and y in the active frame is transparent, false otherwise.
animation:copy()
Creates and returns a copy of the animation. This is useful when the same animation is used multiple times in parallel. By using a copy every animation has its own timing.
animation:start()
Starts the animation.
animation:stop()
Stops the animation
animation:render(x, y, delta)
Renders the animation at the point defined by x and y. delta is the time in milliseconds passed since the last rendering. Usually this is exactly the delta passed to the render callback by Scrupp. See the example for clarification.

Example

scrupp.init("Animation Test", 600, 400, 32, false)

-- load required plugins
scrupp.addFile("scripts/class.lua")
scrupp.addFile("scripts/animation.lua")

local animation = Animation()

-- loads the frames from animation.png which contains 5x5 = 25
-- single frames, each with a size of 20x20 pixels, with no 
-- separating pixels in between
-- each frame is shown for 150 ms
animation:addFrames("animation.png", 5, 5, 20, 20, 0, 150)

main = {
	render = function(dt)
		animation:render(10,10, dt)
	end
}

Hosted by
SourceForge.net Logo

Valid XHTML 1.0!

Last modified Mon Oct 27, 2008