Vehicle animation

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Post Reply
User avatar
oftcrash
Transport Coordinator
Transport Coordinator
Posts: 304
Joined: 03 Jan 2013 17:20
Location: New England, USA

Vehicle animation

Post by oftcrash »

Hi there!

I'm trying to figure out how to get an animation working on a vehicle using NML. I have 4 spritesets - 1 for each of the animation frames. As I understand it, I should use the motion_counter variable. Assuming I call this in a switch, what would that look like? Here's what I have right now (which is obviously incorrect).

Code: Select all

switch (FEAT_AIRCRAFT, SELF, sw_v22_hor_anim, (motion_counter / 256)) {
    1:    ss_ac_v22_hor_1;
    2:    ss_ac_v22_hor_2;
    3:    ss_ac_v22_hor_3;
    4:   ss_ac_v22_hor_4;
    5:   ss_ac_v22_hor_1;
    6:   ss_ac_v22_hor_2;
    7:   ss_ac_v22_hor_3;
    8:   ss_ac_v22_hor_4;
    9:   ss_ac_v22_hor_1;
    10:   ss_ac_v22_hor_2;
    11:   ss_ac_v22_hor_3;
    12:   ss_ac_v22_hor_4;
    13:   ss_ac_v22_hor_1;
    14:   ss_ac_v22_hor_2;
    15:   ss_ac_v22_hor_3;
    16:   ss_ac_v22_hor_1;
    ss_ac_v22_hor_1;
}
Thanks!
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Vehicle animation

Post by Leanden »

Is this for helicopters by chance?
Image
User avatar
oftcrash
Transport Coordinator
Transport Coordinator
Posts: 304
Joined: 03 Jan 2013 17:20
Location: New England, USA

Re: Vehicle animation

Post by oftcrash »

Leanden wrote:Is this for helicopters by chance?
Sort of - its for a tiltrotor. I know there's support for rotors in helicopters, though I've only played with them a little bit. In this case though, I want it to both spin in the vertical as well as the horizontal position.
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Vehicle animation

Post by Leanden »

I dont think that is possible. There are 4 sprites available for animated aircraft, 3 in motion on a cycle and fourth for landed position.
Image
User avatar
oftcrash
Transport Coordinator
Transport Coordinator
Posts: 304
Joined: 03 Jan 2013 17:20
Location: New England, USA

Re: Vehicle animation

Post by oftcrash »

Is the only animation available for an aircraft the rotor, or can it be done through cycling through a few sprites for the vehicle. The docs for motion_counter imply that it can be done, but I don't know what restrictions there might be on its usage.
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Vehicle animation

Post by Leanden »

oftcrash wrote:Is the only animation available for an aircraft the rotor, or can it be done through cycling through a few sprites for the vehicle. The docs for motion_counter imply that it can be done, but I don't know what restrictions there might be on its usage.
I suppose in theory you could do it that way. How would you tell the vehicle which way to point the rotors?
Image
User avatar
oftcrash
Transport Coordinator
Transport Coordinator
Posts: 304
Joined: 03 Jan 2013 17:20
Location: New England, USA

Re: Vehicle animation

Post by oftcrash »

I have that part working in a separate switch.

Code: Select all

switch (FEAT_AIRCRAFT, SELF, sw_ac_v22, (var[0xE2, 0, 0xFF])) {
    16: sw_v22_hor_anim; // final approach before landing or going for another round
    18: sw_v22_hor_anim; // heading for tower contact point (where airplanes initiate their approach)
    20: sw_v22_hor_anim; // heading for the final approach entry point
    23: ss_ac_v22_ver; // helicopter taking off from airport
    24: sw_v22_hor_anim; // helicopter preparing to land at airport
    25: ss_ac_v22_ver; // helicopter landing at airport
    26: ss_ac_v22_ver; // helicopter taking off from heliport
    27: sw_v22_hor_anim; // helicopter preparing to land at heliport
    28: ss_ac_v22_ver; // helicopter landing at heliport
        ss_ac_v22_ver; // default
}
In flight it calls the animation switch (which doesn't animate at the moment, but does return the correct failover spriteset). When the state is landing or take-off, it switches over to the vertical animation switch.
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Vehicle animation

Post by Eddi »

usually you would use the lowest bits of the motion counter, not the highest. so something like "motion_counter % 16" instead of "motion_counter / 256" (this would result in values 0 to 15). an alternative way to write this is "motion_counter & 0x0F"
User avatar
oftcrash
Transport Coordinator
Transport Coordinator
Posts: 304
Joined: 03 Jan 2013 17:20
Location: New England, USA

Re: Vehicle animation

Post by oftcrash »

Eddi wrote:usually you would use the lowest bits of the motion counter, not the highest. so something like "motion_counter % 16" instead of "motion_counter / 256" (this would result in values 0 to 15). an alternative way to write this is "motion_counter & 0x0F"
That did it. Thanks!
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 27 guests