ISOmetric

Members
  • Content Count

    10
  • Joined

  • Last visited

About ISOmetric

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I'm not sure how I would be able to use this in to context of the update function. Would I have to check every sprite in locks against every sprite in slots continually, using something like forEach?
  2. I have two groups of sprites, lets call them locks and slots, and each slot has a custom parameter, lets call it slot.locked. I want to implement functionality whereby when any one of the locks is overlapping a slot, the variable slot.locked becomes true, which I managed to implement as follows: function update() { game.physics.arcade.overlap(locks, slots, lockOverlap); } function lockOverlap(lock, slot) { slot.locked = true; } But now I want to have a situation in which whenever a lock is NOT overlapping a slot, the parameter slot.locked becomes false again. Any ideas? Thanks.
  3. I shall look into that but I think it's unlikely, as I can see this behavior when I have a single rectangle on it's own. I'll put together a sandbox to try and replicate it. EDIT: here's a sandbox: https://phaser.io/sandbox/PStxrwRb/play There's some oddness occurring when the circles hit the side of the purple square (they should bounce off, but they vanish) which isn't happening on my local version but I think the issue I'm having is quite clearly replicated. Also, sorry my code is a mess, I'm currently refactoring and I've been doing some chopping and changing.
  4. I have an issue where I've got a row of rectangular sprites, drawn with phaser graphics, sitting in a seamless row. I then have some circle sprites set to move with set velocity in any of four directions (200x200, 200x-200, -200x200 or -200x-200) and bounce off this row of rectangular sprites. However, and this is behavior I've noticed before in a similar situation, whenever a circle sprite hits a rectangular one directly on the corner, the velocity drops drastically and it's direction changes substantially. Any clue on why this particular behavior occurs and any steps I can take in fixing it?
  5. You really are a very big help samme, but it seems that every time I try to move to the next step of this process, there's something interfering! I think I'm having an issue with setting the velocity after ejecting a circle from a slot. It also seems to be somehow tied into my timer(s). When a circle is ejected, it heads off at a velocity of 200x200 (south-east, I guess) but has some odd behavior when it hits the game bounds. I think it's still trying to move at the same velocity even though it has hit a wall, so it judders in the corner for a few seconds before bouncing. I think this is the core bit of the code where problems are arising: function disable_collision(circle){ circle.body.checkCollision.none = true; } function enable_collision(){ this.body.checkCollision.none = false; } function eject_circle(){ // Function to remove a circle from a slot circle = this[0]; slot = this[1]; disable_collision(circle); circle.body.velocity.setTo(200,200); timer = game.time.create(false); // Give the cirle 'enough time' to leave the slot before re-enabling collision // ?? Is a timer the best way to do this? timer.add(150, enable_collision, circle); timer.start(); circle.tint = 0xFFFFFF; slot.tint = 0xFFFFFF; } function on_overlap(slot, circle) { // Function called when a circle overlaps with a slot circle.tint = 0x000FFF; slot.tint = 0xBB00BB; circle.x = slot.x; circle.y = slot.y; circle.body.velocity.setTo(0,0); timer = game.time.create(false); // Hold the circle in the slot for 4 seconds, then eject timer.add(4000, eject_circle, [circle, slot]); timer.start(); } The full example, with the behavior described, is here: https://phaser.io/sandbox/edit/IlpZAzQN and the above functions can be found in the 'update' panel. NB: I've set my game bounds to 1000 by 450 - the blue section to the right is my 'drag tray' for which I haven't implemented much functionality yet. Thanks for the help! I really appreciate it!
  6. The callback has fixed my problem, thanks very much samme. However, I've now hit another issue, where I want to deactivate the callback for a short period of time. As I said before, I'm trying to get the circles to move onto the slots, sit for a while and then move off again. I've got the timer working, so they sit for the time I've allocated, but as soon as they start to move off the slot they are still intersecting it.. and the callback function is called again. This happens repeatedly, so once a circle moves to a slot it essentially just sits there permanently. Any advice for that? Thanks.
  7. Thanks samme, didn't realize I could do that with entire groups! With this format, how would I implement events that should happen upon each intersection? In my particular case, I want to create a system where whenever a circle intersects a slot, the circle moves to the centre of the slot and sits for a few seconds before moving on? I know how I would implement this with single objects but not with groups of objects.
  8. I've got a wee game where I've created a group of circles and a group of rectangles (they're called slots in the code) which are placed randomly on the canvas. The circles move around the world pseudo-randomly and when they intersect with a slot, the text at the top of the screen should change. However, I'm struggling to 'traverse' the groups properly: my function only checks one specific circle against one specific slot. I'm still pretty new to Phaser, and this 'game' is cobbled together from various examples so I'm sorry if it doesn't make much sense. Here's the sandbox: https://phaser.io/sandbox/edit/EilDwRdH And here's the markup of the specific functions I'm using to check intersection: function update() { circles.forEach(function(c_circle) { slots.forEach(function(c_slot) { if (checkOverlap(c_circle, c_slot)) { text.text = 'Overlapping: true'; } else { text.text = 'Overlapping: false'; } }); }); } function checkOverlap(spriteA, spriteB) { var boundsA = spriteA.getBounds(); var boundsB = spriteB.getBounds(); return Phaser.Rectangle.intersects(spriteA, boundsB); }
  9. I see. Thanks Rich, I have it working now.
  10. I am looking at this Phaser example, and am simply trying to replace the aliens sprites with simple filled circles drawn by graphics - I've also removed the car, I just want some sprites moving around the area randomly. Unfortunately, the sprites appear with the "no image" graphic. I'm not sure what I am doing wrong here, any help is appreciated: var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create }); var aliens; var sprite; function preload() { sprite = game.make.graphics(0,0); sprite.beginFill(0x00FFFF, 1); sprite.boundsPadding = 0; sprite.drawCircle(50, 50, 100, 100); } function create() { game.physics.startSystem(Phaser.Physics.ARCADE); aliens = game.add.group(); aliens.enableBody = true; for (var i = 0; i < 10; i++) { var s = aliens.create(game.world.randomX, game.world.randomY, sprite); s.name = 'alien' + s; s.body.collideWorldBounds = true; s.body.bounce.setTo(0.8, 0.8); s.body.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40); } }