Posts mit dem Label Actionscript werden angezeigt. Alle Posts anzeigen
Posts mit dem Label Actionscript werden angezeigt. Alle Posts anzeigen

Making a platformer with the Citrus Engine Part 1

climbing and jumping enabled, but
the art department is still on holiday...
A little while ago I stumbled upon the Citrus Engine,
a Flash framework for making platform games. Included in the framework are lots of classes for platform objects, collision control via Box2d physics and camera and input controls giving you a headstart  with your next platformer. My game is still in the early development stage but the engines classes are well documented and easily tweakable to all my needs. I soon modded some build-in objects with custom functionality. On top of all the engine comes with a nice editor (an Air app called "Level Architect") that makes the level design a painless and fun time. Above you see a screenshot of a level done in the Level Architect, still with my development textures I will swap out for the final game art later.
Stay tuned for the next entry in that category to learn more about the development of a multilevel platformer done in Flash!

Bonzai

While recovering from my not-so-funny time in hospital I made this little running game. You must guide your tiny samurai throgh the parcour with up and down swipes of the mouse while collecting health and shield potions. Every now and then a  wooden "soldier" blocks your way which must be destroyed with sword attacks- i.e. your left mouse button. That way, while attcking you cant swipe and fall behind and have to run harder.
The engine for this game was written from scratch in Actionscript3 and is still in a somewhat early stage. The game is playable but might be a bit rough around the edges.


Play here:
http://www.daarboven.net/bonzai/

or on kongregate:
http://www.kongregate.com/games/daarboven/bonzai?acomplete=bonzai

E4X: No L♥ve for siblings

Since AS 3's XML access lacks completely on the sibling axis, i decided to roll my own wire for that:

public class XMLUtils
{
public function XMLUtils():void
{

}
//Alle Geschwister eines Knotens
public static function siblings(node:XML):XMLList
{
return node.parent().children();
}
//nächstes Geschwister
public static function nextSibling(node:XML):XML
{
return node.parent().*[node.childIndex() + 1];
}
//voriges Geschwister
public static function previousSibling(node:XML):XML
{
return node.parent().*[node.childIndex() -1];
}
}


Namespace weirdness with AS3

For my recent pet project (Displaying an Excel Sheet in Flash) i ran into a strange behaviour along with namespace usage. The Class responsible for loading and displaying the XML had a namespace variable initialised and set later on once the XML loaded and the namespace therein was read. But now the main Timeline threw an error with every function telling me the namespace variable was not defined- WHAT THE **?

Soon as I declared the variable with a dummy value on the Main Timeline, my FLA compiled succesfully with no errors. Someone please explain that to me...

More control over the dataGrid component

When using the dataGrid component being lazy as me, you would just get the column names from your dataProvider

//name and rating are the field names in the dataProvider
myGrid.columns=["name","rating"]

and call it a day...
But that leaves you with evenly spaced columns and without any dynamic height of your grid, so you better resort to something like:

var nameCol:DataGridColumn=new DataGridColumn("name");
nameCol.headerText="Game";
nameCol.width=150;

var ratingCol:DataGridColumn=new DataGridColumn("rating");
ratingCol.headerText="Rating";
ratingCol.width=60;

myGrid.columns = [nameCol, ratingCol];
myGrid.width=210;

myGrid.dataProvider=new DataProvider(dp);
//auto-height
myGrid.rowCount=myGrid.length;

which will let you size the columns at your will and have the component grow as you plug in more entries.

Dude, where's my DragOver?

Having it not used for a long time I found out today that AS3 has no DragOver in its MouseEvents. So after a bit of research dugged out several solutions with a custom Event Class but finally resorted to this little if.. statement in my Event Handler for MOUSE_OVER:

//pcont serves as a container for about 100 clips 
//inside that will react to dragOver 
 
//activate on Mousedown immediately
pcont_mc.addEventListener(MouseEvent.MOUSE_DOWN,onDragOver);
pcont_mc.addEventListener(MouseEvent.MOUSE_OVER,onDragOver);

function onDragOver(e:MouseEvent):void
{
  if(e.buttonDown)
   {
     //the Mouse is pressed, 
     //Do something here
   }
}


the buttonDown Property of the MouseEvent makes sure that the Mouse is pressed while you hover your mc.
A more advanced solution can be found at Andre Michelle, he wrote some class files and stuff to adress this shortcoming of Events.

attachMovie in AS3

Today I wrote a little replacement snippet for the deprecated attachMovie. The snippet has 3 parameters for the linkage name in the library, the name of the displayObject you wish to attach the MC to and an optional name param to identify it by name on the display list later on:


function attachMovieClip(mcName:String,target:MovieClip,newName:String="")
{
var mc=new (getDefinitionByName(mcName) as Class);
mc.name = newName;
target.addChild(mc);
}

along with Lee Brimelows very useful snippet panel for Flash CS4 attaching MovieClips from the Library at runtime is a bit less complicated especially for AS2 veterans ;-).

the xml snippet for the snippet panel is here for convenient copy/paste:

<snippet>
<title>attachMovie AS3</title>
<code><![CDATA[function attachMovieClip(mcName:String,target:MovieClip,newName:String="")
{
    var mc=new (getDefinitionByName(mcName) as Class);
    mc.name=newName;
    target.addChild(mc);
}]]></code>
</snippet>

Have fun!