animated objects in NML

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

Moderator: Graphics Moderators

Post Reply
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

animated objects in NML

Post by Yoshi »

Hello,

i tried to animate some NewObjects...

They should work parallel (same frame), if they are built next to another animated object....

I think "nearby_tile_animation_frame" is the right thing for this task, or?


The newgrf-specs and NML Tutorial aren't that useful here :) One more page in the tutorial would make it a lot easier:D

Code: Select all

spriteset (spriteset_animated) {
        template_animated()
}

spritelayout gfx_animated(frame) {
	ground {
		sprite: GROUNDSPRITE_NORMAL;
	}
	building {
		sprite		:spriteset_animated(frame); 
		xextent		:16;
		yextent		:16;
		zextent		:40;
		zoffset		:0;
	}
}



item (FEAT_OBJECTS, item_animated) {
	property {
		class					:"INFR";
		classname				:string(STR_CLASS_INFR);
		name				:string(STR_NAME_animated);
		climates_available		:bitmask(CLIMATE_ARCTIC);
		size					:[1,1];
		build_cost_multiplier	        :0;
		remove_cost_multiplier	:0;
		introduction_date		:date(1800,1,1);
		end_of_life_date		        :0xFFFFFFFF;
		object_flags			:bitmask(OBJ_FLAG_ANIMATED, OBJ_FLAG_NO_FOUNDATIONS);
		animation_info			:[ANIMATION_LOOPING,48];
		animation_speed		:2;
		animation_triggers		:1;
		height				:5;
		num_views			:1;
	}
	graphics {
		default            		        :gfx_animated(animation_frame);
		additional_text			:string(STR_animated_PURCHASE);
		anim_control			:return CB_RESULT_NEXT_FRAME;
		anim_next_frame		:return CB_RESULT_NEXT_FRAME;

    }
	
}

Where do I have to insert code for synchronising?

At "animation_frame" ?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: animated objects in NML

Post by planetmaker »

You have one tile use its own animation frame. The other tiles need to reference (look at) that neighbouring tile.

Both, animation_frame and nearby_tile_animation_frame(rel_x, rel_y) are variables which can be evaluated in a switch or in an advanced spriteset directly.

Mind, that you can only do that for a multi-tile object. You cannot do that for several 1x1 objects.

Untested, but maybe you can even write it in a concise form like this with one variable in the spriteset itself, instead of using several switches:

Code: Select all

spriteset (spriteset_animated) {
        template_animated()
}

spritelayout gfx_animated {
   ground {
      sprite: GROUNDSPRITE_NORMAL;
   }
   building {
      sprite      :spriteset_animated(nearby_tile_animated_frame(-relative_x,-relative_y)); 
(...)
   }
}

item (FEAT_OBJECTS, item_animated) {
   property {
 (...)
}
   graphics {
      default                          :gfx_animated;
 (...)
   }
}
}
If it doesn't work, you'll want a switch for the "master" tile and the "slave" tiles. Where the latter reference the animation frame of the master-tile.
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: animated objects in NML

Post by Yoshi »

Mind, that you can only do that for a multi-tile object. You cannot do that for several 1x1 objects.
So it's impossible to get the "information" from a nearby tile which isn't in the same object but from the same type?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: animated objects in NML

Post by planetmaker »

Did you try?

I'm not sure right now. It might work. But you then will have to make sure that it's also an object tile, that it's the object of the right type before you actually want to evaluate the animation frame.
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: animated objects in NML

Post by Yoshi »

I tried....but it didn't worked....

Maybe the offsets are wrong?
(c) SwissFan
(c) SwissFan
nearby_tile.png (16.14 KiB) Viewed 3321 times
The left tile is animated and the right one should copy the animation stages from the left one.

Code: Select all

spritelayout gfx_seilbahn2() {
			ground {
				sprite: GROUNDSPRITE_NORMAL;
			}
			building {
				sprite		:spriteset_seilbahn2(nearby_tile_animation_frame(0,-1)); 
				xextent		:16;
				yextent		:16;
				zextent		:40;
				zoffset		:0;
			}
		}
Who implemented this variable?
Maybe he can give some light on the question, whether it has to be the same object or not.
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: animated objects in NML

Post by wallyweb »

newgrf-specs wrote:Get object type at offset (60)

The parameter of this variable is an offset from the current tile. The low nibble contains the signed X offset (that is 0h=0, 1h=+1 ... 7h=+7, 8h=-8, 9h=-7 ... Fh=-1), the high nibble contains the Y offset. Therefore the parameter 00h accesses the current tile itself. The high word of the return value is currently reserved, and the low word can be:

00xxh if the tile is an object tile and was defined in the current GRF with ID xx.
FFFEh if the tile is an object tile that was defined in another GRF file or it's a default object.
FFFFh if the tile isn't an object tile.
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: animated objects in NML

Post by michael blunck »

Yoshi wrote: [Seilbahn]
The left tile is animated and the right one should copy the animation stages from the left one.
Do you keep in mind that you´ll need all types of part graphics for border-crossings?

Depending on the length of your funicular, it´ll be beneficial to plan the motion scheme beforehand.

regards
Michael
Image
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: animated objects in NML

Post by Yoshi »

michael blunck wrote: Depending on the length of your funicular, it´ll be beneficial to plan the motion scheme beforehand.
I have planed a 32-frame cycle... That should work...
So every second tile shows the same state and the other tiles show the state + 16 frames :)
Attachments
Seilbahn32.png
(6.57 KiB) Downloaded 4 times
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: animated objects in NML

Post by Yoshi »

Maybe I can get around the problems....

Is it possible to get the coordinates of the object, like houses can with "y_coordinate"?
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: animated objects in NML

Post by frosch »

Not sure whether this was answered, but "nearby_tile_animation_frame" cannot access animation frames of other objects.
Also in your case it would not make a lot of sense, as it would break with more than two tiles in a row, or when building a circle of tiles.

Anyway, if you want animations of multiple tiles to run synchronously you might want to not use a tile-specific "animation frame", but rather a global "time" variable, like "animation_counter". See http://newgrf-specs.tt-wiki.net/wiki/NM ... _variables

Edit: And, no, there is currently no way to get the position of the tile on the map. So you cannot do stuff "every second tile". But that might be a valid feature request :)
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: animated objects in NML

Post by wallyweb »

frosch wrote:Edit: And, no, there is currently no way to get the position of the tile on the map. So you cannot do stuff "every second tile". But that might be a valid feature request :)
What about this?
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: animated objects in NML

Post by michael blunck »

Yoshi wrote: [synchonizing animated objects]
[...]
frosch wrote: Anyway, if you want animations of multiple tiles to run synchronously you might want to not use a tile-specific "animation frame", but rather a global "time" variable, like "animation_counter".
Just a reminder for newGRF authors, there´s (still) no possibility to start synchronized multi-tile animations in a random way, see http://bugs.openttd.org/task/5144 and discussion here.

(IMO, a more valid feature request ... :cool: )

regards
Michael
Image
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: animated objects in NML

Post by Yoshi »

michael blunck wrote:
Yoshi wrote: Just a reminder for newGRF authors, there´s (still) no possibility to start synchronized multi-tile animations in a random way, see http://bugs.openttd.org/task/5144 and discussion here.
(IMO, a more valid feature request ... :cool: )
frosch wrote: Edit: And, no, there is currently no way to get the position of the tile on the map. So you cannot do stuff "every second tile". But that might be a valid feature request :)

I think both are valid requests...
frosch wrote:Anyway, if you want animations of multiple tiles to run synchronously you might want to not use a tile-specific "animation frame", but rather a global "time" variable, like "animation_counter". See http://newgrf-specs.tt-wiki.net/wiki/NM ... _variables
[/quote]
I already switched to this variable :), and it works fine :)
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: animated objects in NML

Post by Eddi »

frosch wrote:Edit: And, no, there is currently no way to get the position of the tile on the map. So you cannot do stuff "every second tile". But that might be a valid feature request :)
well, the only way to do that then would be to have the object available only in fixed 2x1 and 1x2 sections. you still have no idea where on the map it is, but you can distinguish the front and back tile then.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: animated objects in NML

Post by frosch »

wallyweb wrote:
frosch wrote:Edit: And, no, there is currently no way to get the position of the tile on the map. So you cannot do stuff "every second tile". But that might be a valid feature request :)
What about this?
You can only get the position of a object tile within an object, i.e. relative to its north tile.

This thread is about synchronizing animation of multiple independent 1x1 objects, not to synchronize animation within a single multitile-object (which is already possible using var 63).
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: animated objects in NML

Post by wallyweb »

frosch wrote:You can only get the position of a object tile within an object, i.e. relative to its north tile.
Oh noooo! Then I must plead guilty to having done the impossible. :cry:
This thread is about synchronizing animation of multiple independent 1x1 objects, not to synchronize animation within a single multitile-object (which is already possible using var 63).
Yes ... I realize this. :D
Here is what I did:
In your Action0 you can have several objects with the same class label even though each of these labels represents a unique 1x1 object.
Unseen to the coder, the Action0 also adds an Object ID for each of these objects.
So for example you could have 3 objects with the same property 08: "OBJ0" "OBJ0" "OBJ0"
They would also have the same property 09: 00 D4 00 D4 00 D4
They would differ in their property 0A: 01 D4 02 D4 03 D4
What we do not see is that both TTDP and OTTD assign Object IDs to each of these objects starting at 00 for the first "OBJ0", 01 for the second "OBJ0", 02 for the third "OBJ0", ... etc.
Using variable 60:

Code: Select all

129 * 100	 02 0F 35  85	   60 01 20 FF 00
						04 60 0F 20 FF 00
						04 60 10 20 FF 00
						04 60 11 20 FF 00
						04 60 1F 20 FF 00
						04 60 F0 20 FF 00
						04 60 F1 20 FF 00
						04 60 FF 00 FF 00
						01 0A 00  00 00  00 00   1C 00
This code checks for the presence of a tile with Object ID 00 at coordinates 0F, 10, 11, 1F, F0, F1 and FF.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: animated objects in NML

Post by Yexo »

wallyweb wrote:
frosch wrote:You can only get the position of a object tile within an object, i.e. relative to its north tile.
Oh noooo! Then I must plead guilty to having done the impossible. :cry:

This code checks for the presence of a tile with Object ID 00 at coordinates 0F, 10, 11, 1F, F0, F1 and FF.
Sure, but var 61 (Get random tile bits at offset param) doesn't work for those tiles since they belong to a different object.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 24 guests