Archive for the ‘ ActionScript ’ Category

Molehill might become a fun, usable mountain

[tweetmeme source=”neoRiley” only_single=false]So, essentially, Unity has entered the Flash 3D world.  While 3D api’s (Away3D is doing an excellent job, btw) might provide a way to bring 3D to life via Molehill, Unity brings a kick-ass IDE with it.

And considering that they’re going to support AS3 right out of the bag (which they practically already do with UnityScript) as well as the other languages you can already use (I’ve become a c# fan myself), I’m hoping the resulting project from Unity will allow for maximum integration with flash projects.  I have no idea what output they intend to target (swf or project to yet be compiled by flash), but I do hope they output a project we can work with on the FlashBuilder or Flash IDE side of things.

There have been quite a few discussions about this move, and as usual, there’s 2 camps – the yay’s and nay’s.  I see it as a positive for Unity overall – they’re in the business of making tools, and they do that extremely well, and without a doubt, their developer base will broaden drastically if the resulting Flash is what people expect and need to get their work done (reference Adobe’s output for iPhone compared to Unity’s – case closed).  Case in point, I’d created a Papervision3D component for the Flash IDE a while back – it was downloaded over 450,000 times).  That tells me that people want visual solutions to 3D problems and that there’s a huge potential user base for a good Flash3D IDE.  Bringing Flash3D to the lower common denominators in the development food chain is a “good” thing.

But without a doubt, Adobe is the massive winner here.  IMO, they are walking away with much more of a win.  The one thing I’d complained about early on was that Molehill left 3D to the egg-heads who loved being the only ones who could use it.  As I’ve said before – until you bring it to a state of usability by the masses, it’s pointless and will largely be fruitless.  In other words, I felt that if the new 3D capabilities weren’t put in the hands of us lesser-folk through a common interface and language, it wasn’t going to go anywhere except for demoscene reels on YouTube.

Enter in Unity, and you just fixed all of that.  All of what I was saying and telling them they needed to achieve, they received from Unity3D (Merry Christmas Adobe).   I do wonder how Unity’s physics, Beast Light mapping and shaders will translate, but I’m guessing those are the fruits they intend to dangle in front of even the most hardened Flash 3D developer 😉

Check out the official release statement:
http://blogs.unity3d.com/2011/02/27/unity-flash-3d-on-the-web/

Coming from ActionScript / UnityScript to c#

[tweetmeme source=”neoRiley” only_single=false]After writing iFly and Star Wars: Trench Run in UnityScript, I became painfully aware of the shortcomings associated with UnityScript.  Mainly that it has no decent event / delegate system to leverage.  Sure, you have event handler methods that exist in GameObject etc, but that’s a complete throw back to AS2/1 days.  I tried porting an old AS2 event dispatcher class to UnityScript (which I did successfully) but had pointed out to me by someone at Unity that it would be painfully slow.  He then suggested I consider c# and get involved with delegates.  He was right.

So, for a while now, I’ve been doing c# and loving it.  There were, however, some things that obviously caused me some discomfort and that’s why I’m writing this post.  I’ll be adding to it when ever I find new topics that apply.

First, here is a link that provides the majority of the “differences” between UnityScript and c# – I recommend this one as it really covers the basics very well.  I’ll be covering the not-so-obvious ones that made me scratch my head 😉

http://answers.unity3d.com/questions/5507/what-are-the-syntax-differences-in-c-and-javascript

Alright then, here’s the first thing to look out for:

Number = float

Coming from AS3, you’re used to Number, int, uint and for the most part, you get what they do.  When coming over to c#, there is no “Number” type.  Instead, use float.  Just think of it in the most simple terms:  “f”loat for “fraction”.  Meaning, if you know you’re number will be fractional (like 3.16) then give it a type of float:

float myScale = .5f;

Note the “f” at the end of the declaration (.5f) – that’s how you cast it as a float.  If you don’t, Unity compiler will give you an error.  Same goes for passing floats as arguments, make sure you include the “f” cast:

Vector3 pos = new Vector3(.1f, .05f, 2);  // you can add the "f" cast after a whole number if you like, but it's not necessary

If you’re doing some division or scaling math and you know the outcome *could* be fractional, both sides of the equation need to be floats or you’ll get a whole value in return.  Simple enough you might think, but I’ll bet you scratch your head at least one time on this one where you can’t figure out *WHY* it’s not calculating a remainder for you:

float i = 15f;
float j = 10f;
float value = i / j; // 1.5f

If you want to parse a string into a float or int:

int value = int.Parse(stringValue);
float value = float.Parse(stringValue);

If you want a whole number and an int from a float, use FloorToInt() – I mention this one simply because of how AS3 just doesn’t give a crap, but c# does:

int value = Mathf.FloorToInt(float n);

Event Dispatching

In AS3, everything extends EventDispatcher practically.   Everything can dispatch events, have listeners and everyone’s happy in their little event driven world.  Then you come over to Unity and realize, we’ve taken a step back into AS1/2 land. There are event handlers on GameObjects and if you declare them, then they will receive the calls – very very onEnterFrame type of stuff here.

So, given my history and experience with AS2, I naturally dusted off an old EventDispatcher class that we used to use back in the day.  Like I said above, I converted it, it worked, but was made to realize that in a performance setting, it’d be a pretty substantial bottle neck.  Still, if you’d like to see how it’s done, here you go ( now at least, I won’t feel like the time I spent on it was wasted )

EventDispatcher.js
ListenerObject.js

But now, the real deal in c# for creating an event and dispatching goes something like this:

Declare a delegate for the event. Note that I’ve created it outside the class declaration – this is so it’s available to any class:

public delegate void LoadComplete(float value);
public class MyClass
{
    //...
}

Now, create the event in MyClass:

public delegate void LoadComplete(float value);
public class MyClass
{
public event LoadComplete LoadCompleteEvent;
}

To add a listener, you add a new delegate instance with the handler to the LoadCompleteEvent event:

public delegate void LoadComplete(float value);
public class MyClass
{
public event LoadComplete LoadCompleteEvent;
    public void Start()
    {
        LoadCompleteEvent += new LoadComplete(HandleLoadComplete);
    }

    // note how the argument signature matches the delegate declaration
    private void HandleLoadComplete(float someValue)
    {
        // event handled here
    }
}

To send out the event, first check to make sure the event is not null (has listeners), then call it like a method:

public void DoSomething()
{
    if( LoadCompleteEvent != null ) LoadCompleteEvent(1.0f);
}

To remove a listener, just remove the handler from the event:

LoadCompleteEvent -= HandleLoadComplete;

Coroutines (replacement for setTimout, setInterval, Timer object)

In AS3, we’re used to setTimeout() or the Timer object to deal with waiting and looping stuff.  In the old days, we used onEnterFrame and I can still remember the arguments over which was better – setInterval or onEnterFrame.  It was a ridiculous argument, because in reality, it just depended on *what* you were doing when that even fired.  Please don’t leave comments regarding this tired and exhausted discussion which has zero relevance these days 😉

In UnityScript, you’ll be introduced to WaitForSeconds() which is really nice when coming from AS3.  In c#, however, you get a bit of a rude awakening. You begin to realize how much UnityScript lets you get away with.  Its insane.

So, here are the basics.

If you want to loop or wait a certain amount of time, you have to call a method that returns IEnumerator:

public IEnumerator DoMyBidding() {...};

Then, you have to have some sort of yield/return statement in this method or the compiler with barf all over your keyboard:

public IEnumerator DoMyBidding()
{
    yield return WaitForSeconds(1.5f);
    if( myConditionNotMet ) yield return null;  // this is how you just simply return out if you no longer wish to continue.
}

If you want to loop something:

public IEnumerator MonitorMe()
{
    while ( conditionNotMet )
    {
        // do something
        yield return WaitForSeconds(.025f);
    }
}

To call these methods, you have to use StartCoroutine():

public void Start()
{
    StartCoroutine( MonitorMe() );
}

Well, for now, that’ll get you started, and as I remember/think of things, I’ll come back and update this post with more tid-bits.  Enjoy!

Do developers drive the market?

[tweetmeme source=”neoRiley” only_single=false]I’ve heard several different ideas over the past week about what we might do and what we ought to do as developers (and consumers) to teach Apple a lesson about section 3.3.1.

Everything from “post everything you have to the app store” for approval, to purchase every app known to be made by a 3rd party app, to stop developing for iPhone / iPad all together ( as I type this out on my new iPad ). Personally, I don’t think the first 2 are going to make a difference that apple would see or much less care about.

So I was thinking about what Mike Chambers posted about yesterday. He states that he’s going to focus on android and is looking forward to the tablets coming out later this year. He then goes on a bit further about not going forward with any iPhone development to the point of not even maintaining the apps he’s already put out in the apps store.

While I can certainly appreciate where Mike is coming from and his reasons, I think that it’s premature for one, and I think ultimately we as developers should never burn technical bridges so to speak. Not that I have any idea whether or not Mike will ever do OC work again or not, that’s beside the point. And to be fair to Mike, his job doesn’t require him to keep OC in his back pocket – that’s not his job.

My question is: what drives the mobile market anyway? Is it the will of the developer community? Or, is it based on what the consumers want? Simple enough, right?

If you think it’s driven by the developer community, you’re wrong. It’s driven by the fanboys and fangirls who have no clue what’s going on behind the scenes – they see new toy, they buy new toy as long as the experience is good. And right now, the iphone IS the best mobile phone experience out there. This is mainly to do with the fact that Apple IS so anal. Just look at every other phone being developed these days. The phone makers are responding to a public that loves the experience of the iphone. Look no further than android for an example of that ( case in point Nexus one which looks like your dad’s old palm pilot compared to an iPhone IMO )

Bottom line – there’s a need and market for iPhone and iPad apps right now, and this means we have a demand. As long as there’s demand, someone’s going to step up to the plate, take the gig, and make the money. Simple as that.

So with that, I would encourage any developer out there to not abandon technology for ideology. What comes around goes around, and we’ve seen it way too many times already in our short history. Today’s hypocrite is tomorrows hero and in the end, whatever the consumer wants, the client needs. And whatever the client needs, the developer should be able to provide to stay competitive.

NEW: Papervision3D Component 2.1

I’ve just posted the latest version of the component for the Flash IDE:

http://code.google.com/p/papervision3d/downloads/list

It’s been a long long wait and I’ve been handing the component out at Flash conferences and classes that I’ve taught, but was waiting for Flash CS4 to be fixed to work with my component.  CS4 has alot of known issues with components, Adobe is well aware of the issues that cause my component not to work and I’m sure it’ll be fixed down the road sometime.

So for now, the component will only work in Flash CS3 IDE.

New Features and bug fixes:

1.  new Materials panel – now you can deal with your materials through this panel that Andy Zupko added oh so long ago 😉

2.  Code Templates:  I’ve put in 2 templates for writing code against the component all flushed out with all the event listeners etc.

3.  Many bugs fixed

Thanks all, and enjoy!

John

Flash on Tap Slides:

Flash on Tap was a GREAT conference – unbeleivably cool and laid back (at least for me it was).  It was truly great to see old friends again and hang out a bit.  Last time I went to a conference I was so stressed about about getting hours in on a project, I couldn’t enjoy Brighton.  It was a shame really.  But this time around, I really took the time to enjoy myself and just do what I wanted.  The class went great on Thursday, and the 3D panel discussion today was very cool.  I was nice to get to voice some opinions about about Flash, Unity and 3D in general.

Anyway, I rushed through my Papervision to Unity to iPhone session like mad at the end and promised I’d post the slides, so click on the image above or here.  I’d clearly planned to talk about way too much in my presentation, but I was at least able to do the sample demo app I’d put together of the obstacle course.  I was happy that people enjoyed seeing Unity in action and creating a simple game, but was bummed I didn’t even get the chance to show some scripting so they could see how very similar Unity’s Javascript is to ActionScript3.

There’s always next time!!

Papervision Training at Flash on Tap

Man, I was just over at Keith’s blog and saw him realizing that FOT is just 3 weeks away!!! I instantly had the same reaction – holy beer batman!

I thought it’d be good a good idea to post what Andy and I will be covering and what you’ll need.  We’re giving a live full day workshop the day before the event starts.  If you haven’t signed up and you’re interested in going to the 1 day work shop (you don’t have to attend FOT for this), email me at neoriley at gmail dot com and I can get you the same $70 off discount code.

What we’ll be covering:

John first half of day:

  1. Papervision basics – scenes, cameras, setup
  2. cameras and animation
  3. Primitives
  4. Materials
  5. Collada
  6. Papervision3D component for Flash IDE (requires CS3 unfortunately)

Andy will cover:

  1. Effects and Layers
  2. Effects Filters
  3. Shaders

The class has filled up nicely I so far and I’m really glad to get out and teach again.  Its something I really enjoy doing

Change to my Session at FOT

It was a year ago when i’d put up my description for my Session at Flash on Tap and I’d really intended just to follow through with that, but now that we’re getting much closer to the actual event, I think my topic is really not in sync with what I’v been working with in the past 6+ months.

So, I’m going to be covering the development crossovers between Papervision/actionscript3, to Unity3D/Javascript, to iPhone 3D gaming.  I’ll be showing the differences and similarities between Papervsion and Unity3D and talk about the caveats to iPhone 3D gaming with its abilities and limitations.  I’ll also being showing the Unity3D IDE,  features and workflow.

Stunt Bike iPhone game in Unity3D IDE

Stunt Bike running on iPhone

Many of the issues we deal with in Papervision3D are applicable to the iPhone 3D gaming development.  With Unity as a middle man for development, I think there’s plenty to talk about 😉

Hope to see many of you there!