Overlay image on entity

Place to get help with not working mods / modding interface.
Post Reply
User avatar
moon69
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Sep 18, 2016 6:53 pm
Contact:

Overlay image on entity

Post by moon69 »

Ho modders,

I want to create an upgraded electric drill in 0.15, and was hoping to overlay the default graphics/animation with a simple static png (EG: transparent background with X in corner)...
Image

Code: Select all

local newEntity
newEntity = util.table.deepcopy(data.raw["mining-drill"]["electric-mining-drill"]);
newEntity.name = "my-electric-drill-2"
newEntity.minable.result = my-electric-drill-2"
newEntity.animation_speed = 1
newEntity.energy_usage = "300kW"
newEntity.mining_speed = 1
newEntity.tint = {r = 0.1, g = 0.9, b = 0.9}
I was hoping for something like this:

Code: Select all

newEntity.YYY =
    {
		filename = mod_directory .. "/graphics/purpleX.png",
		priority = "extra-high",
		width = 100,
		height = 100,
		--perhaps need shift etc. here
    }
but no idea what YYY should be!

I'm guessing I need to add a layer, but I can't figure out which property to add the layer to.
Looking at the default entity for the drill it appears the basic structure of the drill is actual repeated in each animation for each direction, but I just want a single overlay that doesn't animate or change direction.

Any hints appreciated thank you.

Edit: Bonus points for info on Z order so I can place my overlay under the animated mining blades :) Is that what "priority" is for?

kikker450
Inserter
Inserter
Posts: 30
Joined: Fri May 05, 2017 9:07 am
Contact:

Re: Overlay image on entity

Post by kikker450 »

You should take a look at the raw data files (Factorio\data\base\prototypes\entity\demo-mining-drill.lua) I don't know exactly how the animation works so no real advice there ( although it seems that you need to make a layer on top of the animation for north,south,west,east) there but if you don't want to find out yourself you can do a workaround by adding the cross as an seperate entity and placing it every time the player places a mining drill on the coordinates of said mining drill. If the priority is set high enough and the entity doesn't collide you should be fine.

User avatar
moon69
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Sep 18, 2016 6:53 pm
Contact:

Re: Overlay image on entity

Post by moon69 »

Thanks (again!) kikker.

I've been toying with the animation code from demo-mining-drill this morning, but have not figured out how to make the layer work properly yet... I was hoping there was a simple property for a static image I could layer.

I'll keep experimenting!

User avatar
moon69
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Sep 18, 2016 6:53 pm
Contact:

Re: Overlay image on entity

Post by moon69 »

I still can't figure this out...

Laying a 2nd entity works but is kind of messy... anyone have a clue on how to overlay a static image on an animated entity?

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Overlay image on entity

Post by bobingabout »

Look at how shadows are added to some entity, they're done using layers. Simply add a new layer with your overlay on it.
A good example would be the tank and it's mask layer, that mask is remapable to player colour, but it doesn't have to be, the point is, that's drawn on top of the entity. You can simply include whatever you want to be drawn on top of your drill using the same method.

you would of course have to completely redefine the graphics section of the entity, it can be easy for me to do that because I don't use the deepcopy method, most of my entities are all code copies from the base game, and while that does allow me to change things like the entire graphics section with a custom version to add layers, it does make my entities more susceptible to breaking, as it doesn't automatically inherit code changes, like the deepcopy method would.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Overlay image on entity

Post by darkfrei »

moon69 wrote:I still can't figure this out...

Laying a 2nd entity works but is kind of messy... anyone have a clue on how to overlay a static image on an animated entity?
The y coordinate of two pictures will be compared, the lowest position is higher layer.

User avatar
moon69
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Sep 18, 2016 6:53 pm
Contact:

Re: Overlay image on entity

Post by moon69 »

Thanks both.

I can easily add a layer to a static object...

Code: Select all

local newPic = {
      filename = BeastMod.mod_directory .. "/graphics/Xpurple.png",
      priority = "extra-high",
      width = 48,
      height = 34,
      shift = {0.1875, 0}
	}
    
local newN = {}
newN.layers = { data.raw["container"]["iron-chest"].picture, newPic }

data.raw["container"]["iron-chest"].picture = newN
Similarly I've managed to add a layer to the electric-mining-drill animations {N, S, E, W}... but it looks like Factorio expects the frame_count in my overlay layer to be the same as the original layer...
"Different frame counts (128 vs. 1) in animation layers of " (path to my png).

I was hoping that "picture" would be common to all entities, but it seems not :(

I think it will be easier just to copy the animation PNGs and just directly add the text to each frame (8 x 8 x 4 directions)!

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Overlay image on entity

Post by darkfrei »

You can make one frame, copy this for 16, 32, 64 files and make sprite sheet of them.

Sprite sheet you can make with imagick in few seconds. Then add new sprite sheet to the old.

Post Reply

Return to “Modding help”