Nightmare Games Posted February 8, 2014 Share Posted February 8, 2014 I've just begun working with Phaser yesterday and I'm a bit confused about how to get my sprites drawn on the screen. I've noticed Phaser seems to draw images automatically, based on the order they're loaded in. For the game I'm working on, I'm not sure how to proceed using that method. None of the examples I've looked at have a traditional "draw game" or "render" function that draws everything each step, and I haven't been able to find information on any type of "draw sprite" function that would let me take control of the drawing myself. Does such a function exist? Link to comment Share on other sites More sharing options...
rich Posted February 8, 2014 Share Posted February 8, 2014 When you add a Sprite to the World (which is what game.add.sprite does automatically) it adds it to the display list. If you create a sprite outside of the factory, so just sprite = new Phaser.Sprite, then it won't render until it's added to the World (or a child that is already present in the World). But you never have to explicitly say 'render this sprite', which is why they don't have render methods. As soon as they are on the display list, they render until you either remove them or set their visible state to false. jerome 1 Link to comment Share on other sites More sharing options...
jpdev Posted February 8, 2014 Share Posted February 8, 2014 You can change the order the images are drawn in by changing their position in the display list. For example by calling bringToTop() on a sprite. (this sprite will then be drawn last an therefor over everything else.) jerome 1 Link to comment Share on other sites More sharing options...
jerome Posted February 9, 2014 Share Posted February 9, 2014 Suggestion for version 1.2bringToTop() is a Sprite class methodBrings the Sprite to the top of the display list it is a child of. Sprites that are members of a Phaser.Group are only bought to the top of that Group, not the entire display list.it's a useful method but it may be sometimes too limited.Maybe would it be appreciable to have a direct access to a DisplayList class with some methods to manage the render order (if it doesn't already exists, I couldn't find it) ? Link to comment Share on other sites More sharing options...
rich Posted February 9, 2014 Share Posted February 9, 2014 Due to changes in pixi 1.2 uses a normal flat array for display list order, so you can easily sort or shuffle it however you need to move things around. Link to comment Share on other sites More sharing options...
ram64 Posted February 9, 2014 Share Posted February 9, 2014 Just in case anyone needs this, in current build (1.1.4) I used the Group._container property to access the PIXI.DisplayObjectContainer and its swapChildren(child1, child2) method in order to sort groups in another group (or world). Link to comment Share on other sites More sharing options...
Recommended Posts