Hello Whirled

From Whirled

Jump to: navigation, search


Set Up Your New Game

To create a new game, change to the whirled directory and run the ant newgame task:

  % cd whirled
  % ant newgame

Windows users can double click the newproject.bat file instead of using the command line.

If this is the first time you are using the SDK, it will ask you to configure the directory of your Flex SDK and your Flash Standalone Player. A dialog box will pop up allowing you to specify that information and then you will proceed to creating your new project.

Next, you will be asked to name your project:

newgame:
[newproject] Please enter the name of your Game project.
[newproject] For example, BestGameEver:
HelloWhirled

[newproject] Your main class will be called:
[newproject]   HelloWhirled.as
[newproject] Is this OK? [y/n]
y

and the tool will do the rest for you:

[newproject]   Creating 'hellowhirled/build.xml'.
[newproject]   Creating 'hellowhirled/HelloWhirled.as'.
[newproject] Done! Your new project has been created in 'HelloWhirled'.

Hello Whirled

A game that doesn't talk over the network is just a simple Flash file. Open the file 'HellowWhirled.as' in a file editor program. Delete the current content and add the following content to 'HelloWhirled.as':

package {

import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;

import com.whirled.game.GameControl;

[SWF(width="400", height="400")]
public class HelloWhirled extends Sprite
{
    public function HelloWhirled ()
    {
        // listen for an unload event
        root.loaderInfo.addEventListener(Event.UNLOAD, handleUnload);

        _control = new GameControl(this);

        var label :TextField = new TextField();
        label.x = 0;
        label.y = 0;
        label.htmlText = "<b>Hello, Whirled!</b>";
        addChild(label);
    }

    /**
     * This is called when your game is unloaded.
     */
    protected function handleUnload (event :Event) :void
    {
        // stop any sounds, clean up any resources that need it
    }

    protected var _control :GameControl;
}
}

To compile it, run ant at the command prompt:

 % ant test

Or simply double click build.bat on Windows.

This will produce an output file called HelloWhirled.swf in the same directory and it will load your game in the test environment.

Image:Hello_whirled_shot.png

Next Steps

Personal tools