Animated movement with AlphaMask problem [SOLVED]

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
computistxyz
Regular
Posts: 58
Joined: Thu Jul 10, 2014 8:35 am
Github: sjgriffiths
Location: Coventry/Norwich, UK
Contact:

Animated movement with AlphaMask problem [SOLVED]

#1 Post 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?
Last edited by computistxyz on Mon Oct 12, 2015 9:47 am, edited 1 time in total.

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: Animated movement with AlphaMask problem

#2 Post by orz »

Why not make the image a composite (using LiveComposite) and just moving that around?

User avatar
computistxyz
Regular
Posts: 58
Joined: Thu Jul 10, 2014 8:35 am
Github: sjgriffiths
Location: Coventry/Norwich, UK
Contact:

Re: Animated movement with AlphaMask problem

#3 Post 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?

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: Animated movement with AlphaMask problem

#4 Post 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.

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: Animated movement with AlphaMask problem

#5 Post 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.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Animated movement with AlphaMask problem

#6 Post 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.

User avatar
computistxyz
Regular
Posts: 58
Joined: Thu Jul 10, 2014 8:35 am
Github: sjgriffiths
Location: Coventry/Norwich, UK
Contact:

Re: Animated movement with AlphaMask problem

#7 Post 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...

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Animated movement with AlphaMask problem

#8 Post 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.

User avatar
computistxyz
Regular
Posts: 58
Joined: Thu Jul 10, 2014 8:35 am
Github: sjgriffiths
Location: Coventry/Norwich, UK
Contact:

Re: Animated movement with AlphaMask problem

#9 Post 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...

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Animated movement with AlphaMask problem

#10 Post 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.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Animated movement with AlphaMask problem

#11 Post 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.

User avatar
computistxyz
Regular
Posts: 58
Joined: Thu Jul 10, 2014 8:35 am
Github: sjgriffiths
Location: Coventry/Norwich, UK
Contact:

Re: Animated movement with AlphaMask problem

#12 Post 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.

User avatar
computistxyz
Regular
Posts: 58
Joined: Thu Jul 10, 2014 8:35 am
Github: sjgriffiths
Location: Coventry/Norwich, UK
Contact:

Re: Animated movement with AlphaMask problem

#13 Post 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?

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Animated movement with AlphaMask problem

#14 Post 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
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
computistxyz
Regular
Posts: 58
Joined: Thu Jul 10, 2014 8:35 am
Github: sjgriffiths
Location: Coventry/Norwich, UK
Contact:

Re: Animated movement with AlphaMask problem

#15 Post 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!

Post Reply

Who is online

Users browsing this forum: Bing [Bot]