Page 1 of 1

Animated movement with AlphaMask problem [SOLVED]

Posted: Fri Sep 25, 2015 9:11 am
by computistxyz
I've got a small sprite on the screen which I'm masking in certain areas of the screen with a screen-sized separate mask image using AlphaMask(). But, how can I then animate the small sprite to move around the screen without changing the position of the screen mask image?

If I simply use:

Code: Select all

image spriteMasked:
    AlphaMask("sprite.png", "mask.png")
    pos (0, 0)
    linear 2.0 pos (500, 500)
Then the entire AlphaMask image will of course move. In short, how is it possible to access these two AlphaMask components separately for the sake of animation?

Re: Animated movement with AlphaMask problem

Posted: Fri Sep 25, 2015 12:11 pm
by orz
Why not make the image a composite (using LiveComposite) and just moving that around?

Re: Animated movement with AlphaMask problem

Posted: Fri Sep 25, 2015 12:25 pm
by computistxyz
orz wrote:Why not make the image a composite (using LiveComposite) and just moving that around?
I'm not sure I understand how that would help. Do you mean putting the small sprite in a LiveComposite, such that:

Code: Select all

AlphaMask(LiveComposite( (1920,1080), (0,0), "sprite.png") , "mask.png")
Or put the entire AlphaMask object into a LiveComposite?

Re: Animated movement with AlphaMask problem

Posted: Fri Sep 25, 2015 12:34 pm
by orz
I misunderstood your problem - skimmed too fast. Thought you were saying only one part was moving when you wanted all of it to move, not the opposite.

I'll have to do some reading on what exactly AlphaMask is and does.

Re: Animated movement with AlphaMask problem

Posted: Fri Sep 25, 2015 5:41 pm
by orz
Okay, you'll have to do some rethinking as to how you've coded it. The point of AlphaMask is to take an image, a mask, and to spit back one image - not something with multiple components.

If you need them to be separate components, you have to program it *as separate components*.

How to do it exactly? I don't know how you're planning on having it work in the long run, so I can't answer that.

Re: Animated movement with AlphaMask problem

Posted: Fri Sep 25, 2015 6:16 pm
by Onishion
I'd like to know an easy way to do this as well, but there might be a cheap workaround to it, if this would work for your project.

1. Take the background you're using.

2. Duplicate that background, and display the second copy of it on a layer above the object you want to move around.

3. Alpha that second "background" to have holes wherever you want to see your object, and be opaque where you want the object invisible.

That way, it should provide the effect you're describing.

Re: Animated movement with AlphaMask problem

Posted: Fri Sep 25, 2015 9:28 pm
by computistxyz
Onishion wrote:I'd like to know an easy way to do this as well, but there might be a cheap workaround to it, if this would work for your project.

1. Take the background you're using.

2. Duplicate that background, and display the second copy of it on a layer above the object you want to move around.

3. Alpha that second "background" to have holes wherever you want to see your object, and be opaque where you want the object invisible.

That way, it should provide the effect you're describing.
That's an interesting workaround. However, in my case, there's a number of different backgrounds and animated sprites all preexisting behind this masked animated element, so it's not as simple as duplicating and masking a single background...

Re: Animated movement with AlphaMask problem

Posted: Fri Sep 25, 2015 10:12 pm
by Onishion
That's an interesting workaround. However, in my case, there's a number of different backgrounds and animated sprites all preexisting behind this masked animated element, so it's not as simple as duplicating and masking a single background...
Hmm. Well I haven't messed with the alpha thing much, so I'm not sure if this would work, but it might.

1. Take the background, and make a composite image that is the background AND all images that you want to be behind the moving object.

2. Duplicate that image, use it as the foreground with the alpha thing going on, with the moving object sandwiched between.

I have no idea whether parts of that would fail, but it might work.

Re: Animated movement with AlphaMask problem

Posted: Mon Sep 28, 2015 8:54 am
by computistxyz
I've attempted a slightly different approach by defining the sprite image separately like so:

Code: Select all

image sprite:
    "sprite.png"
    #Animation data here

image maskedsprite:
    AlphaMask("sprite", "mask.png")
Which works as expected. However, whilst transforms such as zoom and rotate can be applied and even animated with linear in that preliminary image definition, positional transforms (namely, pos and offset) used in exactly same way have no effect. I'm not entirely sure as to why this is - perhaps someone with a deeper understanding of the AlphaMask function could offer an explanation for this behaviour?

Onishion wrote:
1. Take the background, and make a composite image that is the background AND all images that you want to be behind the moving object.

2. Duplicate that image, use it as the foreground with the alpha thing going on, with the moving object sandwiched between.
I can imagine that working; the only problem is that this masked animation occurs quite regularly at various points, with no particular way of knowing what else may or may not be present behind it on the screen in any given instance...

Re: Animated movement with AlphaMask problem

Posted: Tue Sep 29, 2015 12:14 am
by Onishion
Which works as expected. However, whilst transforms such as zoom and rotate can be applied and even animated with linear in that preliminary image definition, positional transforms (namely, pos and offset) used in exactly same way have no effect. I'm not entirely sure as to why this is - perhaps someone with a deeper understanding of the AlphaMask function could offer an explanation for this behaviour?
I know I've run into similar issues with LiveComposite. If I try to insert animated objects into Live Composites, they sometimes don't work right, in exactly that way. Certain image compositing mechanisms seem to be squirly when it comes to positional data.
I can imagine that working; the only problem is that this masked animation occurs quite regularly at various points, with no particular way of knowing what else may or may not be present behind it on the screen in any given instance...
Hmm, yeah, it would get complicated.

Re: Animated movement with AlphaMask problem

Posted: Tue Sep 29, 2015 1:42 am
by nyaatrap
It looks you want to mask a layer, not an image. It can be done when you show an image on a higher layer then apply an alpha transition on the layer.

Re: Animated movement with AlphaMask problem

Posted: Tue Sep 29, 2015 9:57 am
by computistxyz
nyaatrap wrote:It looks you want to mask a layer, not an image. It can be done when you show an image on a higher layer then apply an alpha transition on the layer.
That sounds like it could work!

I've gotten this so far:

Code: Select all

init python:
    config.layers = ["master", "transient", "screens", "overlay", "sprites"]

define spriteMask = AlphaDissolve("mask.png", delay=1.1, alpha=True)

image sprite:
    #blah blah animation goes here

label start:
    show layer sprites at spriteMask
    show sprite onlayer sprites
The actual masking effect works correctly in tandem with the animations when tested separately. However, upon the show statements, I get the following critical error:

Code: Select all

TypeError: __init__() got multiple values for keyword argument 'delay'
The fact the masking transformation is actually a transition strikes me as odd; I've just thrown in a suitable value of 1.1 for 'delay'. But, it doesn't seem to like this.

Re: Animated movement with AlphaMask problem

Posted: Tue Oct 06, 2015 5:19 am
by computistxyz
TARDISam24 wrote:
nyaatrap wrote:It looks you want to mask a layer, not an image. It can be done when you show an image on a higher layer then apply an alpha transition on the layer.
That sounds like it could work!

I've gotten this so far:

Code: Select all

init python:
    config.layers = ["master", "transient", "screens", "overlay", "sprites"]

define spriteMask = AlphaDissolve("mask.png", delay=1.1, alpha=True)

image sprite:
    #blah blah animation goes here

label start:
    show layer sprites at spriteMask
    show sprite onlayer sprites
The actual masking effect works correctly in tandem with the animations when tested separately. However, upon the show statements, I get the following critical error:

Code: Select all

TypeError: __init__() got multiple values for keyword argument 'delay'
The fact the masking transformation is actually a transition strikes me as odd; I've just thrown in a suitable value of 1.1 for 'delay'. But, it doesn't seem to like this.
Bumping for increasing urgency. Could someone with a more in-depth knowledge of layers/AlphaDissolve perhaps have any explanation for this situation?

Re: Animated movement with AlphaMask problem

Posted: Wed Oct 07, 2015 12:03 am
by PyTom
So, the problem is that you're trying to use AlphaDissolve, but it's a Transition, not a Transform - and so won't work. I think want you probably want is an AlphaMask transform. That doesn't exist in the form you want, but we can easily create one.

Code: Select all

init python:
     def SpriteMask(d):
         return AlphaMask(d, "mask.png")

show layer sprites at SpriteMask

Re: Animated movement with AlphaMask problem

Posted: Mon Oct 12, 2015 9:47 am
by computistxyz
PyTom wrote:So, the problem is that you're trying to use AlphaDissolve, but it's a Transition, not a Transform - and so won't work. I think want you probably want is an AlphaMask transform. That doesn't exist in the form you want, but we can easily create one.

Code: Select all

init python:
     def SpriteMask(d):
         return AlphaMask(d, "mask.png")

show layer sprites at SpriteMask
Brilliant - that's working perfectly, thanks!