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

Starlock

  • Jr. Member
  • **
  • Posts: 90
    • 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: 1104
    • 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

  • Jr. Member
  • **
  • Posts: 90
    • 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
  1. local entity = ...
  2. local map = entity:get_map()
  3. local hero = map:get_hero()
  4.  
  5.  
  6. function entity:on_created()
  7.   local sprite = self:create_sprite("hero/swordflame")
  8.   self:set_traversable_by(true)
  9.   self:set_drawn_in_y_order(true)
  10.  
  11.     local kai_movement = sol.movement.create("target")
  12.     kai_movement:set_target(hero)
  13.     kai_movement:set_speed(1000)
  14.     kai_movement:start(entity, function()
  15.     end)
  16.  
  17. end
  18.  
  19. function entity:on_update()
  20.  
  21.         local x, y, layer = hero:get_position()
  22.  
  23. entity:set_position(x, y, layer)
  24.  
  25. end

Diarandor

  • Hero Member
  • *****
  • Posts: 959
  • 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

  • Full Member
  • ***
  • Posts: 105
    • 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

  • Jr. Member
  • **
  • Posts: 90
    • 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