How to create entity over hero?

Started by Starlock, April 09, 2018, 03:39:39 AM

Previous topic - Next topic
So I'm trying to create an entity that overlaps the hero,but whenever I attempt this the hero is always on top. The only way I've found to fix this problem is by setting the entity to the hero's layer + 1, but this leads to other graphical issues, so it really needs to be on the hero's layer.

What kind of entity is it? If it is a custom entity, you can use set_drawn_in_y_order(true).

Hey, sorry for the late response I've been busy with college.

This doesn't really seem to work. Sometimes the entity will appear on top and other times it won't. This is the code for the entity, it's purpose is to follow directly on top of the hero.

Code ( lua) Select
local entity = ...
local map = entity:get_map()
local hero = map:get_hero()


function entity:on_created()
  local sprite = self:create_sprite("hero/swordflame")
  self:set_traversable_by(true)
  self:set_drawn_in_y_order(true)

    local kai_movement = sol.movement.create("target")
    kai_movement:set_target(hero)
    kai_movement:set_speed(1000)
    kai_movement:start(entity, function()
    end)

end

function entity:on_update()

        local x, y, layer = hero:get_position()

entity:set_position(x, y, layer)

end

You should check (and study) the code of the custom shield of the project CoS. I use 2 custom entities following the hero: one to draw the shield below, and the other to draw the shield above. I use a trick that is not obvious.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

I'm not 100% sure how y-order works, but would you maybe want the entity to follow the hero's coordinates, but Y+1 so it's slightly "lower"/south/in-front-of the hero?

Yeah, it looks like making it y+1 made it work. Thanks