Showing posts with label Flash. Show all posts
Showing posts with label Flash. Show all posts

Sunday, October 25, 2009

iPhone Game Project

My first iPhone game project is underway...



(click the image to make it larger)

Step one is learning all about basic physics and how to pull off physics in Flash. I have so far tackled basic velocity and trajectory along with some collision math (when two or more object bump into each other.)

In the above screen shot you can see an iPhone sized screen with 100 objects bouncing around the screen at random velocity, spinning at random rates, all random sizes and one of three random shapes. Next notice the colors. That is only helpful to me at the moment while I am programming but the color coding goes like this:

  • Green: the object recently bounces off of the west wall.
  • Yellow: the object recently bounced off of the north wall.
  • Orange: the object recently bounced off of the east wall.
  • Blue: the object recently bounced off of the south wall.
  • Red: Two or more objects recently collided with the object.
  • White: the object recently collided with another object but is currently not touching another object nor is it touching an outer wall.


Here is another screen shot with 400 objects all bouncing around the screen!


Almost nothing is anything other than red, meaning that flash is working hard to calculate a whole bunch of collisions. Technically, with 400 objects on the screen that means that Flash would potentially need to calculate 400 x 400 possible combinations of objects colliding. I recently learned a little trick about how to pull this off without demanding that amount of CPU power to collision detection. Basically, in short, I have divided the screen space into a grid and I am only testing for collision against objects that share reasonable proximity. This drastically cuts down on the number of tests. Next I can avoid testing similar converse cases meaning if I test if Object-A and Object-B are colliding then I don't have to test if Object-B and Object-A are colliding (that would be a valid test [permutation], but a redundant one.) That cuts the tests way back again. Finally, to keep track of objects I am sorting them into Vector (or data-type-based) Arrays which just cuts process time for lists of objects to test... in half!

Here is one more screen shot of the same view but with only 25 objects bouncing around...



You can see more colors at work depicting bounce-state in this example since there are fewer collision opportunities.

So, currently there are over 75,000 iPhone apps out there which means there are likely not many more opportunities falling into the "completely unique" category. Whatever game idea this evolves into, well... there will likely already be "an app for that." So I am not worried about competition. I am in search of killer cool ideas. My first game might be something simple like rounds of flying a spaceship through an asteriod field (like this game here) and each new screen would get increasingly more complicated. I have a few ideas for interesting ways to make the effort more challenging using multitouch and the accelerometer (when you tilt the iPhone) , but we will see.

Below is a tweaked version of this for the blog here (only 50 objects set into motion with object collision turned off):

Wednesday, October 14, 2009

Google Andriod Mobile OS Moves to #2


Phones running on the Google Android operating system just got a promotion in device domination, PC World reports. Just as looming is the news that by 2012 industry analysts are saying that the Apple iPhone will lose market share. Don't obviously cash in your Apple stock yet. The iPhone surely seems to be the trend setting device at the moment and I believe it's a safe guess that we will see more innovations over the next two years.

What is interesting is the proliferation of available mobile software development kits that allow mobile device software developers the ability to more easily build games and applications for these devices.

Of course I would be remiss if I didn't mention the 2010 commitment of Adobe to put its final touches on the coming Flash 10.1 player. Flash 10.1 player will be the first majorly significant move by Adobe to unify the Flash player across desktop and mobile platforms. To the average person, this means, if your phone can see Flash then any Flash on a website you view from your desktop will be fully visible from your mobile device. No more stripped down version of Flash player (i.e. Flash Player Lite) for mobile devices. This also marks the first time Flash will show up on a number of Mobile Operating Systems.

What does this mean for Flash Developers? It means that it is time to get your creative hats on and be ready to invest in building your own mobile applications for sale. Apple has gotten the whole "there's an app for that" right from the beginning of their foray into phone devices. Now Adobe is following close behind with the development tool to end all mobile development tools... Flash CS5!

The web you hold in your hand is about to get a whole lot better!

Monday, October 5, 2009

Flash On The iPhone is (almost) Here!


My dream just arrived! Hot off the press, Adobe has announced that the next version of Flash, Flash Professional CS5, will compile ActionScript 3 Flash projects into iPhone applications distributable via the Apple Store!

Read the press release here:
http://labs.adobe.com/technologies/flashcs5/appsfor_iphone/



Before you jump to conclusions, there is still no Flash browser plugin for Safari in the iPhone. So all of the websites that display Flash are still not going to work on the iPhone (yet.)



So what does this mean for Flash Developers? Well, it simply means that we will be able to create ActionScript 3 projects that can run like iPhone applications. At the moment, we have no way of knowing how much of ActionScript 3 or what techniques outside of scripting will translate to the iPhone. For example, will timeline effects and tweens all translate? Do we have to do anything to optimize graphics for the iPhone? Are their new features that allow Flash for iPhone apps to save data to the iPhone? Can Flash for iPhone apps communicate with web services and retrieve external XML data? Can Flash for iPhone apps communicate with iPhone data and services (like GPS data, photos on the iPhone, the iPhones photo and video camera, phone lists, email, etc.) There are no answers yet. And even if there were, those answers would likely change since Flash CS5 isn't even in beta yet. But this is only going to get more fun.



Recently in the news, Adobe also made an announcement that the new HTC Hero Phone running the Google mobile operating system would have Flash built into it. According to Adobe, while that is only Flash Lite right now, they are throwing their weight behind getting a full Flash player for mobile devices this next year.



It seems that Adobe is completely poised to dominate as the development platform for cross OS mobile device development and that is great news for the many people who have invested in Flash for years. If you are simply someone who is geeked about your iPhone or interactive mobile device, just wait until the Flash development community has at it.



Now, we just need to see more people embrace cloud computing and the world will truly go mobile!



Note: For those of you who start spamming about where I found a picture a Flash for iPhone version of the all-powerful Adobe Kuler application, well... I didn't... it is a mock up I threw together assuming that would be one of the first apps that adobe will likely convert for use on the iPhone. Can you imagine it? Take a picture of something and launch the Kuler application so it can inspect it and create color schemes from the photo!?!?!?

Saturday, June 20, 2009

AS-MVC: Hot From the Geekery

In the world of code development, stuff changes all of the time. And when a programming language makes a big change everyone using that language suddenly gets reduced from being fluent to, say, a seven-year-old who is recovering from having just fallen from a tree. You brain hurts all of the time and you can't remember where you left your shoes or how to tie them.

In the Adobe Flash world I have lived through a few of these large changes. For example, Flash used to have a coding language under it that was, well, fairly silly at best. But it was the most interactive language for client-side web development and so I learned it. From that language (I believe this would be back in Flash 3 or maybe 4) ActionScript was born. ActionScript (later referred to as ActionScript 1) added some standardization but also let you write code the older, sillier way. But it was a syntax move in the right direction (they added something called "dot notation" which pretended to be object oriented.) Then along came ActionScript 2.0 which was a move from "dot notation" to a slightly more "object oriented" reality.

Since ActionScript 2.0 a Flash Developer had the luxury of writing code that adhered (mostly) to object oriented development techniques but could also write completely valid AS 2.0 code that had far less to do with Object Oriented Programming (OOP.)

Now we are in ActionScript version 3.0 and that is also quite similar to AS 2.0 but the OOP-side of AS 3.0 is far closer to OOP than flash has ever been. As a result, people attempting to learn AS 3.0 are searching the web for examples of how to build Flash content using AS 3.0 and are running into a mix of OOP techniques and non-OOP approaches. I say OOP approached because Object Oriented Programming to many people comes down to meaning "I built a bunch of classes" but that is a very rudimentary understanding of what OOP is. Saying OOP is "building a bunch of classes" is like saying web accessibility is "adding ALT properties to IMG tags in HTML." To a degree that is true, but that doesn't begin to come close to explaining what 508 web accessibility really is, how it works and all that it encompasses.

If you have made the jump from "timeline" code in flash to "class-based" code then you have surmounted the first hurdle. Again, because you could write non-OOP code in AS 2.0 making the jump into AS 3.0 was like pulling off a motorcycle trick across the wide side of the Grand Canyon. Having at least created classes in AS 2.0 is like having a bigger more powerful bike and simply jumping across, say, the Mississippi River: still scary but you can at least see the other side without squinting.

So, if you have made the first jump (building classes) then here is a hint to understanding some of the rest of the jump.

Now, I don't have the time to help outline all of the new classes or any new syntax here. That is an unavoidable effort at scratching around and memorizing a new framework / code-base. There are no shortcuts to that, but I can say that tools like FlashDevelop can help you find your way much faster since FlashDevelop will add your import statements to your custom classes. The bigger (or at least equally as large) hurdle in making the AS 3.0 jump is understanding the most appropriate approach to coding your classes and how the timeline (or visuals) relates to that code. Most folks don't know how to avoid writing code in the timeline and are searching desperately for what the right best approach might be.

The amazing part about OOP is that there are a number of excellent approaches to organizing your coding effort, but I am going to briefly explain one of the older techniques that remain valid to this day.

Let's look at the Model-View-Controller (MVC) approach to development.

Model-View-Controller is about cleanly separating the three parts of a software development experience: The interface (View), the common utility logic (Model), and the instance of the application and it's controlling of the interface and the utility logic (Controller.) Let's go through each of the three parts.

The View:
In the Flash world, the View is the "front-end" interface where the user is listening, watching, talking, typing and clicking. In the MVC approach the interface would be planned appropriately to break apart the interface into various logical parts: video player, audio player, text presentation, lists, editing forms, common game controls, etc.

In the various Views you might create animations that are completely controlled in code by class utilities like "Tweener" which can be told to animate something from one frame to another specific frame and notify you when that animation is complete. That sort of "control" code is written into the Controller to manipulate various states of a View.
The Model:
The Model is where we put the logic of the application. I previously referred to it as common utility logic because I want to separate in your mind the code that animates the state of an application and the code that provides common services in a very interface-agnostic utilitarian manner. Said another way, you might create a rich internet application (RIA) in flash that retrieves information from an RSS feed for displaying in the browser. In this architecture and approach you would write an interface-agnostic utilitarian class that simply gets that data and hands it over as a result. If you write a class to retrieve RSS feed data (XML) and hand back the results and you keep that separate from any interaction with the presentation / interface / View then you can reuse that code (Model utility class) in future projects that implement different interfaces.

Your custom common utility classes, any other classes you are using in Flash, or classes from some third party are typically referred to as part of the Model part of the MVC approach.
The Controller:
The Controller as you can imagine is also comprised of code. In the AS 2.0 world the controller was typically just a number of functions in the lowest level "_root" timeline in flash. In the AS 3.0 world inside the Flash paradigm of development, the Controller is the Document Class associated with the lowest level timeline FLA. Inside the Flash project properties you can now assign a class to basically be the code that the SWF calls first before anything else. It is inside the Document Class where all of the action starts.
The document class could create an instance from the View (some interface, possibly a login), animate it into visibility and link up code that "Controls" (or watches) for clicks from that Interface, which might create instances of common utility classes from the Model to perform some function. Let's look at one example of what that interaction might look like.

Going back to the previous example, let's imagine someone arrives at your RSS Viewer RIA. Once the SWF loads it would call the code in your Controller (Document class.) The Controller would animate in a presentation of the RSS List View (an Interface element from the library) and then wire-up the list to code, in real time (animate and setup the View for interaction): The Controller might use a class from the Model to get the list of RSS Feeds and then populate the View with that information. The Controller might dynamically associate a mouse-click event with the list.

Let's imagine that the user mouse-clicks on an RSS Feed item presented in the RSS list View. The Controller would be notified of that click (because it wired it up a moment ago) and would then need to present the RSS Feed Reader View (yet another View inside the View part of the MVC approach.) Before it does this you might have written the Controller to clean up the List View by unloading arrays or removing event watchers that are no longer needed.

Once the RSS Reader View was ready, the Controller would wire up that view for scrolling and various kinds of mouse-click interactions.

This is the basic MVC approach to OOP in AS 3.0 under Flash CS3 and CS4. As you can see, it is all about events managed by the Controller resulting in the presentation of new Views and the Controller management of their interactions via Controller code as well as the Controller using other utility classes from the Model but it is all about events.

Naturally you are going to want to get really familiar with the ActionScript 3.0 event model: how do you code for events, how do you handle asynchronous events, how do you author asynchronous events in your custom classes, what are the more common View related events that the Controller needs to manager (for example: setting up a View, managing interactions a user experiences with a View, cleaning up after a View no longer needed in that moment, etc.)

Well, that is MVC and I hope it wraps some context around knowing how to explore AS 3.0 and what sort of architecture and approach decisions you might want to make inyour new coding projects. Have fun and build cool stuff!

Friday, May 4, 2007

Flex 2 is Open Source: The Web Is Dead, Long Live The Web

Ok, for those of you who have been paying attention to rich internet application development, we fundamentally know that Flex 2 development is XML template for having a server-side process compile a SWF in near real time. This basically means that a flex MXML file is basically just a set of instructions for how a SWF should be created, including actionscript wrapped in CDATA tags in the XML (imagine a Flash project decompiled into a set of XML tags.) Well, Adobe decided at the end of last month to completely Open Source the entire Flex 2 solution, as a part of the Mozilla project, including the server-side Java code that dynamically creates SWFs. A long time ago they Open Sourced the SWF file format (I remember that was when Corel Draw Suite, specifically their animated-gif timeline tool, all of a sudden could output to SWF.) and now they are Open Sourcing the server-side code that builds the Flex files into SWFs.

There shouldn't be any more complaining from purist web geeks about Flash on the web. Technically, they could go read through the Open Source Flex Project and create their own Flash SWF Compilers. This is as open as open gets. The only thing Adobe could do now is to give away the Flash Development tools, which would be rediculous.

http://labs.adobe.com/wiki/index.php/Flex:Open_Source

Adobe has thrown down the gauntlet. If "open source" really just means free to you, then you will be relegated to a back seat on the ride that is the web. If you don't want to buy the Flash development environments from Adobe then you should team up with some people and build your own "free flash content creation tool" based on the Open Source reality of Flash. My goodness. Adobe has taught you how to fish. Does the world need to catch you a fish and feed you as well, hand to mouth?

Even though we know it is happening in FireFox (Firefox will have native support for running actionscript in the browser instead of writing javascript), if IE implements that as well, I see the end of javascript, we would have been completely right about fjax (as a concept/idea) and rich internet applications will be the new norm.

Traditional HTML tagging embedded in a text document will be viewed as "something we did once when the web was far less dynamic." For those who are exhausted by the forever steep learning curve that is the web industry, buckle up (and read my last blog). We are just getting started and those who do not "enhance" will be left behind ("left behind" is a fairly long curve in itself. I am willing to guess that one has about two years to ignor the trends before one has to go find a new industry to stagnate in.)

For more info on Flex Open Source, check out: http://flex.org