Jump to content

Carousel: Project Advice


Recommended Posts

Hey everyone!


I'm brand new here and I'm just getting into Phaser.


Currently, I'm attending an intensive coding bootcamp, where we cram 2 years worth of code school into 3 months. I'm almost done school, aced my tests, and am now starting on my final project. I want to do an interactive, point-and-click story. My instructor recommended Phaser and I'm enjoying using it so far while playing around with tutorials.


Since I'm a newbie and I have only 3 weeks to finish this short project, I really need some help! I hope that I can learn from the more experienced Phaser users. :)


Two of the things I need to accomplish in the game are:


1. I need to figure out how to bind a sprite's movement to the cursor's movement and have the sprite rotate down on click. It's a mini-game where players use a bug net they collect earlier to catch bugs. I've tried searching online for answers and can't find anything. The bug net replaces the cursor and every time the player clicks, the sprite responds by taking a swipe with the net.


2. Have the bugs that the player is catching fly in randomized patterns on/ off the screen and pick up speed every time one is caught to increase difficulty.


3. Creating a timed event. The player only has 1 minute to catch as many fireflies as they can.


I know, I'm a noob! I just really want my final project to be something fun! I've even hired an illustrator to create professional backgrounds and sprites for the game. Any assistance would be appreciated. :)

Link to comment
Share on other sites

There's no built-in Phaser classes to handle randomised sprite patterns, so you'll have to just come up with something for that. You could look at the Coding Tips tutorials, the WaveForms one has some nice path code in you can use.


For a timed event look at the Time examples on the examples site - but it's as simple as 'game.time.events.add(1000 * 60, gameOver, this)'.


Didn't totally understand 1) - should the sprite follow the mouse or move based on keyboard cursors?

Link to comment
Share on other sites

I actually figured out #1 on my own. I wanted the sprite to follow the mouse's movement tightly, so that the mouse could take over the sprite's position.

function preload( ) {     game.load.image('bugnet', 'assets/bugnet.png');},function create( ) {      bugnet = game.add.sprite(400, 300, 'bugnet');      bugnet.name = 'bugnet';      bugnet.anchor.setTo(0.5, 0.5);      game.physics.enable(bugnet, Phaser.Physics.ARCADE);      bugnet.body.allowRotation = false;},function update( ) {     bugnet.rotation = game.physics.arcade.moveToPointer(bugnet, 0, game.input.activePointer, 100);}

With this one, I do find that my sprite rotates like crazy, though. Is there any way to keep the sprite staying straight? I'm sure it has to do with the allowRotation, but I'm not experienced enough on Phaser to know if there's anything better to use?

For the randomized patterns, I found these:


However, I'm not sure how exactly to implement this into my code. What I'm trying to accomplish is to have the player move the net around with their mouse position. The fireflies will move in random paths. When bugnet overlay on firefly is true, the player can click and the bug will be collected. This will increase the bug counter by +1. They objective is to collect as many fireflies in 60 seconds as possible, with a minimum to continue on the story.

Link to comment
Share on other sites

So, we ended up figuring out how to stop the net from rotating and we're working on having the bugs move randomly.


Right now I'm encountering a problem as I add sound effects.


preload: function(){     game.load.audio('net_swish', 'assets/Sounds/net_swish.ogg');},create: function(){     netswish = game.add.audio('net_swish');     ...     game.input.activePointer.leftButton.onDown.add(function(e)        {          game.sound.play('netswish')        });},

I'd like for the sound to play when the mouse is clicked. However, I keep getting this error message in my Google dev console:


Phaser.Cache.isSoundDecoded: Key "netswish" not found in Cache.phaser.js:70169 Phaser.Cache.getSound: Key "netswish" not found in Cache.

Here's where it points to in the Phaser.js file:

getItem: function (key, cache, method, property) {        if (!this.checkKey(cache, key))        {            if (method)            {            >>>>    console.warn('Phaser.Cache.' + method + ': Key "' + key + '" not found in Cache.');            }        }

I've done some research and can't find much information on this error. From what I gather, the ogg file failed to be decoded? I'm not really sure. Any suggestions?

Link to comment
Share on other sites


  • Recently Browsing   0 members

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