Moving Mask

Hello,

I was wondering if anyone had any insight on moving a mask. Basically i’m creating an endless runner like game. Instead of spawning random platforms as you go I want to create one long level image that the player uses. However, by doing this i’m only using one very long png image. I need to mask out the spots that are transparent gaps in the png. The mask also has to move with the moving platform/level image. Is there a way I could accomplish this? The player will be interacting with the long platform/level image and I just want to get it so they will fall if they run into a gap. 

Any help would be greatly appreciated.

Thanks so much!

Hi @bkove12,

You can move a mask via the .maskX and .maskY properties:

https://docs.coronalabs.com/api/type/DisplayObject/maskX.html

https://docs.coronalabs.com/api/type/DisplayObject/maskY.html

That being said, I personally feel that your approach is going to cause more difficulties than solutions. This includes possibly exceeding the texture size of the device by using one giant .png. Even if you assembled it from several pieces within a group, you may encounter other issues with the mask. It’s up to you, but I would approach this method with caution.

Brent

Thank you! I completely understand, then if this is the case is there another method I could use rather than just spawning platforms randomly? I’m basically trying to have it where I can show an overlay of the level. I just cant figure out how to accomplish this without being able to define exactly whats being shown rather then just random generation. 

Any advice would be greatly appreciated!

-Thanks again!

Why not just layout the level from separate objects like most developers would do? Background, platforms in specific (not random) places, etc. Then just scroll the level as needed.

On that note, how do you intend to detect the location of platforms in regards to the player? Physics? If so, then it’s even more important that you find another non-masked way. Yes, you could technically assemble the entire level as one giant multi-element physics body, but that’s fairly complicated too, and more work than I think is necessary.

Take care,

Brent

I’ve only been working with corona for about half a year so i’m still pretty new. How would I go about scrolling the level? If I could accomplish that than it would work perfectly. I was planning on using physics, yes. Also if I am going to define the level using separate objects is there an easy way of doing this without randomly placing x and y placements until I get the correct spot?

Your advice is very appreciated!

-Thanks!

Hi @bkove12,

I guess the best advice I can give is that you find a way to logically layout the levels using individual objects. If you have the “entire level image”, can you determine the location of the objects by inspecting them in an image editor like Photoshop or similar?

As for scrolling the level, you might want to inspect the “Perspective” library which many Corona developers use for purposes of creating a camera-like system in their games:

https://gist.github.com/GymbylCoding/8675733

Brent

Hi @bkove12,

You can move a mask via the .maskX and .maskY properties:

https://docs.coronalabs.com/api/type/DisplayObject/maskX.html

https://docs.coronalabs.com/api/type/DisplayObject/maskY.html

That being said, I personally feel that your approach is going to cause more difficulties than solutions. This includes possibly exceeding the texture size of the device by using one giant .png. Even if you assembled it from several pieces within a group, you may encounter other issues with the mask. It’s up to you, but I would approach this method with caution.

Brent

Thank you! I completely understand, then if this is the case is there another method I could use rather than just spawning platforms randomly? I’m basically trying to have it where I can show an overlay of the level. I just cant figure out how to accomplish this without being able to define exactly whats being shown rather then just random generation. 

Any advice would be greatly appreciated!

-Thanks again!

Why not just layout the level from separate objects like most developers would do? Background, platforms in specific (not random) places, etc. Then just scroll the level as needed.

On that note, how do you intend to detect the location of platforms in regards to the player? Physics? If so, then it’s even more important that you find another non-masked way. Yes, you could technically assemble the entire level as one giant multi-element physics body, but that’s fairly complicated too, and more work than I think is necessary.

Take care,

Brent

I’ve only been working with corona for about half a year so i’m still pretty new. How would I go about scrolling the level? If I could accomplish that than it would work perfectly. I was planning on using physics, yes. Also if I am going to define the level using separate objects is there an easy way of doing this without randomly placing x and y placements until I get the correct spot?

Your advice is very appreciated!

-Thanks!

Hi @bkove12,

I guess the best advice I can give is that you find a way to logically layout the levels using individual objects. If you have the “entire level image”, can you determine the location of the objects by inspecting them in an image editor like Photoshop or similar?

As for scrolling the level, you might want to inspect the “Perspective” library which many Corona developers use for purposes of creating a camera-like system in their games:

https://gist.github.com/GymbylCoding/8675733

Brent