Jump to content

RPG style map and making characters fit into a specific layer


rpiller
 Share

Recommended Posts

I have an RPG style game that has 3 layers created in Tiled. Ground layer, Object layer, & Foreground layer. I create my player character in code and I'm wondering how I can make it drawn in the same layer as the Object layer so that foreground objects are drawn on top of the character.

 

I can't seem to find any layer.addObject(player) or something like that.

 

 

I see http://examples.phaser.io/_site/view_full.html?d=groups&f=depth+sort.js&t=depth%20sort but is this the only way? Doesn't seem all that efficient to always have to sort when it's not really needed. Also, this does a group.create() but I don't want to create, I'd want to add objects already created from the Tiled json map.

Link to comment
Share on other sites

I didn't even know what a world was since I haven't seen any phaser basics that explain such a thing. Just source code that has a bunch of assumptions.

 

"A game has only one world. The world is an abstract place in which all game objects live. It is not bound by stage limits and can be any size. You look into the world via cameras. All game objects live within the world at world-based coordinates. By default a world is created the same size as your Stage."

 

So it seems the creation order of things matters in how things are ordered in the world to be drawn and everything gets added to this one world container. This would mean I need to know where these characters are in the world in order to be able to insert other characters at run-time dynamically so they get drawn in the right order.

Link to comment
Share on other sites

The creation order of things always matters in display list based frameworks (Phaser, Flash, etc). The earlier you create it, the further to the back it is.

 

Knowing where something is in a Group is easy, just look at its z property.

 

Plus lots of other Group methods like "getAt", "getIndex", etc.

 

http://docs.phaser.io/Phaser.Group.html

Link to comment
Share on other sites

So I should create an actor, on startup in between my layers, that I use as a marker in the world and when I need to create other actors dynamically I find that actors index and insert my other actors after (which I assume pushes everything else back?). Seems a little strange to me but it should work.

Link to comment
Share on other sites

Dunno, depends on your game. If you're going to need loads of objects between 2 Tilemap Layers then create a Group between them instead. Then you can add and remove as many sprites to that Group as you need, and never have to shuffle anything around.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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