Overlay flash displayobject on Starling Stage3D - actionscript-3

I'm using Starling to build a space shooter game in ActionScript, and I'd like to draw simple lasers using the normal graphics primitives that Flash provides.
How can I set the translation matrix for Flash to be the same as for any given Starling DisplayObject?
transform.matrix = starlingDO.getTransformationMatrix(starlingDO.root);
comes close, but it seems it does not take into account viewport scaling of Starling.

Have you tried using the Starling Graphics Extension here https://github.com/StarlingGraphics/Starling-Extension-Graphics ?
It's easy to use and you don't have to use native Flash display objects.

Related

Calling sprites from texture atlas without using starling in action script 3

Is there anyway to use a texture atlas without using starling framework in flash?
Everywhere i looked for related tutorials it's all about starling framework. I suppose there must be a way to embed the texture atlas without using starling.
The starling movie clip is a bit different from actionscript3 movie clip, so that's where i'm having problems.

Can I use the effects made in Adobe After Effects in the game developed with Adobe Flash Pro and ActionScript 3? If so how?

I am developing a 2D game using Adobe Flash Pro CS 6 and ActionScript3. I am having some trouble in developing some effects e. g. bomb blast, particle effects etc. I want to know, whether I can use After Effects for those and then use them the game. Please suggest me.
There's no problem of using any graphics data from any program in Flash as long as flash can support the file format.
In case of After Effects graphics, you'll probably have to export them as a PNG file sequence, so they'll most probably be pretty large in file size.
To import:
You can either make a movie clip and just import the first image of a sequence with CRTL/CMD + R and Flash with be "smart" enough to suggest to load the other files of that sequence.
If you want, you can load them during run-time, add them to the array/vector, create a Bitmap object and change it's bitmapData property on enter frame/timer to animate it.
If you are decided on using the actual After Effects graphics rather than emulating them using an Actionscript 3 particle effect, I'd actually recommend exporting them as video on an alpha channel and then converting that to flv and then hosting them individually and streaming them in via Netstream and placing them on the proper layer via an addchild. If bandwidth isn't a huge concern here, this would be a good method for achieving this effect.
Here is some documentation on Netstream. http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d4e.html
If this seems like it might achieve the desired result, I can explain further if needed.

Taking advantage of Flash hardware acceleration

My goal is to test Flash 3D environment performance by generating lots of 3D cubes, rotating them and reading FPS.
I know that I can rotate 2D objects in 3D space. For example, I can construct a cube with 6 movie clips, rotating them and putting them together accordingly. Then I can generate lots of these cubes in random x,y,z locations (predefined area in front of viewport), rotate them and read fps.
But then I read about this hardware acceleration and it's unclear to me, when it is activated/used. Certain conditions must be met. I know that it must be allowed by the user (right click->settings->enable hardware acceleration) or if it is embedded through object tag, wmode=direct must be set.
That's from viewers side, but what from developers?
If I draw a simple red rectangle on stage, and user has enabled hardware acceleration, does that mean that graphic information will get rendered on GPU?
I'm reading various sources and "Adobe Flash 11 Stage3D Game Programming" book, and from what I gather, in order to render graphical information on GPU, I have to explicitly call Stage3D class in AS3, then I can draw my 2d/3d objects there.
Which is it - if I want my app to be run in hardware acceleration mode (and its enabled from viewers side), does it happen automatically no matter what the content in my flash file? Or do I have to add the Stage3D class there.
Thank you.
Will be waiting for the answer.
First off: Don't mix up 2 distinct concepts in Flash:
General Hardware Acceleration
This was introduced mainly for video playback in Flash Player 10. I am not sure if it used for graphics at all. It has nothing to do with rendering 3D Graphics directly on the GPU.
GPU Support
With Flash Player 11, Adobe introduced Stage3D. This is an interface through which Flash can render graphics utilizing the GPU, if available. On Windows it uses Direct3D, on Mac OpenGl. The classic Flash DisplayList Graphics API does not support this. You have to go through the Stage3D Api, as explained in the book you have mentioned. To use GPU Support in the browser the embed tag needs the attribute wmode set to "direct". Working directly with the Stage3D Api is not easy and you have to learn the concepts of 3D Programming, Shader Programming, etc. for doing this. There are some libraries which help working with Stage3D. For 3D there is i.e Away3D. If you just need 2D graphics with gpu support, Starling is a very popular framework these days.
Here's a function that converts a movieclip into a bitmap. I use normal flash to create what is going to be shown on screen, then convert the movieclips to bitmaps and delete the movieclips:
private function fConvertClip(pClip: MovieClip, pWidth: int, pHeight: int): Bitmap {
var bd: BitmapData = new BitmapData(pWidth, pHeight, true, 0x00000000);
bd.draw(pClip, null, null, null, null, true);
aBitmaps.push(bd);
var bmp: Bitmap = new Bitmap(bd, "auto", false);
bmp.smoothing = true;
return bmp;
}
Don't turn on the hardware acceleration setting. In general, you control what's on the gpu with code. Bitmapdata is on the gpu so you convert everything that goes on the screen to bitmaps.
gotoandlearn.com has great tutorial videos on this.
You can create anything in normal flash - shapes, gradients, dropshadows, dynamic text, programmed coloring, etc. - and convert it all to bitmaps with programming while your game is running. You don't need to import images/spritesheets/animations. Have artists give you everything in vector. So when the user wants to change the color of a car, you simply convert the code instead of loading/importing a bitmap of the car in red.

How to use starling with Flex, mixed MXML and Stage 3D AS3 code

I need to build a mobile application using starling by creating a FlexMobileApplication project and not an ActionScriptMobileApplication project.
Can i have both MXML controls and Stage 3D (strarling content) at the same time in my app.
Yes you can mix them, but take note of the following:
Starling is a framework for stage3D which runs on a lower layer than the normal Flex (non stage3D) content.
You need to set your Application backgroundAlpha to 0 in order to be able to see the starling content.
You will only be able to display Flex controls over Starling (and not mix them or have the reverse layering)
there may be other points to disuss, as performance and so on but since you picked already Starling you should know the basics by now.
Update
If you need flex like controls on the Stage3D leyer, use Feathers Framework for Starling.
Here are some samples: http://feathersui.com/examples/components-explorer/
Here is the framework wiki: http://wiki.starling-framework.org/feathers/start

Native Flash rendering vs Starling Framework rendering for bejeweled style web game

I am creating a bejeweled style game using flash builder for the web and I am wondering if it would be best (higher framerates, less render intensive, fast on all types of computers) to use the native rendering of actionscript 3 (display lists) or the gpu rendering of the Starling 2D Framework? My reasoning for wanting to use the native flash rendering is because from my research I understand that flash will utilize redraw regions and only redraw portions of the stage that need to be updated whereas starling will re-render the entire stage every frame. In a bejeweled style game there are many static objects and fewer dynamic objects so generally the entire stage does not need to be redrawn every frame, only small portions of the stage. Would it be better for performance to stick with the native rendering calls of actionscript 3 or would it be wiser to use the starling framework to utilize the gpu to accelerate the rendering? Any perspective would be much appreciated. Thanks.
Starling will be faster if you are using images, particularly on mobile.
The static regions can either be rendered as a single Sprite, or you can flatten it at runtime to improve the performance.
If you are drawing, in Starling you'll need to draw to a bitmap and then use that as a Sprite. You'll get better performance if everything is in the same sprite sheet, however.
While it's true that Starling draws every frame, it's a different sort of operation. Here's what actually happens:
1) The textures (images) being used by the app are uploaded to the GPU. This is done once.
2) Each frame, Starling tells the GPU "render this texture at this position with this scale and rotation". This is called a "draw call" but it's extremely fast. The slick thing with Starling is that it can batch these draw calls under certain circumstances to get serious speed improvements.
So yes, everything is "redrawn" each frame, but the GPU's hardware acceleration is used.
On mobile, Starling (or similar) is really the only way to do something at 60fps.