rpiller Posted April 15, 2014 Share Posted April 15, 2014 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 More sharing options...
rich Posted April 15, 2014 Share Posted April 15, 2014 Tilemap layers are just Phaser Sprites, so you can move them around the display list like any other Sprite. Insert objects (like your player) between them, etc. rpiller 1 Link to comment Share on other sites More sharing options...
rpiller Posted April 15, 2014 Author Share Posted April 15, 2014 How do you insert between the layers? If I create the character between then it works, but what if I need to dynamically create characters during run-time. How do I "insert" them between the layers. Link to comment Share on other sites More sharing options...
rich Posted April 15, 2014 Share Posted April 15, 2014 Don't forget that the game world is a Phaser Group, so anything you can do with a Group re: insertion, sorting, moving, you can do to the world too. Link to comment Share on other sites More sharing options...
rpiller Posted April 15, 2014 Author Share Posted April 15, 2014 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 More sharing options...
rich Posted April 15, 2014 Share Posted April 15, 2014 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 More sharing options...
rpiller Posted April 15, 2014 Author Share Posted April 15, 2014 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 More sharing options...
rich Posted April 15, 2014 Share Posted April 15, 2014 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 More sharing options...
rpiller Posted April 15, 2014 Author Share Posted April 15, 2014 Ah, OK so that makes sense now. Sorry, I've been in the 3D realm of game creation for a long time where creation order doesn't matter, but I'm following this now. Thanks for all your help! Link to comment Share on other sites More sharing options...
Recommended Posts