A couple of newb questions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

A couple of newb questions

Richard Stranberg
Hello Everyone,

I have a couple of newb questions.

I'm interested in developing a 2D games in haxe that have a lot of objects
in them.  Most of them are stationary but some will move and be animated.  I
guess what I want to know is:

1)  What's the best way to move graphics around?  I've seen a lot of things
about sprites and even some code examples, but then I've also read that it's
hard to animate sprites.

Also, when I move characters around the screen, there'll be a lot of
stationary objects.
2)  Should these be sprties also?  Or simply bitmaps?  Or something else?

And finally, collision detection,
3)  I would like to navigate my character through a path with walls and not
being able to go through the walls.  Do I just make the walls separate
objects, create a coarse array that will contain whether a wall object
exists there or not and check the x and y coordiantes of my character when
it comes close to a corresponding wall object within that particular part of
the array?  Or is there a better way?

Thanks a lot for answering my newb questions.
Rick




--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: A couple of newb questions

Joacim Magnusson
Hi Rick,

When you deal with graphics in flash, pretty much everything will be a Sprite object, or something else derived from the DisplayObject class. Of course, you could write your own graphics engine that render to a BitmapData instance for more specialized graphics. But in most cases using the built-in Sprite class will do just fine.

If you need advanced animation, such as animating the limbs of your character etc, you can do that in the flash authoring app and import the swf using --swf-lib in the hxml file. Then you can use the library from that swf like so: mcFromFlash:MovieClip = flash.Lib.attach("NameOfObjectInLibrary");

Moving Sprites around and doing hit testing is easy since this is also built in. If you only have a few moving objects, simply doing "mySprite.hitTestPoint(x, y, true);" will work for pixel perfect collision detection. Then you can have all your walls and non-walk-through stuff in a single Sprite, and hit test against that sprite. Check out the documentation for the Sprite class: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Sprite.html

An other way of animating your world and achieving collision detection is to use a physics lib such as Box2D or PhysaXe. PhysaXe is really fast if you only need collision detection. Box2D is slower, but has more features and is better documented. The downside of this approach is that everything in your world needs to be a polygon. Google these for more info.

/J

On 22 nov 2009, at 06:24, Richard Stranberg wrote:

> Hello Everyone,
>
> I have a couple of newb questions.
>
> I'm interested in developing a 2D games in haxe that have a lot of objects
> in them.  Most of them are stationary but some will move and be animated.  I
> guess what I want to know is:
>
> 1)  What's the best way to move graphics around?  I've seen a lot of things
> about sprites and even some code examples, but then I've also read that it's
> hard to animate sprites.
>
> Also, when I move characters around the screen, there'll be a lot of
> stationary objects.
> 2)  Should these be sprties also?  Or simply bitmaps?  Or something else?
>
> And finally, collision detection,
> 3)  I would like to navigate my character through a path with walls and not
> being able to go through the walls.  Do I just make the walls separate
> objects, create a coarse array that will contain whether a wall object
> exists there or not and check the x and y coordiantes of my character when
> it comes close to a corresponding wall object within that particular part of
> the array?  Or is there a better way?
>
> Thanks a lot for answering my newb questions.
> Rick
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

RE: A couple of newb questions

Richard Stranberg
In reply to this post by Richard Stranberg

Thanks a lot, Joacim!  That's exactly what I was looking for.  I was over at
Nicolas's blog yesterday looking at PhysaXe.  Pretty impressive!  I think
I'm starting to get the big picture in this now.  For a while I had a big
"disconnect" in my head.  I didn't understand why people would refer to the
adobe AS3 (or whichever) API documentation; I always thought that "haXe is
it's own language, where are its' APIs?"  I don't know why it took me so
long to understand that just like any language, you have the language itself
that you develop in and the API's to the machine that you're working on - in
this case Adobe's Flash engine.  I just don't do this enough...!

Thanks again!

Rick




Hi Rick,

When you deal with graphics in flash, pretty much everything will be a
Sprite object, or something else derived from the DisplayObject class. Of
course, you could write your own graphics engine that render to a BitmapData
instance for more specialized graphics. But in most cases using the built-in
Sprite class will do just fine.

If you need advanced animation, such as animating the limbs of your
character etc, you can do that in the flash authoring app and import the swf
using --swf-lib in the hxml file. Then you can use the library from that swf
like so: mcFromFlash:MovieClip = flash.Lib.attach("NameOfObjectInLibrary");

Moving Sprites around and doing hit testing is easy since this is also built
in. If you only have a few moving objects, simply doing
"mySprite.hitTestPoint(x, y, true);" will work for pixel perfect collision
detection. Then you can have all your walls and non-walk-through stuff in a
single Sprite, and hit test against that sprite. Check out the documentation
for the Sprite class:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Spri
te.html

An other way of animating your world and achieving collision detection is to
use a physics lib such as Box2D or PhysaXe. PhysaXe is really fast if you
only need collision detection. Box2D is slower, but has more features and is
better documented. The downside of this approach is that everything in your
world needs to be a polygon. Google these for more info.

/J

On 22 nov 2009, at 06:24, Richard Stranberg wrote:

> Hello Everyone,
>
> I have a couple of newb questions.
>
> I'm interested in developing a 2D games in haxe that have a lot of objects
> in them.  Most of them are stationary but some will move and be animated.
I
> guess what I want to know is:
>
> 1)  What's the best way to move graphics around?  I've seen a lot of
things
> about sprites and even some code examples, but then I've also read that
it's
> hard to animate sprites.
>
> Also, when I move characters around the screen, there'll be a lot of
> stationary objects.
> 2)  Should these be sprties also?  Or simply bitmaps?  Or something else?
>
> And finally, collision detection,
> 3)  I would like to navigate my character through a path with walls and
not
> being able to go through the walls.  Do I just make the walls separate
> objects, create a coarse array that will contain whether a wall object
> exists there or not and check the x and y coordiantes of my character when
> it comes close to a corresponding wall object within that particular part
of

> the array?  Or is there a better way?
>
> Thanks a lot for answering my newb questions.
> Rick
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org





--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: RE: A couple of newb questions

gershon
2D Games have been with us for about 3 decades, so most of the things you've mentioned have already been named in the "jargon"...
"Graphically moving about", can range from "jumping" from tile to tile on the screen, in constant gird-sized steps, to "simple" movement (sprite.x++), and complex parametric physical simulations, using floating-point values and sub-pixel rendering...

Sprite in the old (non-flash) sense, usually meant you'd have a so called "Sprite-sheet" (http://www.freewebs.com/hadouken_dude/DBZvegetassj2.gif), from which parts would be cropped in accordance to a specific action \ frame, those are just bitmaps.

Sprite in flash's sense (which i'm guessing is the platform we're talking about) is a much more generic thing, which does'nt necessarily contain color bits,  but can also hold parametric curves ("Vectors" in designer's jargon) and surfaces.

Regarding (3), there's more than one way to go about this, the simplest being "Tile-Based", found in most "Side-Scrolling Platforms" (mario clones :)), much like you've said, usually a 2D int array is used (Array<Array<Int>>) where the indices specify offset from the top left, and the value an offset in a sprite-sheet:
00000000000
00000000010
00100001110
22222222222

Tile sized is costant, usually 2^n, 32x32, 64x64... Values can be, 0 - Sky, 1 - Rock, 2 - Ground...
The simplest form of collision detection is called "Bounding-Box Collision Detection", and is still used as a primary stage to minimize cpu cycles when doing more complex "Pixel-Perfect Collision Detection".

One last thing i'd like to mention, regards AI, "Pathfinding" is used when the baddie chases the player (http://lib.haxe.org/p/aPath for haxe is sweet), "Line-of-Sight" is when those nasties shoot at you :)

Best of luck, and remember than writing the thing should be at least as fun as playing it.


On Mon, Nov 23, 2009 at 1:34 AM, Richard Stranberg <[hidden email]> wrote:

Thanks a lot, Joacim!  That's exactly what I was looking for.  I was over at
Nicolas's blog yesterday looking at PhysaXe.  Pretty impressive!  I think
I'm starting to get the big picture in this now.  For a while I had a big
"disconnect" in my head.  I didn't understand why people would refer to the
adobe AS3 (or whichever) API documentation; I always thought that "haXe is
it's own language, where are its' APIs?"  I don't know why it took me so
long to understand that just like any language, you have the language itself
that you develop in and the API's to the machine that you're working on - in
this case Adobe's Flash engine.  I just don't do this enough...!

Thanks again!

Rick




Hi Rick,

When you deal with graphics in flash, pretty much everything will be a
Sprite object, or something else derived from the DisplayObject class. Of
course, you could write your own graphics engine that render to a BitmapData
instance for more specialized graphics. But in most cases using the built-in
Sprite class will do just fine.

If you need advanced animation, such as animating the limbs of your
character etc, you can do that in the flash authoring app and import the swf
using --swf-lib in the hxml file. Then you can use the library from that swf
like so: mcFromFlash:MovieClip = flash.Lib.attach("NameOfObjectInLibrary");

Moving Sprites around and doing hit testing is easy since this is also built
in. If you only have a few moving objects, simply doing
"mySprite.hitTestPoint(x, y, true);" will work for pixel perfect collision
detection. Then you can have all your walls and non-walk-through stuff in a
single Sprite, and hit test against that sprite. Check out the documentation
for the Sprite class:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Spri
te.html


An other way of animating your world and achieving collision detection is to
use a physics lib such as Box2D or PhysaXe. PhysaXe is really fast if you
only need collision detection. Box2D is slower, but has more features and is
better documented. The downside of this approach is that everything in your
world needs to be a polygon. Google these for more info.

/J

On 22 nov 2009, at 06:24, Richard Stranberg wrote:

> Hello Everyone,
>
> I have a couple of newb questions.
>
> I'm interested in developing a 2D games in haxe that have a lot of objects
> in them.  Most of them are stationary but some will move and be animated.
I
> guess what I want to know is:
>
> 1)  What's the best way to move graphics around?  I've seen a lot of
things
> about sprites and even some code examples, but then I've also read that
it's
> hard to animate sprites.
>
> Also, when I move characters around the screen, there'll be a lot of
> stationary objects.
> 2)  Should these be sprties also?  Or simply bitmaps?  Or something else?
>
> And finally, collision detection,
> 3)  I would like to navigate my character through a path with walls and
not
> being able to go through the walls.  Do I just make the walls separate
> objects, create a coarse array that will contain whether a wall object
> exists there or not and check the x and y coordiantes of my character when
> it comes close to a corresponding wall object within that particular part
of
> the array?  Or is there a better way?
>
> Thanks a lot for answering my newb questions.
> Rick
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org





--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org