Page 1 of 1

Defining a function that returns an animated image

Posted: Mon Apr 20, 2020 9:10 am
by GhastlyEster
I've been using animated images to make sprites blink and talk.

Code: Select all

image linnea neutral blinking:
    "linnea neutral blinking frame_1"
    3.0
    "linnea neutral blinking frame_2"
    0.016 * 2
    "linnea neutral blinking frame_3"
    0.016 * 4
    "linnea neutral blinking frame_2"
    0.016 * 4
    repeat
And I would save a lot of time if I could make a function that returns the animation instead of declaring one for each expression.

Code: Select all

show get_blinking_animation("linnea", "neutral")
Tried to write a function like this, but I keep getting syntax errors because I don't know how images work or how the animation language works. Is it possible? How would I do it?

Re: Defining a function that returns an animated image

Posted: Mon Apr 20, 2020 12:29 pm
by rames44
At present, there isn’t a programmatic interface for ATL. I’ve done something like this in the past using a Creator Defined Displayable, however. The CDD can build the image names dynamically, convert them to Displayable, and then render the correct one at the correct time using the time base passed into the CDD’s render() method.

Re: Defining a function that returns an animated image

Posted: Tue Apr 21, 2020 9:37 am
by GhastlyEster
Bummer that you can't use ATL like that. Would you share the code for your creator defined displayable? I'll give it a try because I would save so much time.

Re: Defining a function that returns an animated image

Posted: Tue Apr 21, 2020 11:00 am
by MaydohMaydoh
Transforms can take arguments, so you could try using the contains statement in the image and pass a name to the transform.

Code: Select all

transform blinking(name):
    "{} blinking frame_1".format(name)
    3.0
    "{} blinking frame_2".format(name)
    0.016 * 2
    "{} blinking frame_3".format(name)
    0.016 * 4
    "{} blinking frame_2".format(name)
    0.016 * 4
    repeat
    
image linnea neutral blinking:
    contains blinking("linnea neautral")
    
image linnea happy blinking:
    contains blinking("linnea happy")
    
...etc...

Re: Defining a function that returns an animated image

Posted: Wed Apr 22, 2020 2:01 am
by GhastlyEster
Thanks! Tried this and it totally works. My game will be done like, SO fast.