Get masking working properly

This is more of a demonstration of an issue faced while using the Masking functionality of CoronaSDK than a resolution. This would have been posted on the forums for a resolution but it seems that it might not get a response other than a *it is not supported* type response. So,

Here's the scenario.
According to the official documentation, we can apply masks to Images and groups. So, here are the assets we have.
1. A picture of a developer from the Humble Indie Bundle
2. A mask that has a a window at 42, 360 with a width of 684 and a height of 516

so we create a group, create a background that is white, and place the image on it. Then we draw text from top to bottom and apply the mask to this group. So what we should get is a window in the middle of the screen that will show through.

local _W = display.contentWidth
 local _H = display.contentHeight

 local tG = display.newGroup()

 local rect = display.newRect(tG,0,0,_W,_H)

 local mask = graphics.newMask("mask.png")
 local dev = display.newImage(tG, "sad_developer.jpg")

 tG:setMask(mask)
 tG:setReferencePoint(display.TopLeftReferencePoint)
 tG.maskX = 0
 tG.maskY = 0

local i
for i=0,50 do
 local text = display.newText(tG,"item ".. i, 100,i*20)
 text:setTextColor(0,0,0)
end

But when we run this, this is what we get to see...


The concerning thing about this is that if this is how the mask works, it is as good as not having the functionality at all. It is almost as it the mask is trimmed down. If the positioning of the mask was set as x=370, y=200 then this is what the image looks like


The mask was then cropped, if it is not a multiple of 4, it has a funny display, which looked something like

then finally setting it up as multiples of 4, it did display and it almost felt like the maskX and maskY were like the dimensions of the mask, but setting both to a very small number like 10, it stayed at a larger size, thereby dispelling that theory. An easy thing like this has given a lot of pain. It is almost like having something but not having it. I quickly put up a small touch handler to scroll the text items. It so happened that any group or item that has a mask applied becomes exceptionally sensitive and crashes more often than other.

Some other experiments with setting masks and then using a bit of scrolling to create a scrolling list in the middle of the screen ended up with a disaster with the simulator crashing. It is a shame that a very important feature that has been available to developers since the days of text terminals, using "curses" and "conio" (these are not swears, these are the names of the libraries that were available in C for working with text, positioning text and creating windows on screen, something similar to viewports) Windows API had this functionality since windows 3.1, I still recollect reading the first Charles Petzold book on developing a program for Windows 3.1

It is rather stressful, if a developer is not making a physics based game which almost works by itself if you let enough physics bodies interact with each other. If one is seriously interested in rapid native/businessy app then this is a big impediment, there is no stable support for native components, if one is able to create their own components, the API is not supportive to allow that. This is a big segment of enterprise developers that are turning away from Corona as they are unable to do basic simple tasks.

Objective-C *is* painful, the number of lines of code just to instantiate the objects and then retain, release, auto-release, etc not exactly pretty. However creating a message or email is the most easy API offered by Apple, it is in-fact as easy as the UIAlertView or as it is known for those using Corona, the native.showAlert but it still isn't available to developers, this provides such an easy experience to create emails, the recipients can be selected from the Address Book, attachments can be added, etc... NADA!! Not present

ListViews, since the masking does not work properly, it would be quite funny to see the data scrolling up out of the list box co-ordinates onto the other information. It is strange to note that CSS can offer not only all of these clipping, etc functionality, I had seen a demonstration of the Atari logo with an animating ping-pong game all written in *PURE CSS*, it is a shame that this is more powerful than a programming/scripting language. If that be the case then HTML5 seems to be the future as it can do a lot more, it might chew CPU as FLASH used to in the past, but it does provide much more ...

There might be something that is wrong in the way the masks are being used, however given the spartan documentation on these, it is as good as none at all. Even the code samples are helpful, they work... but it is no wonder that there are so many questions on the forums with users that change one tiny bit and the samples stop to work. The daily builds are *ß* versions, however the stable build 591 that was released a while ago also crashes and is quite temperamental, leading to more lost productive time restarting the terminal before getting anything done. I think it is time that the things that were once the pride of the Corona framework, do not become otherwise.

Comments

  1. 100% agreed ... Did ya sent ya thoughts to the Ansca Stuff?

    ReplyDelete
  2. Anonymous, long story short...

    Yes, I have let Ansca know...several times...on not just this but many other issues.

    The focus is the issue... I'd rather not get into more details here, not the right place and the right time.

    ReplyDelete

Post a Comment

Popular Posts