It is currently 28 Mar 2024, 10:38

WELCOME TO SIMUSCAPE!


Please Sign in or Register to enable all features, remove restrictions and gain additional access!
For information on how to bypass the CAPTCHA or to contact Team Simuscape, Continue Here!


Post a new topicPost a reply Page 1 of 1   [ 1 post ]
Author Message
PostPosted: 24 Aug 2012, 03:05 
Master Mentor
User avatar

Joined: 27 Feb 2012, 22:45
Posts: 1880
Location: Canada
Newobject Tutorial - A Simple Animation

DISCLAIMER
This tutorial assumes that the reader is familiar with the coding of a simple newobject and is focused on adding the coding required to provide animation to the newobject.

This tutorial will provide the reader with the code required for newobject animation along with a brief explanation and where the code is placed within the nfo file.
This tutorial does not cover the synchronized animations of individual tiles that together form a single multi-tile newobject.

Orange text is a link to the relative location found in the NewGRF Specs
Italicized text is a direct quotation from the NewGRF Specs

For newobject animation to function properly certain properties must be enabled within Action0/Objects:

Object flags(10)
Bit Value Meaning
6 64 Object has animation[3]
{64 = h40 = 00 40 = 40 00}
Code:
10  40 00

[3] Setting this flag will allow the object's animation counter to be increased,
must be set if you plan to make use of animations.
Like stations you must enable animation on a per tile basis by means of the "built tile" trigger and callback 159
.

Animation information (11)
Code:
11  02 01 // 3 frames looping

The low byte specifies the number of animation frames minus one, so 00 means 1 frame, 01 means 2 frames etc.
The maximum number of frames is 256, although you can have some problems if your animation exceeds FD (253) frames.
The high byte must be 0 for non-looping animations and 01 for looping animations.
Every other value is reserved for future use.
In addition, if the whole word contains FFFF, animation is turned off for this object (this is the default value).
Since you can't have properties for individual object tiles, this property applies for every tile of the object.
If you don't want to animate some tiles, you should check the current position during callback 159 and return FD if the current tile doesn't need to be animated.
If you also need animations of different length per tile, you'll have to use callback 158 for that.


Animation speed (12)
Code:
12  06 // 6 = 1728ms

The meaning is the same as for house property 1B, but the lower limit is 0 instead of 2,
so the fastest possible animation changes frames every game tick (27ms).
The default value is 0.

0 = 27ms
1 = 54ms
2 = 108ms
3 = 216ms
4 = 432ms
5 = 864ms
6 = 1728ms

Animation triggers (13)
Code:
13  01 00 // Start animation when object is built.

Bit Value Meaning Happens on
0 1 Object is built all tiles
1 2 Periodic tile loop single tile
2 4 Synchronised periodic tile loop all tiles
{1 = h1 = 00 01 = 01 00}
Currently no trigger provides additional information in var 18.
The synchronised periodic tile loop is called directly after the (unsynchronised) periodic tile loop of the northern tile.


Callback flags (15)
Code:
15  10 00 // CB158 and CB15A are not required for this tutorial. This property is currently enabled only for CB15C.

For objects, the following callbacks can be defined by setting the corresponding bit in property 15:
Bit Value Variable 0C value Callback
1 2 158 Decide next animation frame (CB158)
2 4 15A Decide animation speed (CB15A)
4 16 15C Show additional text in the build object window
{16 = h10 = 00 10 = 10 00}

Here is the complete Action0 code for this tutorial:

Code:
 5 * 48    00 0F 0E 01 00
      // 08 D Class label
      08 "TU01"
      // 09 W Text ID for class
      09 00 D4
      // 0A W Text ID for this object
      0A 01 D4
      // 0B B Climate availability
      0B 07
      // 0C B Byte representing size
      0C 11
      // 0D B Object build cost factor
      0D 0C
      // 0E D Introduction date
      0E 00 00 00 00
      // 0F D End of life date
      0F 00 00 00 00
      // 10 W Object flags
      // 64 Object has animation
      // 64 = h40 = 00 40 = 40 00
       10 40 00
       // 11   W Animation information - 3 frames looping
       11 02 01
       // 12   B Animation speed - 6 - 2128ms
      12 06
       // 13   W Animation triggers (CB 159)
         // Bit   Value   Meaning               Happens on
         // 0      1   Object is built            all tiles
         // 1      2   Periodic tile loop            single tile
         // 2      4   Synchronised periodic tile loop   all tiles
         //      *1 = 0x1= 00 01 = 01 00
      13 01 00
      // 15 W Callback flags
         //  2 x 158 Decide next animation frame
         //  4 x 15A Decide animation speed
         // 16 y 15C Show additional text in the build object window
         // y value sum = 16 = h10 = 00 10 = 10 00
      15 10 00
      // 17 B Number of object views
      17 01


Before we continue here are the real sprites (The sprite sheet) we will be using:
Attachment:
objtutanim.png
objtutanim.png [ 1.62 KiB | Viewed 3302 times ]

Our code then defines only 3 of the 4 real sprites, those to be used for the animation frames:
Code:
   6 * 4    01 0F 03 01
// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel
    7 C:\mps\___Simuscape\Tutorials\Object Animation\objtutanim.png 16 16 09 47 64 -31 -34
    8 C:\mps\___Simuscape\Tutorials\Object Animation\objtutanim.png 96 16 09 47 64 -31 -34
    9 C:\mps\___Simuscape\Tutorials\Object Animation\objtutanim.png 176 16 09 47 64 -31 -34
   10 * 17    02 0F 00 00  8D 0F 00 00  00 80 00 80   00 00   0F 0F E5 // frame 0
   11 * 17    02 0F 01 00  8D 0F 00 00  01 80 00 80   00 00   0F 0F E5 // frame 1
   12 * 17    02 0F 02 00  8D 0F 00 00  02 80 00 80   00 00   0F 0F E5 // frame 2

We must now assemble the sprites in the sequence that they will appear in the animation:
Code:
13 * 18    02 0F 03 81 43 00 FF 02
                01 00 01 01 // frame 1
                02 00 02 02 // frame 2
                00 00       // frame 0

... and then we define the trigger that will initiate the animation:
Code:
14 * 17    02 0F 04 85 0C 00 FF FF 01
                00 80 59 01 59 01    // start animation on frame 0
                03 00

Our fourth sprite is now defined to appear in the menu:
Code:
15 * 4    01 0F 01 01
   16 C:\mps\___Simuscape\Tutorials\Object Animation\objtutanim.png 256 16 09 47 64 -31 -16
   17 * 17    02 0F 05 00   00 80 00 80   00 00 00 00   00 00   00 00 00 // ANIMATE

Our final Action2 returns our code to graphics and invoke our callbacks:
Code:
18 * 23    02 0F 06 85 0C 00 FF FF 02
   02 80  5C 01 5C 01 // Additional text
   03 00  59 01 59 01 // Animation
   05 00 // Default

Lastly ... Action 3 to tie everything together:
Code:
19 * 10    03 0F 01 00 01 FF  06 00  04 00


Here is the complete nfo file:
Attachment:
objtutanim.nfo [4.53 KiB]
Downloaded 371 times

Here is the GRF:
Attachment:
objtutanim.grf [2.65 KiB]
Downloaded 366 times

Comments or questions? Post them here.

_________________
Visit SimuSchool - Tutorials, Questions and Answers
TTDPatch Nightlies Downloads are back
Thrive


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 1 post ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


Status SimuscapeTerms of UseAbout Simuscape

Design by SAC © 2012-2015, Sweden • Powered by phpBB • Based on twilightBB by Daniel St. Jules