• Content Count

  • Joined

  • Last visited

  1. From the documentation, that big unknown for noobs like me: audio(key, urls, autoDecode) → {Phaser.Loader} Adds an audio file to the current load queue. The file is not loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. So basically, game.load.audio() after preload isn't loading the song, just adding it to a queue for later. In order to load the song, I also need to invoke game.load.start(): create: function(){ game.load.audio('pixel_world', ['assets/music/pixel_world_lo.ogg', 'assets/music/pixel_world_lo.mp3']); game.load.start(); // THIS! // good things follow...}
  2. Hi all, I wonder whether it would be possible to load an asset dynamically at a given time in Phaser rather than loading everything in the preload function. The reason for this is simple: I have a game with three different levels, all of which have different background songs; and so I'd rather only load a single song at startup to reduce loading times. Right now, my preload function looks like this: preload: function(){ game.load.audio('pixel_world', ['assets/music/pixel_world_lo.ogg', 'assets/music/pixel_world_lo.mp3']); game.load.audio('second_source', ['assets/music/second_source_lo.ogg', 'assets/music/second_source_lo.mp3']); game.load.audio('reboot_complete', ['assets/music/reboot_complete_lo.ogg', 'assets/music/reboot_complete_lo.mp3']); game.load.image('pickup', 'assets/img/pickup.png');}I tried moving one of the game.load.audio() calls to the create function instead: create: function(){ game.load.audio('pixel_world', ['assets/music/pixel_world_lo.ogg', 'assets/music/pixel_world_lo.mp3']); // good things follow...}However, the following calls fail: this.cache.isSoundDecoded(level.song)// Phaser.Cache.isSoundDecoded: Key "pixel_world" not found in Cache.song = game.add.audio(level.song);// Phaser.Cache.getSound: Key "pixel_world" not found in Cache.Do you know how I can get this to work, or any other way to ensure that the three songs are not loaded at game startup? Thank you!
  3. In case anyone has the same problem, StackOverflow gave me the solution. The key to have groups in layers is to add the groups in order: the group I add in the first place is always going to be shown in the bottom. One of the Phaser examples shows that you can edit the z-indices for a group, but this is misleading IMHO. Phaser doesn't seem to care about a group having a certain z value; if it's added last, it's painted on top of everything else.
  4. Hi all, I've been trying to achieve a certain effect. I have two polygons, one of which is still while the other moves, and when they overlap, I want to have the still polygon on top. However, it always seems to be the moving polygon that remains on top. I've been trying to use groups following the example here, to no avail. Here is (most of) the offending code: var LayerTest = { preload: function () { }, create: function () { game.world.setBounds(-SIZE_X / 2, -SIZE_Y / 2, SIZE_X / 2, SIZE_Y / 2); var center_group = game.add.group(); center_group.z = 1; var center_hexagon_graphics = new Phaser.Graphics(game, 0, 0); var center_hexagon_poly = buildRegularPolygon(0, 0, 6, 40); center_hexagon_graphics.beginFill(CENTER_COLOR); center_hexagon_graphics.drawPolygon(center_hexagon_poly); center_hexagon_graphics.endFill(); center_group.add(center_hexagon_graphics); var moving_group = game.add.group(); moving_group.z = 0; moving_graphics = new Phaser.Graphics(game, 0, 0); moving_group.add(moving_graphics); }, update: function () { var moving_poly = new Phaser.Polygon([ new Phaser.Point(-SIZE_X / 2 + tick, -10), new Phaser.Point(-SIZE_X / 2 + tick, 10), new Phaser.Point(20 - SIZE_X / 2 + tick, 10), new Phaser.Point(20 - SIZE_X / 2 + tick, -10), ]); moving_graphics.clear(); moving_graphics.beginFill(ALT_COLOR); moving_graphics.drawPolygon(moving_poly); moving_graphics.endFill(); tick++; }};This particular example creates a regular hexagon around (0,0), and a small yellow square in the left side of the screen that then moves right and overlaps with the hexagon. Even though I set moving_group.z to 0 and center_group.z to 1, it always paints the small square on top. I also tried to do without the groups, setting the z indices on the graphics directly, but it didn't make a difference. Any help will be much appreciated. layer-test.zip