Posts Tagged Android
Hell yeah! Crazy day. Spent all day figuring stuff out, now I’m pretty tired but I have to share my findings.
NME, a cross-platform solution
So, I am looking for a true cross platform development solution that will give me output for iOs, Android and Web (Flash). Using Flash and Air is too slow for me, but I do like ActionScript 3 a lot so NME seems like the logical solution. What is exactly NME? You know what? I don’t really know. It uses haXe and I think haXe is a programming language based on ActionScript. NME can compile both to Flash and C++ (and many more). That is as much as I could figure out, but I’ll keep digging.
Installing haXe and NME seemed pretty straight forward and it seemed to have worked, the only trouble I had was with FlashDevelop. Syntax high lighting is all off and it doesn’t seem to find where the classes are. But it compiles so I could at least get some stuff done.
From ActionScript to haXe
Actually that part isn’t that bad, there are little differences which you can find on this cheat sheet, but there are also concepts that are totally oblivious to me like the Dynamic type. But I just rolled with it and everything kept working, so this is something I’ll figure out later too. Little annoying thing every class needs a constructor (but at least the function name is only “new”) and if you extends something, you have to call super. Also, I noticed that on the NME Sprite (nme.display.Sprite), there is no rotationY property (well this is particular to NME, and I have never used rotationY before until 2 days ago, so I find this very funny).
On to RobotHaxe
Well I can’t really do anything without Robotlegs. I like how simple things are with it and well organized, so if I was going to move to another language, it needed to have Robotlegs. Period. Well I also need to be able to embed Fonts, have a Tweening engine and something to replace timeline animations, Robotlegs is the most important. Turns out there is a port to haXe called RobotHaxe made by David Peek. The only problem, there is no documentation, no examples, no tutorials… I decided to give it a shot anyway, how hard could it be? Kinda hard… haha. Anyway I got it to work, not sure it is the best way to do it, but it works (for what I have tested). I made this test RobotHaxe project using FlashDevelop and NME, not sure what it implies but I think it can be useful to people so I am giving it to you.
Git and GitHub
You might know that I am making a game for the iPad and it’s nearly done. The thing is, I also want to publish it on the web, you know, make money from sponsorship too. Actually, I think it might be the only way I make money with the game as the iPad app market seems really hard. Plus it will also cost me money to publish in the Apple app store (developer account), so I think I might be loosing money going that way. Anyway, I was testing my game for the web first and everything was working fine. I tested on the iPad after and that is when things started to get hairy.
Yeah, an iPad (iPad 2) is not a full fledged computer (funny to say this considering my first computer was a 486), so it is not as fast. Well I have seen some pretty crazy shit on the iPad, like the Dead Space game so I guess it can be pretty strong. This only means that the Flash player isn’t that great on it, probably because it doesn’t use the GPU. So as I was testing my game on the iPad, it started out working really great, but as the game went on, more and more objects got drawn onto the screen and that is when the performance started to go down. So I set out to optimize my code.
Object creation in Flash is an operation that is costly and since I hadn’t optimized anything yet, I was recreating every object on the screen every frame. There is a possibility of having 240 objects on the screen at the same time, so that’s a lot of object creating every frame. To minimize this, you can do object pooling, which is having a pool of already created objects and change their properties instead of creating new ones. I did just that and it went really fast to implement. The thing is, when I tested it on the iPad, it made no difference at all.
Another thing that is heavy on the CPU in Flash is updating graphics, so I tried to optimize that part. Blitting is a technique by which you compress all your visual into only one Bitmap that you draw on the screen. So instead of having multiple display objects being redrawn (in my case 240), you only have one. Read more about blitting here. Blitting doesn’t fit well with every project (like those relying on vector graphics) , but mine was based on Bitmaps and didn’t have a lot of rotations (it did, but only 90 degrees one) so I could easily do it. I was pretty sure that this would help a lot, but it actually did nothing noticeable. I was a bit baffled here, maybe my redrawn zone is too big… It is a game for iPad so I have a full resolution of 1024 x 768, maybe that is too heavy for the Flash Player.
So if it wasn’t the creation of objects or the graphics, than maybe it was the code. I had used Arrays everywhere cause it is just simpler to use than Vectors, so I changed them all. I also did some loop optimization and replaced some divisions by multiplications ( like /2 to *0.5). Also didn’t change anything…
My last resort was to change the game dynamics so that the game is less intensive on the CPU and that is the only thing that made any impact on performance. My game is a puzzle, so I removed 3 rows and 1 column from it thus reducing the possible maximum number of object on the screen (and also the redrawn region size, and probably also the number of computations) by 20%.
I’m pretty sad at this point, changing the game dynamics to optimize is not a really good decision, it’s kinda like saying let’s make the game less fun to make it run faster. What I liked about Flash is that I could compile for the web, iOs and Android with limited changes (in this case all I changed was different layouts based on size (height and width) of the game). Turns out it is not fast enough on iOs (iPad). Maybe when they put Stage3D on iOs that will do it, but till than there is no true cross development platform. I meant to look into Corona, but it does only mobile. And I really don’t want to fall into the HTML5 mess. I would really like to hear about a dev story about HTML5 and a game built for web and mobile and most importantly how much time it took to do.
Back in February I wrote a post in which I stated that the future of Flash wasn’t so bright, well if you ask me what I think about that right now, I would say that it ain’t so bad. Why? Well, the roadmap for new features seems pretty exciting and also the array of stuff you can do with Flash is astonishing.
Molehill API (Hardware accelerated 3D)
After AdobeMax, I wanted to write a post just about this topic but I continually postponed it… but now it seems to fit perfectly with my second point so here it is. Molehill is some new low level API that enables some function calls to be hardware accelerated. Basically it permits some code to be sent to the video card instead of the processor, thus enabling us to do more crazy 3D stuff. Here is an example of what has been done with it and it is not even released yet:
If you’re a Flash Developer and this doesn’t excite you, I don’t know what will. Actually, I don’t think I looked forward so much for the next version of the player since I started using Flash. I started at FlashMX 2004, so Flash 8 gave us the filters and BitmapData; computers weren’t powerful enough to do the cool stuff with filters at the time, and I don’t know, BitmapData is pretty useful but I kinda didn’t know what I could do with it then. After that came Flash 9 with ActionScript 3, well that was nice but it took so much time for people to switch from ActionScript 2 to 3 that the excitement was kinda mitigated. Flash 10 was to follow with nothing really to offer… maybe Vectors are cool but they didn’t really impact anything. Flash 10.1? supposedly it is faster, doesn’t seem to be a game changer, the mobile stuff is cool but I wanted more for the web. Now Molehill is a very different ball game. Molehill will allow us to do way more than what we could before, both on the web and on the mobile. Gaming wise it is very easy to foresee how it will be used, but what I am mostly interested in is how it will be used for rich experiences, for rich internet applications or for data-visualization. It is the possibilities of this new technology to be used in unsuspected ways that makes it very exciting. Now, all we have to do is wait for it to come out. I bet you that the adoption rate will be very fast.
Maybe one of the good consequence of Apple saying no to Flash is everybody else saying yes to it to differentiate themselves. So yeah, Flash on a shit load of mobile ( Android, BlackBerry (PlayBook), Windows Phone 7), Flash on the TV (GoogleTV) and now Flash on the cloud (ChromeOS). It is seeing how easy it was to add a Flash app to the Google Chrome Web Store that made me realize that I was lucky to have liked Flash and have made it my job. I have so many possibilities now, from gaming to advertising (banner ads, ok I never want to do this again even if you threaten me with a gun), from website to mobile application, from your TV to the cloud. If you ever get bored as a Flash Developer there is still so many things you can do. So yeah, that did put a smile on my face and made me realize that Flash’s future wasn’t so bleak.
And to those who said that Flash would die, well it’s going to be goddamn hard to kill now on all these media… Cheers!