Qzlmnrk

Members
  • Content Count

    6
  • Joined

  • Last visited

  1. I'm using a large (3072x3840) spritesheet to play a sprite animation. However, when the animation is played for the first time, there's a noticeable pause where the first ~85% of the animation should be, possibly from the spritesheet being loaded into memory. What can I do to make the animation run smoothly the first time?
  2. The onInputDown handler only works if you press the mouse button after you hover over the button. If you hold down the mouse button and then hover over the button, it does nothing. I want to be able to activate the button by just hovering over it with the mouse button held down, even if I don't "click" per se.
  3. I already know how to destroy a group object when it collides with something else. However, I can't seem to find a way to delay the destruction of the object after the collision. The following code works for instantly destroying the otherThing in the otherThings group that the thing object overlaps: game.physics.arcade.overlap(thing, otherThings, removeOtherThing, null, this);function removeOtherThing (thing, otherThing) { otherThing.destroy();}What I want to do is delay the destruction of the otherThing object by an arbitrary amount. I can't seem to find a way that works, though, with the methods I've tried so far returning errors. Help would be appreciated!
  4. Thanks! Figured it out, game.input.onDown.add(swap, this); should've been in create().
  5. Thanks for the help! Now I'm facing another problem, though: the click only sometimes registers, going through some periods of not working and periods of working. I debugged it, and it doesn't seem to be caused by (this['bucket' + (Math.floor(arrow.x - 55) / 120)]) returning false. Any idea why?
  6. I'm working on a game and need help with an error (Uncaught TypeError: Cannot set property 'frame' of undefined) that appears when I run code inside a function. Here's the full game code, with the error at line 60: function getRandom(min, max) { return Math.floor((Math.random() * (max - (min - 1))) + min);}var game = new Phaser.Game(480, 360, Phaser.AUTO, '', { preload: preload, create: create, update: update });var colorPosition = [0, 1, 2, 3];function preload() { game.stage.disableVisibilityChange = true; game.stage.backgroundColor = '#393837'; game.load.image('collide', 'assets/collide.png'); game.load.spritesheet('bucket-front', 'assets/bucket-front.png', 112, 82, 4); game.load.spritesheet('square', 'assets/square.png', 20, 20, 4); game.load.image('arrow', 'assets/arrow.png'); game.load.spritesheet('bucket', 'assets/bucket.png', 112, 82, 4);}function create() { collide = game.add.sprite(0, 317, 'collide'); game.physics.enable(collide, Phaser.Physics.ARCADE); arrow = game.add.sprite(175, 230, 'arrow'); for (var x = 0; x < 4; x++) { this['bucket' + x] = game.add.sprite((x * 120) + 4, 278, 'bucket', x) } squares = game.add.group(); function addSquare() { square = squares.create((getRandom(0, 3) * 120 + 50), -20, 'square', getRandom(0, 3)); game.physics.enable(square, Phaser.Physics.ARCADE); square.body.velocity.y=100; } for (var x = 0; x < 4; x++) { this['bucketFront' + x] = game.add.sprite((x * 120) + 4, 278, 'bucket-front', x) } game.time.events.loop(Phaser.Timer.SECOND * 1, addSquare, this);}function update() { if ((game.input.x - 120) > 0 && (game.input.x + 120) <= 480) { arrow.x = ((Math.round((game.input.x - 120) / 120)) * 120) + 55; } function removeSquare(collide, square) { //square.kill(); } game.physics.arcade.overlap(collide, squares, removeSquare, null, this); //if (game.input.activePointer.isDown) { game.input.onDown.add(swap(), this) function swap() { //alert(colorPosition) //alert((arrow.x - 55) / 120 + 1) var swap = colorPosition[(arrow.x - 55) / 120] colorPosition[(arrow.x - 55) / 120] = colorPosition[(arrow.x - 55) / 120 + 1] colorPosition[(arrow.x - 55) / 120 + 1] = swap //alert(colorPosition) this['bucket' + (Math.floor(arrow.x - 55) / 120)].frame = colorPosition[(arrow.x - 55) / 120] //Here's the line the error occurs on this['bucket' + (((arrow.x - 55) / 120) + 1)].frame = colorPosition[((arrow.x - 55) / 120) + 1] this['bucketFront' + (Math.floor(arrow.x - 55) / 120)].frame = colorPosition[(arrow.x - 55) / 120] this['bucketFront' + (((arrow.x - 55) / 120) + 1)].frame = colorPosition[((arrow.x - 55) / 120) + 1] //this['bucketFront' + (arrow.x - 55) / 120].frame = parseInt(colorPosition[(arrow.x - 55) / 120]) //alert(this['bucket' + (((arrow.x - 55) / 120) + 1)].frame) //alert(colorPosition[((arrow.x - 55) / 120) + 1]) }}This is my first attempt to do anything with JavaScript, so please try to be patient.