Looking for examples of adding icons on top of player characters or enemies

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
User avatar
slikts
Burner Inserter
Burner Inserter
Posts: 13
Joined: Mon Apr 11, 2016 2:13 pm
Contact:

Looking for examples of adding icons on top of player characters or enemies

Post by slikts »

I'd like to add icons on top of the things that move, but their definitions are somewhat complex, so it'd be very useful to have an example of how it could be done.

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: Looking for examples of adding icons on top of player characters or enemies

Post by PyroFire »

Code: Select all


events.on_event(defines.events.on_tick,function()
	for k,ent in pairs(ENTITIES_WE_WANT_SPRITES_TO_FOLLOW)do
		for i,sprite in pairs(global.sprite_cache[ent.unit_number])do
			rendering.set_position(sprite,ent.position)
		end
	end
end)
/thread

Bilka
Factorio Staff
Factorio Staff
Posts: 3156
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Looking for examples of adding icons on top of player characters or enemies

Post by Bilka »

Without usage of on_tick, the sprite will follow the target around:

Code: Select all

/c rendering.draw_sprite{sprite="item.iron-plate", target = game.player.character, target_offset = {0,-2}, surface = game.player.surface}
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Modding discussion”