How does it work with the graphics?

Place to get help with not working mods / modding interface.
Jadefalke
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Jan 01, 2020 5:03 pm
Contact:

How does it work with the graphics?

Post by Jadefalke »

Hello together I am new in the topic Modding.
Currently I'm trying to find out how the graphics work.
I have created a machine, which should be exactly 2 by 2 fields in the game.
For a reason which is completely incomprehensible to me this graphic is 3 by 3 fields in the game.
The graphic has a size of 64 by 64 pixels, but is treated in the same way as another graphic which is 96 by 96 pixels.
Is there a function that I can use to determine the position of the graphic?

Translated with www.DeepL.com/Translator (free version)
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: How does it work with the graphics?

Post by darkfrei »

I'm using the paint-dot-net for it. in the debug view F5 you can turn on the grid via F4.
Press F9 before the screenshot.
Make the screenshot, open it with the paint-dot-net.
Draw the line between old entity center and the good one. You can see the distance in pixels as x and y difference.
Devide it with 32 or just write it as shift = {x=x_pixels/32, y=y_pixels/32}
Jadefalke
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Jan 01, 2020 5:03 pm
Contact:

Re: How does it work with the graphics?

Post by Jadefalke »

Thanks a lot!
I still don't have a plan what i am doing but sometimes it works and sometimes not.
So i use a lot of hope and Magic to create Graphics ;-)
Hiladdar
Fast Inserter
Fast Inserter
Posts: 214
Joined: Mon May 14, 2018 6:47 pm
Contact:

Re: How does it work with the graphics?

Post by Hiladdar »

Once you have the graphic image or animation graphic, you need to define it within lua. Consider the following code extract using solar panels from the base game:

{
type = "solar-panel",
name = "solar-panel",
icon = "__base__/graphics/icons/solar-panel.png",
icon_size = 64, icon_mipmaps = 4,
flags = {"placeable-neutral", "player-creation"},
minable = {mining_time = 0.1, result = "solar-panel"},
max_health = 200,
corpse = "solar-panel-remnants",
dying_explosion = "solar-panel-explosion",
collision_box = {{-1.4, -1.4}, {1.4, 1.4}},
selection_box = {{-1.5, -1.5}, {1.5, 1.5}},
damaged_trigger_effect = hit_effects.entity(),
energy_source =
{
type = "electric",
usage_priority = "solar"
},
picture =
{
layers =
{
{
filename = "__base__/graphics/entity/solar-panel/solar-panel.png",
priority = "high",
width = 116,
height = 112,
shift = util.by_pixel(-3, 3),

hr_version =
{
filename = "__base__/graphics/entity/solar-panel/hr-solar-panel.png",
priority = "high",
width = 230,
height = 224,
shift = util.by_pixel(-3, 3.5),
scale = 0.5
}
},
{
filename = "__base__/graphics/entity/solar-panel/solar-panel-shadow.png",
priority = "high",
width = 112,
height = 90,
shift = util.by_pixel(10, 6),
draw_as_shadow = true,
hr_version =
{
filename = "__base__/graphics/entity/solar-panel/hr-solar-panel-shadow.png",
priority = "high",
width = 220,
height = 180,
shift = util.by_pixel(9.5, 6),
draw_as_shadow = true,
scale = 0.5
}
}
}
},
overlay =
{
layers =
{
{
filename = "__base__/graphics/entity/solar-panel/solar-panel-shadow-overlay.png",
priority = "high",
width = 108,
height = 90,
shift = util.by_pixel(11, 6),
hr_version =
{
filename = "__base__/graphics/entity/solar-panel/hr-solar-panel-shadow-overlay.png",
priority = "high",
width = 214,
height = 180,
shift = util.by_pixel(10.5, 6),
scale = 0.5
}
}
}
},
vehicle_impact_sound = sounds.generic_impact,
production = "60kW"
},


I picked solar panals from the base game entity definition since it is a fairly simple example that has both high and low resolution, one overlay, and no animation to start. I have highlighted in red the parts I am writing about.

The width and height parameters tell the game engine what the dimensions of the graphic image are. selection_box parameter tells the game engine that it is displayed as a 3x3 graphic on the map. shift allows the graphic to be adjusted a bit on the display so that it looks looks right, Adjustments are made by pixel using x, y coordinate system and can accept negative decimals. Animation files will be a bit more involved since you need to tell the game engine how many rows, and columns there are in the animation graphic file, how fast the animation is suppose to cycle through. Some graphics are even a bit more complicated since there are multiple graphic files to define an entity. This example only has the entity, and one overlay.

My best word of advice is to take a look at how the base game lua defines and integrates graphics, then download some mods, and take a look at what mod developers do. Take the time to compare this code to an entity that is a 2x2, such as a power pole, or stone furnace. Once you have played around with the variables a bit, it will become much clearer.

Hiladdar
Jadefalke
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Jan 01, 2020 5:03 pm
Contact:

Re: How does it work with the graphics?

Post by Jadefalke »

Thats it!!!
I love You!
No more Magic from now on ;)
Why is there not a simple Guide that explains this whole thing?
Post Reply

Return to “Modding help”