Posts Tagged iPad
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.
YEAHH! Pretty nice is the feeling you get when you see your game for the first time on the medium it is supposed to be. Yesterday I dwelled in the mysteriously complicated world of signing applications for the Apple App Store. 6 hours it took me to finally get my game on my tablet ( by the way I didn’t buy the iPad, I won it ). I would say that 2/3 of that I was stuck in Apple developer center where you have to do numerous steps and get many files in order to sign your app / game. The last third came from converting one certificate to something Flash can use to compile a .ipa file.
For that step you can either do it on OSX or on Windows differently and since I have both installed on my machine, I thought I would do it the easy way ( what I thought would be) on OSX, but for some reasons Keychain access didn’t seem to export me the right things. So I had to do everything using OpenSSL on Windows, which after a little tweak, worked like a charm. Follow these instructions from Adobe to do so: generate signing request, convert certificate to .p12.
So with that done, I was set to compile my Flash game into an iOs app. This proved also more complicated than what I thought. My game was built using FlashDevelop, but I have Flash CS5.5 so I thought it was just a matter of setting my main class as the document class of a new fla. Turns out the Flash compiler is different from the Flex compiler and it started throwing me a lot of weird errors. I have to admit my project is a bit weird too (I lost one fla, so I had to decompile one file but I couldn’t get the font out of it, so I have 2 swc that have symbols in common), but it should have worked. Anyway, you don’t need Flash to compile to iOs. I downloaded the new Flex SDK and the latest AIR SDK (4.6 and 3.1) and used those templates for FlashDevelop and it worked mighty fine. Funny thing, my game was already compiled using the Flex 4.5.1 SDK; not AIR (I am not using anything special) and not the latest SDK, but I didn’t have to recompile it, I just packaged it and it worked fine. I wonder if I use the AIR compiler instead if it would run faster???
I don’t really like to do opinion pieces. On the subject of technology, like religion, sometimes it doesn’t really matter what you say; both sides never really listen to each other. I don’t want to add another pointless my side is better than yours article. But I think it is sad when people say that such and such is bad and should die. Like it is currently the case with Flash and the whole iPad brouhaha. What I think these people don’t consider is the human impact behind this.
If Flash was to go away tomorrow, I’d find myself without a job. Well, I’d need time to learn another language and then I’d find another job but it wouldn’t be the same thing. I am really glad I found Flash and ActionScript 3. This is what I want to do for at least the next 5-10 years. What I like about it is that it speaks to both my programmer and creative side. It is also fast-paced; in the web agency world, you move from projects to projects really fast and you have to keep up with technology at the same time. It might seems weird but I really like that; no time to get bored. If it wasn’t for Flash, I don’t think think I would love my job as much as I do.
After the iPad announcement I found myself a bit confused and stressed about my future. The future of Flash seemed uncertain so my future seemed uncertain to. Not uncertain because of the evolution of technology (like HTML5) but because a company decided what the outcome should be. If all Apple products stop supporting Flash, this is not good news to me. What possibilities I had would lessen. Some would say that I shouldn’t tie myself to a technology, I know, and if I have too I will learn something knew, but as I said before I really like Flash. That made me think that it’s not only companies that can choose who gets to live or to fade (technology wise). Us, as developers, can put our weight in the balance too. As long as there will be people producing get content for the Flash platform, it will continue to thrive. If I like Flash that much, I must not be alone and from reading all those article that take Flash’s defense, I think I am right. So I feel more at ease now. The future is still uncertain but certainly less gloomy.
One last thing about the iPad. Zeldman in his post states that the computer of tomorrow is a computer that is dead simple but that in return doesn’t give all powers over it for the sake of usability, like the iPhone and the iPad do. I think that a portion of the population in fact wants that. Right now this portion might be big, but I think it will shrink because it doesn’t consider that the children that are raised right now have never seen the time when there was no computers. These will be way more computer literate than my parents lets say. For that I think a device like the iPad is closer to a toy than to a tool. If it wanted to dominate the netbook market, than it will fail. We don’t really know what is the role the netbook is going to take, but by making one that is limited in its usage, you also reduce your chance of getting it right.
Well that’s all I had to say.