[gd] To make sprite animation, the getsheet() function and Sprite class are used. First, using the ImageSheet class, the frame information must be loaded.
[bl] Assume that the image file 'catrun.png' is as follows
The whole width and height of this image is 2048x512. This image contains 8 frames and the size of each frame is 512x256. The frame in the left-top corner has number 1. The frame number increases to the right and downwards.
The arguments of the constructor of ImageSheet are the following four parameters and are all required.
fileURL, frame_width, frame_height, number_of_frames
Next, a sequence information is to be made.
Single Sequence
The sequence table contains the following information.
• time : (required) play time in milli-second
• frames: (optional) table containing frame numbers to play.
• loops : (optional) number of repeatitions
if loops are omitted, the animation plays repeatedly forever.
If the 'frames' table is omitted, the default table automatically generated contains all the frames in the image sheet.
Some examples are as follows. Note that the 'time' field is always required.
The two sheet and sequence informat are used in Sprite class
The animation is initially paused to play. If one want to create Sprite object and play at the same time, do as follows:
Then, the animation object is created and played immediately.
Multiple Sequences
The sequence table can have more than two sequence information. In this case, each sequence forms a single table. For example,
Each table is given an id in order and this id is used in play() method.
The sequence can have a name and play() method can use this user-designated name instead of automatically given id number.
In this example, the cat sprite plays 'walk' named sequence at the beginning, and plays 'run' sequence after 5 seconds.
댓글 없음:
댓글 쓰기