You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/animation/part-1-basics/README.md
+34-4Lines changed: 34 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,14 +3,44 @@
3
3
There are essentially two forms of animation in Indigo.
4
4
5
5
1. Animations you have imported from a third party tool.
6
-
2. Animations you have described in code.
6
+
2. Animations you have described in code, known as procedural animations.
7
7
8
8
## Importing animations
9
9
10
10
At the time of writing, the only built-in support for importing animations, is from [Aseprite](https://www.aseprite.org/) (an excellent pixel art editor and animation tool) into Indigo as a Sprite or a Clip. For working examples of this, please see the relevant section on Sprites and Clips.
11
11
12
-
## Programming Animations
12
+
Aseprite animations can either be embedded using Indigo's built-in generators, or loaded from JSON data at runtime. Contributions to support other formats are welcome!
13
13
14
-
This series of examples focuses on how to describe your animations in code, what abstractions are available, and what the trade-offs are.
14
+
## Procedural Animations
15
15
16
-
To get started, we're going to look at the fundamentals.
16
+
This series of guides explores on how to describe your animations in code.
17
+
18
+
To get started, we're going to look at the fundamentals.
19
+
20
+
## Movies vs Video Games
21
+
22
+
**Question:** What do the earliest animations, from physical zoetropes to early animations on cellular film have in common with the latest and greatest 3D animated movie extravaganza?
23
+
24
+
The answer is: A fixed frame rate, say 24 frames per second (the standard for theatrical animation screenings at one time).
25
+
26
+
That means that if you want to animate something moving from one side of the screen to the other, at constant speed in a duration of 1 second, you need to move it exactly 1/24th of the total distance on every frame, for 24 frames.
27
+
28
+
Sounds good! Doing that in code is as simple as doing this every frame:
29
+
30
+
```scala
31
+
valincrement= totalDistance /24
32
+
33
+
sprite.moveBy(increment, 0)
34
+
```
35
+
36
+
The problem with this solution is that video games are not movies, and they DO NOT have a consistent frame rate. Each frame will take slightly less or more time to process and render than the last frame. Using the method above will result in jerky and jittery animation.
37
+
38
+
## Frame time deltas to the rescue
39
+
40
+
Luckily, there is an easy solution, all we need to do is multiple the desired number of units (i.e. distance) per second (in our case, the total distance) by the amount of time that has elapse since the last frame was processed.
41
+
42
+
You may recall from school that `speed = distance / time`, well all we're going to do is re-arrange that to `distance = speed * time` where distance is how far we need to move our sprite, speed is the desired distance to move every second, and time is therefore the frame delta. Which gives us something like:
0 commit comments