• Content Count

  • Joined

  • Last visited

About JackAttack

  • Rank

Contact Methods

  • Website URL
  • Twitter

Profile Information

  • Gender
  • Location
    Norfolk, England

Recent Profile Visitors

776 profile views
  1. I think the inCamera property of the sprite does what you need here.
  2. Issue solved, the reference to goToZone should not have the brackets. So: this.game.camera.onFadeComplete.add(this.goToZone, this); works as expected.
  3. So my code currently looks like: this.game.camera.fade(0x112C06, 1500, true); this.game.camera.onFadeComplete.add(this.goToZone(), this); However this.goToZone() is fired immediately, not after 1500 miliseconds. The fade effect does not show at all. If I comment out the onFadeComplete line, the fading does happen successfully. I've tried putting the onFadeComplete line before the fade line, but it has no effect. Does anyone know what is missing here? I'm using Phaser CE 2.8.3.
  4. Thanks Samme, will have a play around there.
  5. I'm trying to create a fast-forward mode in a tower defence game. The physics time can be sped up threefold simply using the following: game.time.slowMotion = 1/3; game.time.desiredFps = 20; The problem is the game has many timed events, which use game time, not the physics time that slow-motion affects, set up using code like the following: game.time.events.add( Phaser.Timer.SECOND * seconds, this.spawnAttacker, this, className ).autoDestroy = true Where seconds is some numeric value. So the physics time speeds up 3x just fine, however in the above example, the spawnAttacker function still only occurs every real-time X seconds. I want it to be modified by game.time.slowMotion. I know I could just do Phaser.Timed.SECOND * seconds * game.time.slowMotion; however when fast-forward mode is toggled on/off, all the existing scheduled events will then be incorrect. Does anyone know if it is possible to schedule events like this in the physics time which game.time.slowMotion will affect?
  6. Stumbled across this thread as I'm looking to do something very similar. One question if anyone can answer: Is it possible to make this also change the speed at which events are fired? So if slowMotion is set to 1/3 (0.3333 ish), an event that is scheduled for 3 seconds in the future changes to 1 second. Maybe changing the value of Phaser.Timer.SECOND? And also iterating over each event already scheduled and changing when it is due to fire? The use case for me would be a fast-forward mode that can be toggled on and off.
  7. I'm using the following code to capture key entry, just numbers for now, but I would like to capture all keys. this.key0 = game.input.keyboard.addKey(Phaser.Keyboard.ZERO); this.key1 = game.input.keyboard.addKey(Phaser.Keyboard.ONE); this.key2 = game.input.keyboard.addKey(Phaser.Keyboard.TWO); this.key3 = game.input.keyboard.addKey(Phaser.Keyboard.THREE); this.key4 = game.input.keyboard.addKey(Phaser.Keyboard.FOUR); this.key5 = game.input.keyboard.addKey(Phaser.Keyboard.FIVE); this.key6 = game.input.keyboard.addKey(Phaser.Keyboard.SIX); this.key7 = game.input.keyboard.addKey(Phaser.Keyboard.SEVEN); this.key8 = game.input.keyboard.addKey(Phaser.Keyboard.EIGHT); this.key9 = game.input.keyboard.addKey(Phaser.Keyboard.NINE); for (let i = 0; i <= 9; ++i) { this['key' + i].onDown.add(this.keyPress, this); } and keyPress(key) { let character = String.fromCharCode(key.keyCode); this.keyInput += character; this.checkForCode(); } Do I need to call game.input.keyboard.addKey for every single key I want to detect? I feel like I missing be missing some functionality that listens for any key press. This doesn't need to work on phones, the purpose is cheat code entry in a computer browser only for my own testing purposes.
  8. Thanks umz! I've got it working as desired now.
  9. I've bought a few sets of royalty free game art, which include some tilesets I would like to used in Tiled. Each tile has its own PNG file, way larger than I want to be using (e.g. 512x512 or 256x256). There are also object images which are not uniform dimensions. Does anyone know if there any software that I can import all these files into, merge them into one file, and resize them all to something usable? When searching about this I've found recommendations for TexturePacker, which I have, however it automatically arranges each image to fit in a smaller space. I just need each image to occupy a square the same size. I could do it manually in some image software, or maybe write a script to do it, but it seems like it must be a common task and surely there's already something out there?
  10. Thanks Bobomite, I'm actually doing something a bit different here, which is redirecting each bullet towards a target I've given it (which is a sprite). If anyone is interested, the code I'm using is: // Begin bullet heat-seeking this.towers.forEach(function(tower) { if (tower.weapon1) { tower.weapon1.bullets.forEach(function (bullet) { if (bullet.target && bullet.target.alive) { var midPoint = mainState.getMidPointBetweenSprites(bullet, bullet.target); var moveX = Math.cos(this.game.math.degToRad(midPoint.angle)) * bullet.speed; var moveY = Math.sin(this.game.math.degToRad(midPoint.angle)) * bullet.speed; bullet.body.velocity.set(moveX, moveY); } }); } }, this); // End bullet heat-seeking The getMidPointBetweenSprites function I use here provides the angle: mainState.getMidPointBetweenSprites = function(spriteA, spriteB) { return { x: Math.round((spriteA.x + spriteB.x) / 2), y: Math.round((spriteA.y + spriteB.y) / 2), angle: Math.atan2(spriteB.y - spriteA.y, spriteB.x - spriteA.x ) * (180/Math.PI) } };
  11. Thanks Samid, using the weapon object got me there. In my case, each weapon is found at weapon1 property in a tower object, which is in the towers group, so my code looks like: this.towers.forEach(function(tower) { if (tower.weapon1) { tower.weapon1.bullets.forEach(function (bullet) { console.log(bullet) }); } }, this);
  12. I'm making a tower defence game and it uses bullets generated through Phaser's weapon/bullet plugin. I want to iterate over them within the game state's update(), however when I do either of the following: this.game.children.forEach(function(bullet) { console.log(bullet); }, this); this.game.bullets.children.forEach(function(bullet) { console.log(bullet); }, this); The bullet object is the group of bullets, not the bullet sprite itself. Inspecting bullet, I can see it has a children property, which is an array of the bullet sprites I want. Alas, trying this.game.bullets.children.forEach() still doesn't get them. The equivalent code on a different group, such as: this.game.towers.forEach(function(tower) { console.log(tower); }, this); behaves as expected, tower is a tower sprite, and not it's containing group. Is there something special about the bullets group that is causing this? If so, is there a way of getting all bullets?
  13. Hello everyone, I'm making a basic tower defence game, and am trying to prevent towers being placed on the pathway. In this case, the pathway is everywhere which is not in this.layers.collision. The following code creates a sprite which is rectangular/square in shape. The size of the sprite seems to be coming from somewhere else in my code, can't pinpoint where, but I've made it smaller so it definitely does not overlap other tiles (used the debugger to visualise this). The x and y co-ordinates are the position of the mouse/input, translated to the top-left corner of it's tile. The tiles are 35 pixels square, so a mouse position of [358, 362] would become [350, 350]. this.pathwayPlacementRectangle = game.add.sprite(x + 8, y + 8, null); game.physics.enable(this.pathwayPlacementRectangle, Phaser.Physics.ARCADE); this.pathwayPlacementRectangle.scale.setTo(0.5, 0.5); var onPathway = true; if (game.physics.arcade.collide(this.pathwayPlacementRectangle, this.layers.collision)) { onPathway = false; } I've offset the rectangle a bit and made it smaller in case it was clashing with the edges of the collision layer. The problem is onPathway is always false, even when this.pathwayPlacementRectangle is not located over the collision layer. If I replace this.layers.collision with another group in the game, such as some moving sprites, the code works as expected. Similarly, if I replace this.pathwayPlacementRectangle with something else, like a group of sprites, the code again works as how you would expect. Possibly I'm doing something wrong with the sprite creation. Can anyone point me in the right direction please?