Friday, February 12, 2010

Newbie tip: Declaring and Managing Linked MovieClip Instances in Parent Classes

Suppose that we have two MovieClip-based classes called MegaNode and SimpleNode. We have created both of them by drawing two vector shapes on the scene and converting them to those Movieclip-based classes. For some reason, we want to call the instance of the shape that's inside - mainShape, therefore we convert it to a MovieClip, and call the instance mainShape.

Now, since on many occasions the MovieClip class is too general for our purposes, we define a SuperNode class, which extends MC, and servers as the parent for both M
egaNode and SimpleNode. We need to be able to manipulate the mainShape instance, so we instantiate it in the SuperNode class:

public var mainShape:MovieClip;

if we simply do that, the compiler will throw the following error: "1152: A conflict exists with inherited definition SuperNode.mainShape in namespace public."
The reason for that is that by default, all instances of linked MovieClips, such as mainShape, are automatically declared by default at runtime. In order to make sure that we don't get into that error again, we need to go to the ActionScript s
ettings, and uncheck the "Automatically declare stage instances" checkbox. With that done, the above mentioned code will work, and we'll be able to manipulate the mainShape instance from the SuperNode class

NOTE: Make sure that instances like mainShape are always declared as public


Wednesday, February 10, 2010

stage.width, stage.stageWidth, and loaderInfo.width

For any new Flasher comes the time of dealing with the stage and its properties. It is probably confusing for newcomers to distinguish between stage.width and stage.stageWidth, therefore this post. (the same logic follows for stage.height and stage.stageHeight)

stage.width is defined by the distance between the smallest and the largest x coordinate that its children reach at any certain point in time. If we imagine the stage as a balloon, the further we inflate it, the bigger the distance between its walls gets. Therefore, if you have tried to determine the width/height of the stage using the stage.width/stage.height properties, before anything has been put on the stage, the output must have always been 0.

stage.stageWidth, on the other hand, defines the width of the entire Flash window.

NOTE: Normally, one would assume that if the stage's scale mode is set to StageScaleMode.NO_SCALE, the stage.stageWidth will remain constant, no matter how much we resize the Flash window. Well, no .... stage.stageWidth changes all the time, regardless of what the documentation says.

If you want to get the value of the stage width, as defined in the project settings, or the SWF metadata, you should use loaderInfo.width

Thursday, August 13, 2009

Man, if I continue writing like that, my next post will be in October 2015. I certainly hope that blogs will still be around at that time. Anyway ...

What came to my mind these days, could turn out to be a promising idea. I was been working on an alpha prototype for my Rapid Prototyping in Game Development course, when I thought how much better it would be if we could create game prototypes using markup code - just like we create Flex or WPF apps. Imagine how much cleaner and comprehensible it would be for not-so-much-in-dev guys: designers, creative people, etc.

Instead of writing tons of declarations on the C# (or whatever language is used) side, one could declare a scene using xml structures.The code will have all the advantages of MXML/XAML such as event bubbling, code nesting, binding, etc.

Two possible solutions come to mind:
1. Integrating XNA with WPF
2. Integrating Papervision3D with FLEX

I guess that integrating PV3D with FLEX will be much easier to integarte.

Monday, June 29, 2009

Pretty Good Impressions from Flash : Movie Clips

I've just recently started using Flash IDE as a development environment. Having a programming backgroung, I've always considered the Flash IDE too "out of the box" for development work. Plus, the built-in ActionScript editor, which I still do not like and try to avoid using always put out my efforts to deal with it. That's why my first experiments with ActionScript turned out to be using Flex. Flex is great, there is no doubt in that, but every tool has its particular purpose. When one wants to setup a WIMP web or desktop app, Flex is really the right one. For rapid prototyping and game development, though, it is not providing results fast enough. This is where Flash comes in.

I've always had difficulties figuring out what the movie clip was and how it worked. Well, most Flash books tend to explain it in the wrong way. Pretty much, a movie clip is the graphical representation of a class. In Flash, a movie clip is what a class is in programming - an abstract description. Just like in programming, a movie clip can be instantialized and changes to the class apply to all instances. Movie clips can be composed of instances of other movie clips, and every movie clip has its own timeline - every movie clip could have its own states and animations. I am coming to the greatest part for every developer - every movie clip can be linked to an ActionScript class. The only requirement for the class is to extend the MovieClip class. Isn't that great? As an experiment, I setup a simple project in which I created a gameCharacter class with simple logic that my game character should implement (methods like jump(), and accelerate()). Then I linked it to a Charater movie clip, and it worked like magic. Simply great.

Sunday, June 21, 2009

Seamless Interaction With the Player: A Good Example

In one of the latest sessions of my "Rapid Prototyping in Game Development" course, we spoke about interaction, and how important it is for a game to interact with the user, so that he/she could feel totally immersed in the action. Moreover, a good game must do that seamlessly. Recently, I saw a very good idea in this direction.

First, some background. Everyone who's played strategy games, be that RTS, or turn-based, knows that before being able to build a complex construction, or produce an advanced unit, the player has to produce several essential buildings or units, or has to fulfill a quest. Before doing that, the player can see all the buildings, units, or whatever, but cannot select them.

I saw a bit different, and personally, a better idea recently. Sprouts Adventure is a small casual game that turns the player into a deity who controls the lives and activities of a bunch of small unit creatures. The idea is to care for them so that they are always motivated, lively, and fed. As a result, usually, one of them says "I have an idea", a small bulb-like icon appears above its head, and when the player clicks on it, the unit starts turning the idea into a building or a construction (a bridge or something else). In this way the hierarchical development is completely hidden from the player.

This gives a bunch of ideas in the same direction...

Friday, June 5, 2009

Random Thoughts 1

So many things in my head. Random ideas, memories, impressions everything. I guess I should start writing them down at some point. With time,they will probably turn into a proper flow of information. Might be very disorganized at the beginning, though.

Anyway, I've been in Germany for a little more than a couple of months already. My general impressions are that the country offers a lot of opportunities for young and ambitious persons, however, the good knowledge of the German language is almost always a MUST. I don't know whether it is specific for the place I'm living in (Magdeburg) or it's common for the entire country, but I've had hard times communicating with Germans in English. Apart from professors and student colleagues, very few people speak English, or at least try by all means to avoid using it.

At the beginning, this was a bit of a shock for me, because I somehow had overestimated the universality of the English language. Anyway, I've always wanted to learn German, so this has been a perfect opportunity to do so. I studied it in high school, but as it happens with anything done in high school, one has to start it from scratch afterwards. That's what I did. For quite a lot of time I didn't see any signs of improvement, but this week I might say, I am definitely feeling my German better. I guess, it is true that patience and consistent practice might make miracles happen.

Thursday, June 4, 2009

Lost Track of This Blog

I so much wanted to be a proactive blogger, and many times I make myself just sit down and start writing, but nothing comes out. Somehow, I make myself believe that there is nothing about me and my world that is worth writing about. So, what I do in many cases is dump my blogging activity and turn to some other kind of info sharing like the so called re-blogging, known from Twitter and Tumblr. There is nothing wrong with that, and I think that this is a great way to share a message with the world. However, one could do so much more than just reblog. One thing reblogging cannot do is spur creativity. That's what blogging's about. There is nothing wrong in watching someone else's work and appreciating it, but one could could contribute so much more by sharing his/her personal opinion on things.

The point of this pointless post is: Make myself writing.