ID:1954649
 
(See the best response by Ter13.)
Code:
flick('specialeffect.dmi',src)


Problem description:
The hair overlays (set to MOB_LAYER+1) are on top of this icon effect, which is not what I want. It covers the target itself, but not anything on a higher layer.

This has to have an easy fix... right?
I think animate() is the proc you want, not flick()
You should not be setting overlays to MOB_LAYER+1. You should be using a variant of FLOAT_LAYER.
In response to Ter13
Just tried with hair set to FLOAT_LAYER and no discernible difference; the effect still sits between hair and mob.
My advice would be to add a blank state to the mob and the hair's icons. Then you can do this:

proc/EffectFlick(atom/ref,effect,duration)
var/oi = ref.appearance
animate(ref,icon=effect,icon_state="blank",time=duration)
animate(appearance=appearance,time=0)


By setting the icon_state to "blank", the hair will now disappear so long as it has a blank state named "blank".

Otherwise, you can do something like this:

var/list/l = overlays
overlays = list()
flick('effect.dmi',src)
sleep(duration)
overlays = l


I'd recommend the first workaround, though.
In response to Ter13
But then my character is suddenly bald during the effect...?

The effect covers half the face-- so low enough to see the cranium, but also high enough that it should cover sideburns and fringes.

If FLOAT_LAYER is the right layer setting (which the mini-nod to it in the reference seems to suggest), and there is no layer control in flick -- I'm inclined to consider this a bug...
Best response
It's definitely not a bug.

Flick() replaces the icon of the object that's been supplied. You shouldn't be using Flick() in this case.

Try this instead:

obj/herpderpeffect
icon = 'specialeffect.dmi'
layer = FLOAT_LAYER


Now, just add the effect as an overlay:

mob.overlays += /obj/herpderpeffect
sleep(duration)
mob.overlays -= /obj/herpderpeffect


Make sure you set the effect's animation to loop 1 time in the icon editor.
Oh dear; thats what I get for using old projects without refreshing my memory. Thanks.

Shame theres not a flick for overlays though.
How do you force the effect overlay to start when you add it to overlays? Do you have to call new() every time? :\

Edit: I had assumed new would resolve the problem mentioned; but even that doesn't work. The icon just starts at the final frame.

mob/verb
TestVerb()
set hidden = 1
usr.overlays += /obj/Smoke
sleep(5)
usr.overlays -= /obj/Smoke

obj
Smoke
layer = FLOAT_LAYER
icon = 'smoke.dmi'
As long as it's set to repeat-once in the icon editor, the appearance will start its animation immediately when added to overlays. If it's set to repeat forever, it'll play based on the world timer.
In response to Ter13
Ter13 wrote:
As long as it's set to repeat-once in the icon editor, the appearance will start its animation immediately when added to overlays. If it's set to repeat forever, it'll play based on the world timer.

That's what I would have thought too. But not the case.

After setting to play once, I've saved the .dmi, closed it and opened it to sanity check saving it.

I've CTRL+U and refreshed obj tree, I've compiled and clean compiled.

It starts at the final state.
Interesting. Let me do some private testing.
In response to Ter13
Hmm quite! I just fiddled with it by checking Rewind: It plays once properly (with the rewind part too; perhaps JUST the rewind part), then starts at the first(final) state only every time thereafter,

Its as though the single loop is being stored in the rsc, and can only ever play once, and then rewind "undoes" that.
But then playing forward again doesn't work once either, jumps straight to final state still.
Okay, I did some testing on my end. It turns out that adding the object prototype inherits the start time of the world, so in order to get a play-once to work as an overlay, you'll want to initialize the object.

var/obj/herpderpeffect/o = new()
mob.overlays += o
sleep(duration)
mob.overlays -= o
In response to Ter13
Aha! So my gut was right with the new() bit (above).

Isn't calling new() best avoided where possible?


Yeah-nah, this doesn't change anything :| (and trying once more with rewind has same outcome mentioned above)
Yes. But the workarounds are pretty ugly. This is one of those cases where you are depending on behavior that pretty much necessitates the use of new().
Are you sure you have the icon set to repeat-once? Because it works just fine for me.
Yes 100% sure; did all the saving, closing & opening, and clean compiling mentioned above -- my results are the same.
Its a 5-frame, single dir, animation. With only one unnamed state.
mob/verb
TestVerb()
set hidden = 1
var/obj/Smoke/o = new()
usr.overlays += o
sleep(5)
usr.overlays -= o

Edit-- apprently we dont allow imgur links, or more likely imgur doesnt permit hotlinks.

http://imgur.com/x2xVVeO

This is a screen cap of my dmi file. I don't know if it means anything, or is intended behaviour, but it runs infinitely in the animation pane to the left, despite setting to play once.
Nope, you are right, it isn't working on my end either.
Page: 1 2