Difference between revisions of "Love - Animation"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "=Requirements= You need to have followed the installation process for the Love engine. You also need to have created a minimal game (ie a new folder, with a 'main.lua' file)...")
 
(Required Variables)
Line 21: Line 21:
  
 
=Required Variables=
 
=Required Variables=
 +
We need to add the following variables before your 'love.load()':
  
 +
<syntaxhighlight lang=lua>
 +
fps = 10
 +
width = 120
 +
current = 0
 +
frames = 4
 +
duration = 1/fps
 +
</syntaxhighlight>
 +
 +
The variable fps is the number of frames per second, this will give you some degree of control and also compensate for varying processing power.
 +
 +
Width is the width of a single frame, if your sprite sheet contained multiple rows (normally one per animation) you would also need to use height.
 +
 +
Current will be the current frame, and frames is the total number of frames in this animation.
 +
 +
Duration is calculated from the frames per second, this will be used to ensure we only switch frames after a certain amount of time has passed.
  
 
=Load in the SpriteSheet=
 
=Load in the SpriteSheet=

Revision as of 10:46, 27 June 2019

Requirements

You need to have followed the installation process for the Love engine.

You also need to have created a minimal game (ie a new folder, with a 'main.lua' file)

You need to have added this code to 'main.lua':

function love.load()

end

function love.update(dt)

end
 
function love.draw()

end

Required Variables

We need to add the following variables before your 'love.load()':

fps = 10
width = 120
current = 0
frames = 4
duration = 1/fps

The variable fps is the number of frames per second, this will give you some degree of control and also compensate for varying processing power.

Width is the width of a single frame, if your sprite sheet contained multiple rows (normally one per animation) you would also need to use height.

Current will be the current frame, and frames is the total number of frames in this animation.

Duration is calculated from the frames per second, this will be used to ensure we only switch frames after a certain amount of time has passed.

Load in the SpriteSheet

Switch Frames

Draw current frame