Hi all
The given sprite rectangle is outside the actual sprite size
that's the message that appeared when i've finished my first entity in the game
the question here how to identify the correlation between numbers;in image i'm dealing with 3 numbers: height,width and resolution,in Factorio it gave me left_top=384x0, right_bottom=768x384 and my sprites actual size is left_top=0x0, right_bottom=384x384)?
is there a way to make the game accept any image size as long as i'm using lua to control that size?
is there a way to use left_top,right_bottom numbers instead of width and height numbers and really control every entity size?
or do i use image-manipulation program to resize that image,and if so how to use the information that Factorio gave me for image size?
Dealing With Sprites
Re: Dealing With Sprites
Some other variables you might want to look at are collision_box, selection_box. Does the spirite have animation? If it does, then there should be a frame_count and line_length, as well as the frame_count to define the number of frames for the animation. shift will allow you to move the sprite up or down to center it. Also, look at having high and normal resolution spirtes. As a rule, high resolution sprite that is twice as high and twice as wide, takes 4 times the disk space and needs 4 times the RAM to render. scale lets you rander much larger graphics file, and have it fit.
Consider the following example of code from rendering the lab, as yanked from demo-entity. I have not pulled the entire code segment, but just enough to illustrate what I am talking about.
A lot more follows here, because the spire is rendered via multiple smaller graphic files. There is quite a bit more, but key is to experiment and try different things out. Also when coding, it is key to test it under both the normal resolution and high resolution.
Hiladdar
Consider the following example of code from rendering the lab, as yanked from demo-entity. I have not pulled the entire code segment, but just enough to illustrate what I am talking about.
Code: Select all
{
type = "lab",
name = "lab",
icon = "__base__/graphics/icons/lab.png",
icon_size = 64, icon_mipmaps = 4,
flags = {"placeable-player", "player-creation"},
minable = {mining_time = 0.2, result = "lab"},
max_health = 150,
corpse = "lab-remnants",
dying_explosion = "lab-explosion",
collision_box = {{-1.2, -1.2}, {1.2, 1.2}}, -- Look at this line here
selection_box = {{-1.5, -1.5}, {1.5, 1.5}}, -- Look at this line here
damaged_trigger_effect = hit_effects.entity(),
light = {intensity = 0.75, size = 8, color = {r = 1.0, g = 1.0, b = 1.0}},
on_animation =
{
layers =
{
{
filename = "__base__/graphics/entity/lab/lab.png",
width = 98, -- Look at this line here
height = 87, -- Look at this line here
frame_count = 33, -- Look at this line here
line_length = 11, -- Look at this line here
animation_speed = 1 / 3,
shift = util.by_pixel(0, 1.5), -- Look at this line here
hr_version =
{
filename = "__base__/graphics/entity/lab/hr-lab.png",
width = 194, -- Look at this line here
height = 174, -- Look at this line here
frame_count = 33, -- Look at this line here
line_length = 11, -- Look at this line here
animation_speed = 1 / 3,
shift = util.by_pixel(0, 1.5),
scale = 0.5 -- Look at this line here
}
},
Hiladdar
Re: Dealing With Sprites
Thanks for the information but that wasn't my question;i'm going to use the lab example to ask about what i'm really after :Hiladdar wrote: ↑Wed Jul 29, 2020 6:01 pm Some other variables you might want to look at are collision_box, selection_box. Does the spirite have animation? If it does, then there should be a frame_count and line_length, as well as the frame_count to define the number of frames for the animation. shift will allow you to move the sprite up or down to center it. Also, look at having high and normal resolution spirtes. As a rule, high resolution sprite that is twice as high and twice as wide, takes 4 times the disk space and needs 4 times the RAM to render. scale lets you rander much larger graphics file, and have it fit.
Consider the following example of code from rendering the lab, as yanked from demo-entity. I have not pulled the entire code segment, but just enough to illustrate what I am talking about.
A lot more follows here, because the spire is rendered via multiple smaller graphic files. There is quite a bit more, but key is to experiment and try different things out. Also when coding, it is key to test it under both the normal resolution and high resolution.Code: Select all
{ type = "lab", name = "lab", icon = "__base__/graphics/icons/lab.png", icon_size = 64, icon_mipmaps = 4, flags = {"placeable-player", "player-creation"}, minable = {mining_time = 0.2, result = "lab"}, max_health = 150, corpse = "lab-remnants", dying_explosion = "lab-explosion", collision_box = {{-1.2, -1.2}, {1.2, 1.2}}, -- Look at this line here selection_box = {{-1.5, -1.5}, {1.5, 1.5}}, -- Look at this line here damaged_trigger_effect = hit_effects.entity(), light = {intensity = 0.75, size = 8, color = {r = 1.0, g = 1.0, b = 1.0}}, on_animation = { layers = { { filename = "__base__/graphics/entity/lab/lab.png", width = 98, -- Look at this line here height = 87, -- Look at this line here frame_count = 33, -- Look at this line here line_length = 11, -- Look at this line here animation_speed = 1 / 3, shift = util.by_pixel(0, 1.5), -- Look at this line here hr_version = { filename = "__base__/graphics/entity/lab/hr-lab.png", width = 194, -- Look at this line here height = 174, -- Look at this line here frame_count = 33, -- Look at this line here line_length = 11, -- Look at this line here animation_speed = 1 / 3, shift = util.by_pixel(0, 1.5), scale = 0.5 -- Look at this line here } },
Hiladdar
Code: Select all
{
type = "lab",
name = "lab",
icon = "__base__/graphics/icons/lab.png",
icon_size = 64, icon_mipmaps = 4,
flags = {"placeable-player", "player-creation"},
minable = {mining_time = 0.2, result = "lab"},
max_health = 150,
corpse = "lab-remnants",
dying_explosion = "lab-explosion",
collision_box = {{-1.2, -1.2}, {1.2, 1.2}}, -- i'm going to assume those numbers represent x,y of entity?if not how to determine them based on my entity?
selection_box = {{-1.5, -1.5}, {1.5, 1.5}}, -- same question here
damaged_trigger_effect = hit_effects.entity(),
light = {intensity = 0.75, size = 8, color = {r = 1.0, g = 1.0, b = 1.0}},
on_animation =
{
layers =
{
{
filename = "__base__/graphics/entity/lab/lab.png", --the Sprite image size for this is 1078x261 <<--what if i want to use that number instead of 98x87?
width = 98, --meanwhile 98 used. Does this represent one frame ?
height = 87, -- meanwhile 87 used. Does this represent one frame?
frame_count = 33,
line_length = 11,
animation_speed = 1 / 3,
shift = util.by_pixel(0, 1.5),
hr_version =
{
filename = "__base__/graphics/entity/lab/hr-lab.png",
width = 194,
height = 174,
frame_count = 33,
line_length = 11,
animation_speed = 1 / 3,
shift = util.by_pixel(0, 1.5),
scale = 0.5 -- how to determine the scale based on my entity?
}
},
Re: Dealing With Sprites
Great questions! Let me try and answer them for you.
collision_box = {{-1.2, -1.2}, {1.2, 1.2}}, -- i'm going to assume those numbers represent x,y of entity?if not how to determine them based on my entity? The normal lab entity size is 3x3. What this is saying, that the collision box is 2.4 by 2.4. In the case of the collision box, that determines if how much room there is to move around it, for both you, a vehicle, or biters. The selection box, determines what you have to click on in order to have it highlighted.
filename = "__base__/graphics/entity/lab/lab.png", --the Sprite image size for this is 1078x261 <<--what if i want to use that number instead of 98x87? The file size is 1078x262. But if you look at the sprite in say PC Paint you will see that it is 3 rows of labs, each one slightly different then the other one. The frame count defines how many frames the graphic cycles through before starting the animation sequence again. With 3 rows, composing 33 graphics, we have 98 the sprite width multiplied by the the number of frames in a row, so 98x11 = 1078. The 3 rows, is multiplied by the height of the sprite, in this case 87x3 = 261. That is why the full graphic containing all 33 frames is 1078x261.
width = 98, --meanwhile 98 used. Does this represent one frame ? You got it. That is the width of the physical width of the graphic as it is displayed in the game.
height = 87, -- meanwhile 87 used. Does this represent one frame? That is the width of the physical height of the graphic as it is displayed in the game.
scale = 0.5 -- how to determine the scale based on my entity? From the normal resolution graphic, the high resolution one will usually be twice the height and twice the width of the normal resolution. This variable defines how large the physical sprite will be displayed on in the game. You can increase the size of the sprite or decrease it, on the screen by adjusting the scale variable.
The frame_count / line_length tells the core game engine how many how the graphic file is organized internally.
There is a lot more, but one of the best ways, is to create a new entity, based of the original game, and try editing one value at a time. The load up the game, and see how your change in the code is now rendered in the game.
Hiladdar
collision_box = {{-1.2, -1.2}, {1.2, 1.2}}, -- i'm going to assume those numbers represent x,y of entity?if not how to determine them based on my entity? The normal lab entity size is 3x3. What this is saying, that the collision box is 2.4 by 2.4. In the case of the collision box, that determines if how much room there is to move around it, for both you, a vehicle, or biters. The selection box, determines what you have to click on in order to have it highlighted.
filename = "__base__/graphics/entity/lab/lab.png", --the Sprite image size for this is 1078x261 <<--what if i want to use that number instead of 98x87? The file size is 1078x262. But if you look at the sprite in say PC Paint you will see that it is 3 rows of labs, each one slightly different then the other one. The frame count defines how many frames the graphic cycles through before starting the animation sequence again. With 3 rows, composing 33 graphics, we have 98 the sprite width multiplied by the the number of frames in a row, so 98x11 = 1078. The 3 rows, is multiplied by the height of the sprite, in this case 87x3 = 261. That is why the full graphic containing all 33 frames is 1078x261.
width = 98, --meanwhile 98 used. Does this represent one frame ? You got it. That is the width of the physical width of the graphic as it is displayed in the game.
height = 87, -- meanwhile 87 used. Does this represent one frame? That is the width of the physical height of the graphic as it is displayed in the game.
scale = 0.5 -- how to determine the scale based on my entity? From the normal resolution graphic, the high resolution one will usually be twice the height and twice the width of the normal resolution. This variable defines how large the physical sprite will be displayed on in the game. You can increase the size of the sprite or decrease it, on the screen by adjusting the scale variable.
The frame_count / line_length tells the core game engine how many how the graphic file is organized internally.
There is a lot more, but one of the best ways, is to create a new entity, based of the original game, and try editing one value at a time. The load up the game, and see how your change in the code is now rendered in the game.
Hiladdar
Re: Dealing With Sprites
Very informative,thanks to you now i have better understanding of what those numbers represent.Based on what you have explained then i can work backward as well,back to the lab example;by opening the image i would know that sprite sheet 1078X261 contains 11 columns and 3 rows then i can divide 1078/11 to get 98,261/3 to get 87,Simple enough.Hiladdar wrote: ↑Thu Jul 30, 2020 4:45 pm Great questions! Let me try and answer them for you.
collision_box = {{-1.2, -1.2}, {1.2, 1.2}}, -- i'm going to assume those numbers represent x,y of entity?if not how to determine them based on my entity? The normal lab entity size is 3x3. What this is saying, that the collision box is 2.4 by 2.4. In the case of the collision box, that determines if how much room there is to move around it, for both you, a vehicle, or biters. The selection box, determines what you have to click on in order to have it highlighted.
filename = "__base__/graphics/entity/lab/lab.png", --the Sprite image size for this is 1078x261 <<--what if i want to use that number instead of 98x87? The file size is 1078x262. But if you look at the sprite in say PC Paint you will see that it is 3 rows of labs, each one slightly different then the other one. The frame count defines how many frames the graphic cycles through before starting the animation sequence again. With 3 rows, composing 33 graphics, we have 98 the sprite width multiplied by the the number of frames in a row, so 98x11 = 1078. The 3 rows, is multiplied by the height of the sprite, in this case 87x3 = 261. That is why the full graphic containing all 33 frames is 1078x261.
width = 98, --meanwhile 98 used. Does this represent one frame ? You got it. That is the width of the physical width of the graphic as it is displayed in the game.
height = 87, -- meanwhile 87 used. Does this represent one frame? That is the width of the physical height of the graphic as it is displayed in the game.
scale = 0.5 -- how to determine the scale based on my entity? From the normal resolution graphic, the high resolution one will usually be twice the height and twice the width of the normal resolution. This variable defines how large the physical sprite will be displayed on in the game. You can increase the size of the sprite or decrease it, on the screen by adjusting the scale variable.
The frame_count / line_length tells the core game engine how many how the graphic file is organized internally.
There is a lot more, but one of the best ways, is to create a new entity, based of the original game, and try editing one value at a time. The load up the game, and see how your change in the code is now rendered in the game.
Hiladdar