Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

About to jump use phaser for a project, a few questions


onedayitwillmake
 Share

Recommended Posts

Hey so i've been watching the Phaser framework for a bit, and about to switch a game I've been working on in another framework to use Phaser. However I have a few questions just to make sure I'm using it right.

 

 

How does world work, vs the stage?

It looks like a World contains a Stage, and you add new objects to the world not the stage, is this correct?

 

How does a group work, what is an example use case?

 

What is the GameObjectFactory, should I use this to create my objects instead of just creating and adding them to the world myself? It looks like a nice little convenience class, i'm just wondering if there are any additional benefits.

 

Also I notice there are 2 physics engine, the simpler one basically providing nice AABB collision stuff and the more advanced one (ArcadePhysics?), I read in the docs that it's still in development? Could anyone provide a bit more info about those, pros cons etc?

 

 

Link to comment
Share on other sites

1) World vs. Stage

 

Think of the Stage is being like the game container. So it's the same size as the canvas, controls the background colour, etc.

 

World is more of an abstract thing. It has a width and height, and every Sprite, Particle, etc is positioned within the World. Every object is a child of the World (or should be if you want it rendered). The Camera is used to view a section of the world.

 

2) Groups are for grouping similar objects together, especially if you need fast recycling of those objects. For example say you're doing a shoot-em-up you'll need bullets. So you could create a bullets group and add a bunch of bullets to it, then set them all to 'dead'. When the player fires you can tell the group to give you the first "dead" bullet, revive it and launch it. Once it leaves the screen / hits something it can be set to dead again. It's a way to avoid constantly creating objects (which is expensive in JavaScript) and instead 'pool' them. Groups have lots of useful functions too (look through src/core/Group.js to see until the docs are done).

 

You can also collide a group with a sprite, or another group.

 

3) The game object factory is basically a way to quickly create common objects and set them in ready in the world. When you do: game.add the 'add' part of that is the factory. It basically cuts down on code quite a bit. You can create a new sprite and add it to the world in a single compact call, rather than having to do "var x = new Phaser.Sprite(game...), game.world.add(x)," etc.

 

4) Right, ArcadePhysics is the only fully implemented and working one at the moment. Advanced is still being worked on and to be honest I'm not 100% sure if we'll carry on with it or move to using something else. Pros/cons depend on the type of game you're making. For a large majority you can get away with AABB just fine and on low powered mobile browsers it's the fastest option by far (second only to "no collision" :). Also doesn't use much memory or overhead. As soon as you enter the realms of Box2D or Chipmunk that all changes. But then for some game types it is essential.

Link to comment
Share on other sites

Great information, thanks a lot.

I'm already into the library as I love the structure coding paradigms you've chosen to follow. 

 

So a group can be considered like an object pool (among other things)? Very cool.

 

I'm going to be using ChipmunkPhysics JS port ( https://github.com/josephg/Chipmunk-js ) for the game since I need the more intricate collision dynamics as well as various joint types.  Hopefully I can make a plugin for it to be used with Phaser, can you describe the plugin system a bit - although it seems straight forward

 

Great library btw 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...