ID:1467998
 
(See the best response by Ter13.)
For example i made a 32x32 base and a 32x32 hair. But the hair is not ontop of the head or somewhere i don't want it how do i make the hair go little bit more up in coding?
Best response
You will need to apply a pixel offset. This is how I handle overlays, for the most part.

overlay_obj
parent_type = /atom/movable

New(var/icon/icon=null,var/layer=FLOAT_LAYER,var/pixel_x=0,var/pixel_y=0)
src.icon = icon
src.layer = layer
src.pixel_x = pixel_x
src.pixel_y = pixel_y


And then to add it to the mob of choice:

var/overlay_obj/o = new/overlay_obj('hair.dmi',FLOAT_LAYER,0,16)
src.overlays += o
In response to Ter13
not meaning to revive an old thread,but I posted a bug the other day and this seemed to fix it.

Edit: Okay disregard the old thread portion! Was thinking this was still 2013! Ooops
Weird. If there is some kind of inaccuracy going on in object prototype overlays, keep trying to identify the root of the problem. I'd be interested to get confirmation what the root cause is, and determine whether it is indeed a bug.
In response to Ter13
Just to let you know I think it has something to do with layers I have had some other weird little like overlay glitches by not setting a layer.
Interesting. Are you using a different map mode?
In response to Ter13
No BYOND default.
...Huh. The other idea I had might be that you were accidentally saving overlays and misapplying them somehow.
I don't think I could be. Before I started doing it this way.

mob
icon='mob.dmi'
mob
proc
Hair()
var/H = pick("Spikey","Short")
switch(H)
if("Spikey")
src.overlays+=new/obj/Spikey_Hair
if("Short")
src.overlays+=new/obj/Short_Hair
mob
Login()
src.Hair()
src.loc=locate(1,1,1)

obj
Short_Hair
icon='overlay.dmi'
Spikey_Hair
icon='overlay2.dmi'
turf
grass
icon='grass.dmi'


I mean I get a weird glitch just doing that. So it beats me as what to be the cause. The overlay will spawn below the actual icon unless I set it to FLOAT_LAYER
Oh. That's not a glitch at all.

By default, objs have a layer of 4. (OBJ_LAYER)

By default, mobs have a layer of 5. (MOB_LAYER)

Thus, any object that is added to the overlays of a mob will always underlay the mob's default icon because the object itself is defaulted to a lower layer than the mob.

FLOAT_LAYER is a special negative value that indicates that the overlay or underlay should be relative to the layer of the owning object.

Meaning, if it's in an overlay list, it will always be the absolute minimum value above the mob's layer, and if it's in an underlay list, it will always be the absolute minimum value below the mob's layer.

You can also specify additional arbitrary offsets to FLOAT_LAYER by subtracting from it. Any object in FLOAT_LAYER will be reordered based on precedence of their negative layer value.

So for instance:

#define ARMOR_LAYER FLOAT_LAYER-1
#define CLOTHES_LAYER FLOAT_LAYER-2


In this case, adding an item with armor layer and clothes layer, regardless of order added to the overlays list, will force the armor to layer over the clothes. Why? Because -1 is greater than -2. As such, anything with a layer of -1 will be rendered above anything with a layer of -2.

However, this does not mean that armor will directly increment or decrement the layer of the base mob.

So, since MOB_LAYER = 5, adding an object with ARMOR LAYER will not equate to the armor being on layer 3. On the contrary, it will act as though the armor is on layer 5, but all other overlays that share the FLOAT_LAYER value in any way, will sort themselves based on the additional value applied to float layer. So in our case, FLOAT_LAYER-X will always be above layer 5, but below layer 5.0001. Subtracting from float layer only matters with regard to other objects in the overlays/underlays list that use float layer on the same object.


Just to be clear, though:

FLOAT_LAYER is by default, -1. Any value below zero will position the element if it is an overlay according to float layer rules.

If it is not being rendered as an overlay, setting a negative layer value will treat -1 as the layer below 0 and above -2, as an arbitrary layer.

Any value that is not <0 and is part of an overlay/underlay list, will be treated as an arbitrarily ordered layer.

Make sense now?
In response to Ter13
Well that's one problem down. Thank you for that information. Also I still have yet to run into that problem again I had posted in the bugs report. So I really have no idea what the deal was!