views:

390

answers:

3

I am digging into OpenGL ES on the iPhone, and I have still no big idea about OpenGL ES and Flash.

About Flash I only know it is capable of making really nice animations and transitions. For best example, lets look at the Ocarina flute for the iPhone. This application makes some simple but powerful animations. It expands little circles to get bigger and bigger. And while they do, they have radial gradients and change alpha.

That is the kind of cool flash animation stuff I mean.

Now, both in Flash and OpenGL ES there is the capability of hooking up some kind of "objects" like circles or whatever with some kind of code, so that touching a circle kicks off another animation.

For my understanding both things are pretty much exactly the same, when looking on the surface. Maybe someone can point out the differences from the inside. i.e. does a Flash Developer has to learn a completely new way of thinking and working, or do both technologies have many things in common?

+1  A: 

In OpenGL there is no notion of 'objects' and 'gradients' and all the nice things flash offers. OpenGL just knows about vertices, normals, colors, matrices etc... Those things combined, together with a lot of programming can make amazing things, but it won't be as easy as using Flash. Keep in mind there's no (good) Flash player for the iPhone, yet.

Emiel
+1  A: 

OpenGL is a lower-level API than what you normally use when developing with Flash. You can do a lot of stuff with it, but either you have to build your higher level abstractions yourself or use some existing library.

If you are coming from Flash world, I assume that you mostly need 2D abstractions like Layers etc. Cocos 2D for iPhone is a great library for that with a lot of cool stuff already built in. You can get it from here

tequilatango
I'd argue that Core Animation, with its layers and animations, is closer to being like Flash on the iPhone. It also has the benefit of being hand-tuned by Apple for the device, which a third-party framework lacks.
Brad Larson
Brad, yes Core Animation is a possibility.However, we have been porting our own 2D animation library from Flash to iPhone. We first evaluated using Core Animation for that, but we didn't find it suitable for our needs. Granted, we needed more granular API than Core Animation provided but we also found that handling a lot of custom animations in Core Animations was really cumbersome. It's fine for making a custom animation for an UI widget now and then, but I wouldn't do game on top of it.I think most good looking 2D games developed on iPhone are using OpenGL, not Core Animation.
tequilatango
+2  A: 

first of all, there is no flash player for the iPhone ... so yeah, that's not really an option ... but there is a flash like alternative ... have a look at this post ... and at haXe ...

in short: haXe is an open source language, that allows targetting flash player 6-10, PHP, JavaScript, neko VM, and C++ (more targets coming) ... the creator of the haXe/cpp compiler backend uses it to get on the iPhone ... as a matter of fact, he has written a library, that allows you to use flash9 API on C++ or neko with openGL (neash? nme? can't remember which is which ... :D) ...

this allows you to write haXe for the iPhone, using flash 9 api ... haXe is a little different from actionscript, but you will quickly get the hang of it ...

currently, a limitation is, that his library uses either software rendering or Open GL for graphics, which is why he has to use software rendering on the iPhone (that's not really an option) ... but it's fair enough for developping and i think, hopefully he'll be having the Open GL ES integration soon ...

so maybe that would be a way to go ...

but as your active tags indicate, you never really dealt with actionscript or flash, so i am not sure, if it is not simpler to use the adequate Cocoa frameworks to get your stuff done ... there is an advantag in using haXe and flash API: i think it is a lot easier than related Cocoa frameworks (a friend of mine, who is a mac developer, started with the iPhone, so i have a superficial insight, but it was a little shocking, how little he had up and running after 2 days of work) ... the flash API more high level, thus simpler, but also limited and may not be as performant ... but you will get results really quickly ... but perfomance matters on the iPhone, because it means power usage ...

this is a full haXe program doing pretty much the circle stuff the ocarina does:

package ;

import flash.display.DisplayObject;
import flash.display.GradientType;
import flash.display.LineScaleMode;
import flash.display.Shape;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.geom.Matrix;
import flash.Lib;
class Main {    
    static function main() {
     for (i in 0...(Std.random(5) + 5)) {
      var s = genCircle();
      Lib.current.addChild(s);
      pulsate(s, Std.random(10) + 10);   
     }
    }
    static function genCircle():Shape {
     var radius = Std.random(50) + 50;
     var s = new Shape();
     var color = 0x110000 * Std.random(8) + 0x001100 * Std.random(8) + 0x000011 * Std.random(8) + 0x7F7F7F;
     s.graphics.lineStyle(5, color,1,false, LineScaleMode.NONE);
     if (Std.random(2) == 1) 
      s.filters = [new BlurFilter(4, 4, 3)];
     else {
      var m = new Matrix();
      m.createGradientBox(radius, radius, 0, -radius/2, -radius/2);
      s.graphics.beginGradientFill(GradientType.RADIAL, [color, color], [1,0.5], [0, 0xFF], m);
     }
     s.graphics.drawCircle(0, 0, radius);
     s.x = 50 + Std.random(300);
     s.y = 50 + Std.random(300); 
     return s;
    }
    static function pulsate(d:DisplayObject, speedModifier:Float):Void {
     var cter = Std.int(Std.random(Std.int(speedModifier)));
     d.addEventListener(Event.ENTER_FRAME, function (e:Event):Void {
      var x = Math.sin(cter++ / speedModifier)/2 + 0.5;
      d.scaleX = d.scaleY = x + 0.5;
      d.alpha = 1.2 - x;
     });
    }
}

still, this i bit further in the future ... what is left to do, is use Open GL ES, as mentioned, and, by far more tricky, get haXe binding to all the inputs an iPhone produces (acceleration, multi-touch) ...

well, you might wanna keep an eye on it, if this road seems interesting to you ... or even, as someone, who works with the iPhone, you might even want to contribute to the haXe->C++->iPhone solution ... ;)

hope that helped ... or that it was interesting at least ... :)

back2dos
cool stuff. thanks! well, my intention wasn't to do anything in flash. I just want to know the differences in the technologies :) but anyways thanks for the haXe hint :)
Thanks