Log in
Please log in or register.
Pages: [1] 2
  Print  
Author Topic: Hello world in Flixel?  (Read 8250 times)
triptych
Newbie
*
Posts: 6


View Profile
« on: Sat, Jun 6, 2009 »

Anyone working on a basic "hello world" type game with Flixel? Starting a scratch game would be a nice tutorial - mode is great but its already all created.
Logged
ben
Newbie
*
Posts: 11



View Profile
« Reply #1 on: Sat, Jun 6, 2009 »

Oops. Somehow I deleted my previous post.

Okay, I'm using FlashDevelop, though it should be similar for whatever environment you're working in (I hope...). Within FlashDevelop (or what have you), create a new AS3 Project named HelloFlixel.  Then copy the com folder (containing the subdirectory adamatomic/flixel) from the flixel_v1.0 download into your project folder.

Your first actionscript file, HelloFlixel.as, should look something like this:
Code:
package {
import com.adamatomic.flixel.*;
public class HelloFlixel extends FlxGame {
public function HelloFlixel():void {
super(320, 240, HelloState, 2, 0xff000000, 0xffffffff);
}
}
}

I went ahead and imported the entire flixel library for simplicity's sake.  All the games you make with Flixel must extend FlxGame.  The FlxGame constructor as we're using it above takes arguments for width and height of your game, the FlxState to initiate, the zoom factor, the background color, and the flixel logo color (on startup).  Here it's just white on black, but feel free to change the colors (the color format is 0xaarrggbb).

Now we need to create HelloState.  Create a new file, HelloState.as, and make it look something like this:
Code:
package {
import com.adamatomic.flixel.*;
public class HelloState extends FlxState {
private var text:FlxText;
public function HelloState():void {
text = new FlxText(0, 0, 100, 10, "hello",0xffffffff);
this.add(text);
}
override public function update():void {
super.update();
}
}
}

Here we have HelloState which is an FlxState. We have a FlxText object named text, which we'll use to write some text to the screen.  Within the HelloState constructor, we'll initiate our text.  FlxText's constructor arguments here are x and y position, width, height, the String to write to the screen, and the color.  (Additional arguments include font size, font face, etc. please feel free to look it up in the documentation).  Then we need to put text into the update loop, by using this.add(text);.  The update() function is called every frame; here we override it because it's already defined inside FlxState.  We don't have anything special we want to do here yet (later you may want to add some interactivity or animation to this; this is where you would check for keypresses and the like), so we just call super.update(); and we're done.

From here you should be able to compile and run, and you get "hello" in the upper-left corner:


I know I left a lot of things out of this, and I don't really know what I'm doing.  I'd appreciate it if anybody corrected me where I'm wrong, but also please feel free to ask questions; I'll try to answer. Tongue I hope this helped somewhat.
« Last Edit: Sun, Jun 7, 2009 by ben » Logged
ben
Newbie
*
Posts: 11



View Profile
« Reply #2 on: Sat, Jun 6, 2009 »

I also have a rather strange Hello I created; this one I did to figure out how Emitter works and to play with quake and stuff.  You can see it here: http://bowlofnoodles.com/Helloflixel.swf (X to quake the screen, Z to stop the flickering and the emitter)

And download the source here (my code is crap, i know): http://willhostforfood.com/?Action=download&fileid=69218

EDIT: Crap. I forgot to take out line 7 in HelloState.as in the zip file linked to above, the [Embed(source = "pixel.png")] private var Pixel:Class; is unnecessary so get rid of it  Tongue
« Last Edit: Sat, Jun 6, 2009 by ben » Logged
SMRobot
Newbie
*
Posts: 14


View Profile
« Reply #3 on: Sat, Jun 6, 2009 »

Thanks for the help ben! I'm just downloading the flex SDK (at dialup speeds) and I'll be sure to give this a go as soon as it finishes.
Logged
adamrobo
Newbie
*
Posts: 10



View Profile WWW
« Reply #4 on: Sun, Jun 7, 2009 »

Thanks for the help, ben!

I'm new to the Flex environment, and I ran into a bit of a snag. I followed your instructions for the first Hello World test, but when I try to run or debug the program it fails and gives me the error message "This file cannot be launched."  Cry

Do you have any idea what I could be doing wrong?

Update: I had to define the the default ActionScript application as being HelloFlixel.as.

I'm getting a new error now in the HelloFlixel.as file.

"A file found in source-path 'HelloFlixel' must have the same name as the class definition inside the the file 'HerroFlixel'.



I thought maybe you meant to type "HelloPixel" instead of "HerroPixel", but when I changed that I got another error.

"1084: Expecting left parenthesis before colon."

And when I try to run the file it tells me that I'm missing HelloFlixel/bin-debug/HelloFlixel.html

Doesn't it create that automatically?
« Last Edit: Sun, Jun 7, 2009 by adamrobo » Logged

Adam Atomic
Administrator
Hero Member
*****
Posts: 724


hostest w/ the mostest


View Profile WWW
« Reply #5 on: Sun, Jun 7, 2009 »

Make sure that inthe filetree you have a file from your project selected
Logged

adamrobo
Newbie
*
Posts: 10



View Profile WWW
« Reply #6 on: Sun, Jun 7, 2009 »

Thanks, Adam.

I deleted the project and started over. All I had to do this time was change "HerroFlixel" to "HelloFlixel" and it worked fine.

Whew!
Logged

ben
Newbie
*
Posts: 11



View Profile
« Reply #7 on: Sun, Jun 7, 2009 »

Haha, wow! Sorry about that! I missed it completely! ...fixed now.
Logged
owen
Newbie
*
Posts: 40


View Profile
« Reply #8 on: Sun, Jun 7, 2009 »

Any luck getting a FlxSprite to show?

var spr:FlxSprite = new FlxSprite(null, 10, 10, false, false, 100, 20, 0x400000);
this.add(spr);

this is a FlxState

Thanks!
Logged
Adam Atomic
Administrator
Hero Member
*****
Posts: 724


hostest w/ the mostest


View Profile WWW
« Reply #9 on: Sun, Jun 7, 2009 »

Remember the Flash color format is AARRGGBB
Logged

owen
Newbie
*
Posts: 40


View Profile
« Reply #10 on: Sun, Jun 7, 2009 »

ughhhhhhhh...

Thanks man!
Logged
SMRobot
Newbie
*
Posts: 14


View Profile
« Reply #11 on: Sun, Jun 7, 2009 »

Thanks a bunch, this was really helpful.
Logged
bbrizzi
Newbie
*
Posts: 5


View Profile
« Reply #12 on: Mon, Jun 8, 2009 »

Trying to do this, Im getting error 1017:The definition of base class FlxGame was not found.
I've copied the com folder as instructed (ya, its the right one). I just did a simple copy/paste of the code. Any advice?
Logged
flexguy1
Newbie
*
Posts: 2


View Profile
« Reply #13 on: Tue, Jun 16, 2009 »

i'm getting this error while opening of this link
http://willhostforfood.com/?Action=download&fileid=69218
given in this topic,

Error:
You're seeing this page because account contains no index file. (EG: index.htm)
Logged
sonictail
Newbie
*
Posts: 6



View Profile WWW
« Reply #14 on: Wed, Jun 24, 2009 »

Trying to do this, Im getting error 1017:The definition of base class FlxGame was not found.
I've copied the com folder as instructed (ya, its the right one). I just did a simple copy/paste of the code. Any advice?

I have to admit that I'm getting this error aswell and I cannot figure out why.  I've been over the code a dozen times and no dice.  I'm using Flex Builder.  Code as follows

Code:
package {
import com.adamatomic.flixel.*;
public class HelloFlixel extends FlxGame {
public function HelloFlixel():void {
super(320, 240, HelloState, 2, 0xff000000, 0xffffffff);
}
}
}
and HelloState.as
Code:
// ActionScript file
package {
import com.adamatomic.flixel.*;
public class HelloState extends FlxState {
private var text:Flxtext;
public function HelloState():void {
text = new Flxtext(0, 0, 100, 10, "hello flixel", 0xffffffff);
this.add(text);
}
override public function update():void {
super.update();
}
}
}

Any help on this matter is appreciated.
Logged
Pages: [1] 2
  Print  
 
Jump to: