I need help with template coordinates

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

Moderator: Graphics Moderators

Post Reply
User avatar
Abydos
Engineer
Engineer
Posts: 20
Joined: 18 Dec 2016 01:51
Location: Rio de Janeiro, Brazil

I need help with template coordinates

Post by Abydos »

<<<Sorry for my bad english!>>>

Hi, I am new to creating NewGRFs, and I would like to ask a question as I wanted to know how I configured a basic 4-view template for a locomotive sprite, since I could not understand the tutorial available on the wiki (https://www.tt-wiki.net/wiki/NMLTutoria ... pritegroup).

Below is the sprite I did:
MAFERSATREM.png
MAFERSATREM.png (2.46 KiB) Viewed 1896 times
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: I need help with template coordinates

Post by Alberth »

Please be more specific.
"I don't understand X" is a good start, but for us X is fully understandable, that is, we fail to see what you cannot understand.

Show us what you made, show us what the compiler says, or show us what the documentation says, and explain to us why that is not what you expect, and why it is a problem that you cannot make sense of.
Basically give us enough information such that we can replay your problem ourselves.
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
Abydos
Engineer
Engineer
Posts: 20
Joined: 18 Dec 2016 01:51
Location: Rio de Janeiro, Brazil

Re: I need help with template coordinates

Post by Abydos »

Alberth wrote:Please be more specific.
"I don't understand X" is a good start, but for us X is fully understandable, that is, we fail to see what you cannot understand.

Show us what you made, show us what the compiler says, or show us what the documentation says, and explain to us why that is not what you expect, and why it is a problem that you cannot make sense of.
Basically give us enough information such that we can replay your problem ourselves.
I did not understand the process of aligning the sprites, as below:

Spriteset (<identifier>, <graphics_file>) {
[Left_x1, upper_y1, width1, height1, offset_x1, offset_y1]
[Left_x2, upper_y2, width2, height2, offset_x2, offset_y2]
[Left_x3, upper_y3, width3, height3, offset_x3, offset_y3]
[Left_x4, upper_y4, width4, height4, offset_x4, offset_y4]
[Left_x5, upper_y5, width5, height5, offset_x5, offset_y5]
[Left_x6, upper_y6, width6, height6, offset_x6, offset_y6]
[Left_x7, upper_y7, width7, height7, offset_x7, offset_y7]
[Left_x8, upper_y8, width8, height8, offset_x8, offset_y8]
}

I compiled the file and tested it in the game, but with the wrong values the sprite gets totally weird, and I do not know how to configure it.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: I need help with template coordinates

Post by Alberth »

In your image, the pixel at the top-left corner is at (0, 0). The x axis goes to the right, and the y axis goes down. Two pixels to the right and one down from (0, 0) thus is at (2, 1).

Each "[...]" line is for one sprite. "left_x" and "upper_y" together, form the coordinates of the top-left pixel that must be shown. "width" is the number of pixels that must be shown in horizontal direction, and "height" is the number pixels shown in vertical direction. These 4 numbers together define the area that is displayed.

Such a displayed area is shown relative to the bottom-center of the train in a game (I think).
That means if you set both offsets to 0, your top-left pixel of the displayed area is shown at the bottom center of the train in the game. In general you don't want that, the top-left pixel must be shown more to the left and up (relative to the bottom center). You do this by setting a negative offset in x, and in y. Starting with the top-left corner of the displayed area at the bottom center of the train, and both offsets to 0. Decrement the "offset_x" by 1 to shift the displayed area 1 pixel to the left, and decrement the "offset_y" by 1 to shift the displayed area up by 1 pixel.

The other way to go about setting offsets is by finding the pixel that should be bottom-center of the train, and count how many pixels that is down and to the right from the top-left pixel of the displayed area. Negate those numbers, and you have your offsets.


Generally setting the numbers is a time consuming process. Do each side separately, tweaking the numbers of the sprite, recompiling, testing in game, for several rounds. This is why most artists use a template where a vehicle is always drawn at the same position in the image. They can re-use the same numbers for each train that they draw.
Being a retired OpenTTD developer does not mean I know what I am doing.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 7 guests