Author Topic: How to create entity over hero?  (Read 3741 times)

0 Members and 1 Guest are viewing this topic.

Starlock

  • Full Member
  • ***
  • Posts: 114
    • View Profile
How to create entity over hero?
« 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.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1194
    • View Profile
Re: How to create entity over hero?
« Reply #1 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).

Starlock

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: How to create entity over hero?
« Reply #2 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

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: How to create entity over hero?
« Reply #3 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.
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Max

  • Sr. Member
  • ****
  • Posts: 276
    • View Profile
Re: How to create entity over hero?
« Reply #4 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?

Starlock

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: How to create entity over hero?
« Reply #5 on: May 08, 2018, 10:16:31 PM »
Yeah, it looks like making it y+1 made it work. Thanks