Is AS 3 capable of supporting a game with 600 + rotating images? - actionscript-3

I made a simple game where squares collect crystals and bring them to a base and replicate. They are just .png images that rotate and move and yet when their number becomes greater than 500, the game starts to lag out. In Java I'm able to do a similar thing with 30,000 units. Could I be doing something wrong or is Flash just not that capable?
I'm using Flash Builder.
I get the image like this:
[Embed(source="../lib/red.png")]
public var redImgClass:Class;
public var redImg = new redImgClass();
Then I pass redImg to a "unit" class which takes an instance of "Bitmap"
I change its "rotation" and x,y members every frame.
Am I doing something wrong here?

you're not using Stage3D. If you use Starling, ND2D or write your own Stage3D wrapper you'll be able to get better performance.
You can also take a look at Jackson Dunstan's blog, this post is especially helpful: http://jacksondunstan.com/articles/2279

Another possible answer is to use blitting, that is, use a single Bitmap object to draw everything on via copyPixels(). This requires that your rotating crystal PNG be replicated into a sequence of rotated images, which you then use instead of directly changing rotation property. This approach is more performance-friendly, and does not depend on video card performance like Stage3D does.
Adobe's manual on blitting
Some discussion on blitting done by game devs

Daniel's answer is correct in that you should use the Stage3D APIs for greater performance. He didn't however mention that you should seriously consider using Starling, which wraps the Stage3D API with much easier to use classes:
Learn more about Starling here.
Example of the level of performance you could expect from Stage3D.

Starling is what you`re looking for (http://gamua.com/starling/)

Related

TweenEngine library vs libGDX Interpolation class

I'm developing a game based on the libGDX framework in eclipse that will have smoothly movements between my entities, so for that, I have used TweenEngine (and it is working nice), but recently I found that libGDX have its own class for interpolations.
I know both are for tweening (or for nice and smoothly animations), and I just want to know if there are technical difference or limitations between this 2 options basically because if both are the same, I would opt for the second one since it is already inside libGDX.
From one side there's generally better to use included tools because of integration and final application size (not saying of setting up the environment or exporting project problems).
On the other hand please notice that Libgdx Interpolation starts to be useful only when you are using it with Scene2D actions. And here is the problem in my opinion because you must implement stage and actors mechanisms - which is good idea by itelf but can be almost impossible if you have created almost whole application without it.
Then I would recommend you:
choose Scene2D actions + Interpolation easing if you are able to implement Scene2D in your project and the easing actions are only reason you want to use Tween Engine
choose Universal Tween Engine if you want to stay independent of new machanisms and use Sprites etc in traditional way

How to make efficient dynamic mask in starling

I'm trying to make an interactive book for tablets with animations and page flip.
I'm using starling framework.
My idea of page flip is to mask 2 instances of next page with 2 static quads which are moving and rotating (it works great on pc/mac, but slow on tablets).
Using PixelMask is slow/very slow(10-20fps). Using clippedsprite is fast(40-50fps) but cant rotate the mask.
Are there any other options?
EDIT:
During my search I've found the idea of shaders (AGAL in ActionScript3), but I'm not familiar with this. Is it possible to simulate masking by the use of GPU shader?
EDIT2:
This problem was experienced on iPad1, on iPad3 its 60fps :) Dont know how its going to work on iPad2 and iPad4
I'm pretty sure AGAL is the ultimate answer!
But easiest, and still very good, solution is the smart use of ClippedSprites
(Sprites with clipRect since Starling 1.3+)
I've managed to achieve almost static 60 fps on iPad1.
Just needed to remove filters and stop/flatten animations inside Objects!
Filters are massive performance killers!
You can find here a mask class based on FragmentFilter. i got better results with it. But if you want to implement a PageFlip, you can use this class. And here is an improved version of the pageflip with interactive corners. Hope it helps you :D

is there a way to bring stage3d to front?

i tried the hello example on the adobe site.
http://www.adobe.com/devnet/flashplayer/articles/hello-triangle.html
it works, but the context3D seems work on the stage's background in the lowest level. if i draw anything it will cover the 3d context.
i want to bring it to front or set it to a certain level. how can i do that?
also i was told if use 2d api and 3d api together , it will lower the performance of 3d,is it truth?In my works ,i still need 2d api ,for example, drawing the textfield .
Everything goes like this (from bottom to top):
StageVideo (1 or more instances) > Stage3D (1 or more instances) > Your regular display list.
And yes, regular display objects may degrade performance of Stage3D, therefore it may be better to use Stage3D alternatives of those. Some Stage3D accelerated frameworks already has some of those built in (like TextField in Starling).
No, you can't bring it to front.
2d and 3d not relates to each other. But of course, if you write 2d stuff that eat 100% of cpu, you'll get overal slow performance.
the only way is to get from the bottom layer of stage3D instance the rendered bitmap and display it on top of you displayList.. but it should work on each frame, thing that will affect the performance a lot and of course no mouse interaction... this solution will work only to display rendered scene on top of stage3D.. just a simulation

Bigger stage vs scrolling background

I'm making a flash game, and I can't decide to use a bigger stage or a smaller one, with scrolling background to make it run smoother. I's going to be some kind of strategy game if it matters.
Thanks
One option is to have a bitmap object the size of your stage for example 800x600, then draw your objects into the bitmapdata of that bitmap using copyPixels this is known as blitting and is pretty fast.
Another option is to just use the flash display list and add every object as sprites onto the stage.
Second method is easier to handle in terms of mouse events and stuff.
My advice is to start with the second option and see if performance is enough, if not go with option 1.
There are many, many variables that determine the performance of your application.
To answer your question, a smaller stage area will make your program run faster. The amount of difference will depend on the way your application deals with display objects. Flash will not render things that are completely outside the stage bounds. So keeping only those objects that are needed at any given time on the stage is a good practice.
using flash player 11's new stage3D features (even for 2D stuff) will likely make your game very smooth. Lots of good frameworks out there that can take care of the low-level stuff if you don't want to get into it. For 2D, starling is very easy to get started with, and seems to be Adobe's favored framework.
At a bare minimum, make sure you use GPU acceleration in your output/compiler options.
There are LOTS of other tips for optimization people could get into, but that is better suited for google searches as Stackoverflow is about specific questions.

Any known solutions for Image Differencing in Actionscript?

I'm working with a few programming buddies to create an AS interface to the kinect and one problem we're running into is image differencing. We need to be able to throw out image data that doesn't change from image to image so we can pin-point only things that are moving(i.e. people).
Anyone have any experience with this or a direction we can go?
I would consider creating a pixel bender shader to find the difference and also do any other math or tracking. Pixel bender gets its own thread outside of the normal flash player so you can get some more horse power for your setup. Pixel Bender shaders can be applied to bitmaps, vectors, or video so I think it is perfect for this project. Good Luck!
http://www.adobe.com/devnet/flash/articles/pixel_bender_basics.html
And is is a full collection of shaders including difference
Take a look at the threshold method on BitmapData.
It'll allow you to do this stuff. Their docs have a simple example so check that out.
It might be a long shot, and this is just me rambling, but in sound theory (strange how I'm relating it to image cancellation, but here goes...) the concept of cancellation is when you take a wave sample and add its inverse. It's how you make acapellas from instrumentals + originals or instrumentals from acapellas + originals.
Perhaps you can invert the new image and "normalize" the two to get your offsets? I.e. the first image is 'black on white' and the second image is 'white on black', and then detect the differences for the bitmap data. I know I did a similar method of finding collisions with AS3 a few years back. This would, in theory, cancel out any 'repeating' pixels and leave you with just the changes from the last frame.
With BitmapData your values are going to be from 0 to 255, so if you can implement a cancellation (because a lot of parts of the image are going to stay the same from frame t frame) then you can easily find the changes from the previous frame.
Just a thought! Whatever your solution is it's going to have to be quick in order to beat the flash runtimes' slow speeds. Your Kinect read FPS rate will be greatly hindered with bad code.
Here is some frame differencing code I wrote awhile back. It uses bitmapData: http://actionsnippet.com/?p=2820
I also used this to capture moving colors in a video feed: http://actionsnippet.com/?p=2736