Solarus-Games English Forum

Solarus => Development => Topic started by: Starlock on April 09, 2018, 03:39:39 AM

Title: How to create entity over hero?
Post by: Starlock on April 09, 2018, 03:39:39 AM
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.
Title: Re: How to create entity over hero?
Post by: Christopho on April 09, 2018, 10:57:47 AM
What kind of entity is it? If it is a custom entity, you can use set_drawn_in_y_order(true).
Title: Re: How to create entity over hero?
Post by: Starlock on May 08, 2018, 04:29:26 PM
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
Title: Re: How to create entity over hero?
Post by: Diarandor on May 08, 2018, 05:31:53 PM
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.
Title: Re: How to create entity over hero?
Post by: Max on May 08, 2018, 09:39:16 PM
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?
Title: Re: How to create entity over hero?
Post by: Starlock on May 08, 2018, 10:16:31 PM
Yeah, it looks like making it y+1 made it work. Thanks