Scrupp 0.4 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

You can download an example image that contains the frames of an animation which can be used with the example below: animation.png.

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

-- load required plugins
require "animation"

-- create a new animation
local animation = Animation()

-- loads the frames from animation.png which contains 3x2 = 6
-- single frames, each with a size of 48x48 pixels, with no 
-- separating pixels in between
-- each frame is shown for one second (1000 milliseconds)
animation:addFrames("animation.png", 3, 2, 48, 48, 0, 1000)

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

Hosted by
SourceForge.net Logo

Valid XHTML 1.0!

Last modified Fri May 29, 2009