it's been a while since I released Starling 1.6, and many interesting additions have found their way into its repository since then! So, what do you think — time for version 1.7, right? Well, I decided to start with a release candidate, as always — just to be sure! 😃
I will describe the major changes & additions of this release below. As always, it would be great if as many developers as possible could update to this version and try it out. If any of you run into problems, just add a post to this thread; I promise I'll look into it as quickly as I can! I really want version 1.7 to be rock-solid. It might very well be the last of the 1.x tree, after all! 😉
But now, let's look at the major new features.
If you've used the "mask" property of the classic display list, you'll feel right at home with this feature. Just assign any display object to the new "mask" property, as shown below. Any display object can act as a mask, and it may or may not be part of the display list.
var sprite:Sprite = createSomeContent();
var quad:Quad = new Quad(100, 100);
quad.rotation = 0.5;
sprite.mask = quad; // <- use the quad as a mask
Those masks are quite fast, since they use the "stencil buffer" of the GPU internally. That means they require two draw calls: one to draw the mask to the stencil buffer, and one to remove it.
One limitation that comes with the stencil buffer is that this type of mask it purely binary: either a pixel is visible, or not. E.g. if you replace the Quad of above's sample with an Image, the result won't change: even if the texture contains only transparent pixels, the mask will be rectangular.
[Oh, one more thing: in order for masks to show up in an AIR application, you have to enable the 'depthAndStencil' flag in the application descriptor.]
Canvas & Polygon
These classes go hand-in-hand with the mask feature. Since masks rely purely on the geometry, not on any textures, you need a way to draw your mask-shapes. And that's what the Canvas class is for.
The API of the Canvas class is similar to Flash's "Graphics" object. This will e.g. draw a red circle:
import starling.display.Canvas; // NEW!
var canvas:Canvas = new Canvas();
canvas.drawCircle(0, 0, 120);
There are also methods to draw an ellipse, a rectangle or an arbitrary "Polygon". (The latter is another new class for the pure mathematical representation of a closed shape.)
Do you want to see it live? The "Masks" scene of the Starling Demo now uses a circular mask.
Finally, here's a pro-tip, if a vector shape just doesn't cut it: I created an extension that allows you to use the alpha channel of a texture as a stencil mask: Texture Mask.
At the end of last year, Adobe introduced a video texture API for AIR. With each release, it's becoming available on more platforms, and now (with AIR 18) it's finally supported on all AIR platforms, most notably iOS and Android (but not the Flash Player). To find out if your current platform supports video textures, simply call:
trace("video texture support?", SystemUtil.supportsVideoTexture);
To make it easy to use those textures, there are two new factory methods on the "Texture" class. Let's first look at displaying the video from the camera:
var camera:Camera = Camera.getCamera();
var texture:Texture = Texture.fromCamera(camera, 1, function():void
Note the last argument of the method, which is a callback. The texture may only be used when that callback has executed. Other than that, it's really straight-forward.
To stream a video from a file or URL, you'll need a little bit more code; that's because Flash's "NetStream" API is a little clunky.
var nc:NetConnection = new NetConnection();
var file:File = File.applicationDirectory.resolvePath("lolcat.m4v");
var ns:NetStream = new NetStream(nc);
var texture:Texture = Texture.fromNetStream(ns, 1, function():void
Such a texture can be used just as any other one, and it even auto-restores on a context loss. Here's a quick sample of such a texture mapped to a rotating cube (in all its animated-gif-glory):
Here's a short list of the most important other changes:
- added 'property hints' to tweening methods (providing easier animation of color and angle)
- added 'ArrayUtil' + 'VectorUtil' classes (for insertion & removal of objects without allocations)
- added 'reverseFrames' method to MovieClip class
- added 'leading' property to TextField class
- added support for latest ATF format updates (coming with AIR 18)
- optimized state changes caused by tinting, reducing draw calls in 'baselineExtened' or higher
- optimized temporary object allocations of DisplayObjectContainer (avoiding 'splice')
- fixed numerous bugs and some memory leaks
As always: the full list can be found on GitHub. A huge thanks to all the contributors of this release!
Now, again: please let me know what you think about these new features — and try them out in your current projects! If there are any problems or incompatibilities, be sure to let me know.
Thanks in advance, guys. I'm looking forward to your posts!