Page 1 of 1

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

Posted: Sun May 10, 2020 11:18 am
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.

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

Posted: Sun May 10, 2020 12:12 pm
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

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

Posted: Sun May 10, 2020 12:34 pm
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}