Search the Community

Showing results for tags 'arcade physics'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser
    • Pixi.js
    • Babylon.js
    • Panda.js
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 32 results

  1. Hi i'm quite new to phaser but ive been making this game for a school project where you control a helicopter and when the helicopter body collides with the water refill building it refills the water but if i go up against the side of the building and change direction it flips my helicopter so that it flys the other direction which then makes the helicopter overlapping the water refill building and my game crashes and i get this error Game.js:342 Uncaught ReferenceError: refill is not defined at Function.<anonymous> (Game.js:342) at Phaser.Physics.Arcade.collideSpriteVsSprite (phaser.js:80431) at Phaser.Physics.Arcade.collideSpriteVsGroup (phaser.js:80520) at Phaser.Physics.Arcade.collideHandler (phaser.js:80369) at Phaser.Physics.Arcade.overlap (phaser.js:80121) at Object.update (Game.js:341) at Phaser.StateManager.update (phaser.js:30658) at Phaser.Game.updateLogic (phaser.js:38763) at Phaser.Game.update (phaser.js:38707) at Phaser.RequestAnimationFrame.updateRAF (phaser.js:61260) function Refill() { water = 3 } game.physics.arcade.overlap(player, WaterBuildings, function (overlappingPlayer, overlappingWaterBuildings) { refill() }); any help would be much appreciated
  2. I'm using physics in one of my games, but I'm having trouble getting things to move realistically. I have the player (a bird), and I have objects in a group (trash). The trash I want to be very lightweight, so that it can be knocked around by the bird. Setting mass on both the player and the objects sometimes results in some weird visual stuff, so for now I have taken those lines out. What I really want to solve is the issue of friction. Right now, my code looks like this: this.trash.forEach(function (piece) { piece.anchor.setTo(0.5, 1); piece.body.gravity.y = 5; piece.body.moves = true; piece.body.velocity.setTo(100, 100); piece.body.collideWorldBounds = true; piece.body.bounce.set(0.8); piece.body.friction.x = 1; piece.body.drag.x = 1; }); The trash is gliding around on the floor of the game like wet ice cubes. I thought perhaps introducing another sprite to interact with would help: this.platforms = this.add.physicsGroup(); // Create the ground and set properties. this.platforms.create(0, game.height - 5, 'ground'); this.platforms.setAll('body.allowGravity', false); this.platforms.setAll('body.immovable', true); this.platforms.setAll('body.moves', false); this.platforms.setAll('body.velocity.x', 100); this.platforms.setAll('body.friction.x', 1); this.platforms.setAll('body.drag.x', 1); I'm still watching ice-cube trash. What I'm aiming for is something that can tumble (is there a way to get corresponding rotation on collision to happen?), so I want moving the trash to be more of a shove to move a distance rather than a tap from the player. Thank you for your help!
  3. I have a block based game that requires separated physics bodies, which is why I can't merge a wall of five bodies into one. It appears like the player could still hit the floor in-between the blocks, if the player is forcing itself towards that direction, which makes me think that the bodies are slightly overlapping and causing this. I'm using arcade physics. Is there a way to avoid this? A video here shows the player executing the bug on the top of the tower. He's jumping on the wall, eventually getting over it.
  4. Hi! I'm making a game where the player clicks or touches the screen and his avatar walks towards that point and stops. It works great without obstacles. With obstacles the player avatar get stuck in the corner. See gif below. I managed to fix it, but it feels hacky. When hero (player's avatar) collides with box (obstacle on screen) I move him towards his target EXAMPLE: if hero collides with left or right side of box and target is above him, I move hero up a bit function collisionHandler(){ //prevent hero avatar from getting stuck on corners kick = 0.4; if(box.x < hero.sprite.x && hero.target.sprite.x > hero.sprite.x){ hero.sprite.x += kick; //KICK right } else if(box.x > hero.sprite.x && hero.target.sprite.x < hero.sprite.x){ hero.sprite.x -= kick; //KICK left } if(box.y < hero.sprite.y && hero.target.sprite.y > hero.sprite.y){ hero.sprite.y += kick; //KICK down } else if(box.y > hero.sprite.y && hero.target.sprite.y < hero.sprite.y){ hero.sprite.y -= kick; //KICK up } } Is there a property of ARCADE physics I'm missing? Do I need my hacky code or there's a better way of fixing it? UPDATE: Github page: https://github.com/CaioMGA/ZenvaGameJam/ hero.js: function createHero(x, y, _speed){ return { "alive":true, "walking" : false, "speed":_speed, "direction" : {"x":1, "y":0}, "target":null, "sprite" : null, "createTarget": function(){ this.target = createTarget(); }, "createAnimations" :function(){ this.sprite = game.add.sprite(x, y, 'hero_spritesheet', 10); this.sprite.anchor.setTo(0.5, 0.5); this.sprite.animations.add('walkH', [13, 14 ,15, 14], 8, true); this.sprite.animations.add('walkUp', [7, 8, 7, 9], 8, true); this.sprite.animations.add('walkDown', [10, 11, 10, 12], 8, true); this.sprite.animations.add('idle', [10], 8, false); this.sprite.animations.add('idleUp', [7], 8, false); this.sprite.animations.add('victory', [10, 16, 10, 16, 10, 16], 5, false); this.sprite.animations.add('death', [0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6], 10, false); this.sprite.animations.play('idle'); game.physics.enable(this.sprite, Phaser.Physics.ARCADE); this.sprite.body.collideWorldBounds = true; this.sprite.body.setCircle(16); this.sprite.body.bounce.set(0.05); }, "death" : function(){ this.sprite.animations.play('death'); }, "walk" : function(direction){ this.sprite.animations.play('walkH'); this.sprite.scale.x = direction; }, "walkUp" : function(){ this.sprite.animations.play('walkUp'); }, "walkDown" : function(){ this.sprite.animations.play('walkDown'); }, "stop" : function(){ this.walking = false; this.sprite.animations.play('idle'); }, "victory" : function(){ this.sprite.animations.play('victory'); }, "update" : function(){ this.move(); }, "move" : function(){ if(this.walking){ game.physics.arcade.moveToXY(this.sprite, this.target.sprite.x, this.target.sprite.y,this.speed, 0); if(Phaser.Math.distance(this.sprite.x, this.sprite.y, this.target.sprite.x, this.target.sprite.y) < 8){ this.sprite.x = this.target.sprite.x; this.sprite.y = this.target.sprite.y; this.walking = false; this.sprite.body.velocity.setTo(0, 0); this.stop(); this.target.hide(); } } }, "setTarget" : function (x, y){ this.target.set(x, y); this.walking = true; if(Math.abs(this.sprite.x - this.target.sprite.x) >= Math.abs(this.sprite.y - this.target.sprite.y)){ if(this.sprite.x > this.target.sprite.x){ this.walk(-1); } else { this.walk(1); } } else { if(this.sprite.y > this.target.sprite.y){ this.walkUp(); } else { this.walkDown(); } } }, "init" : function(){ this.createAnimations(); this.createTarget(); this.target.init(); } }; }
  5. Hello, does someone perhaps have any examples for this? I want to make a "button" with the arcade physics system, so that when the player steps on it, it is pushed into the ground, and triggers some event, and when the player moves away, it sticks out again.
  6. Hello everyone, I've got a very odd problem with the collision detection of the arcade physics system. The code is as follows: var x_player = null; var floor = null; BasicGame.Game.prototype = { preload: function () { }, create: function () { this.physics.startSystem(Phaser.Physics.ARCADE); var boundary_bottom = 650; var boundary_top = 50; floor = this.add.sprite(640, 680, 'floor'); floor.anchor.setTo(0.5, 0); x_player = this.add.sprite(640, 450, 'x_player'); x_player.anchor.setTo(0.5, 0.5); this.physics.arcade.enable([floor, x_player]); floor.body.allowGravity = false; floor.body.immovable = true; x_player.body.gravity.y = 600; x_player.body.bounce.y = 0.4; x_player.body.setCircle(27,9,9); }, update: function () { this.physics.arcade.collide(x_player, floor); if (this.input.activePointer.isDown) { x_player.body.velocity.y = -500; } }, render: function () { this.game.debug.body(x_player); this.game.debug.body(floor); } }; The collision detection seems to work basically, but when I let the ball jump by pressing the mouse button, there is a pretty big random chance it will just slip through the floor when it comes down again. It seems like it doesn't work precisely enough or something. Does anyone know more? Help is greatly appreciated!
  7. HI Been going through the Book Discover Phaser, but are stuck with this bit of code: The jump functionality on the player somehow doe's not work. When I console.log the body.touching object, I can see, that body.touching.down does not turn true, when the player hit's the a platform. Furthermore, the cursor.up is detected when I leave out this bit of code: '&& this.player.body.touching.down', but somehow does not function, when the code is as in the Quote. Any Ideas to what I should be looking for? Thanks.
  8. Hey! I have a group of enemies created like this (called from create()): spawnEnemies: function(map){ this.enemies = this.game.add.group(); this.enemies.enableBody = true; this.game.physics.arcade.enable(this.enemies); var enemyStartPositions = this.findObjectsByType('enemyStart', this.map, 'objectLayer'); for(var i = 0; i < enemyStartPositions.length; i++){ var enemyStart = enemyStartPositions[i]; var enemy = new Enemy(this.game, enemyStart.x, enemyStart.y, 'cultist'); enemy.countStats(); this.enemies.add(enemy); } this.enemies.setAll("body.immovable", true); } In the update function - I try to detect the collision between the children in the group like in this example (using 2.4.7): http://examples.phaser.io/_site/view_full.html?d=arcade physics&f=group vs self.js&t=group vs self&phaser_version=v2.4.7& this.game.physics.arcade.collide(this.enemies); But they wont collide with - just passing trough - each other. Also tried with adding a callback as when I let the player sprite collide with the enemy group like this: this.game.physics.arcade.collide(this.player, this.enemies, this.collisionHandlerPlayerAndEnemy, null, this); this.game.physics.arcade.collide(this.enemies, null, this.collisionHandlerEnemyAndEnemy); And the callback-function will not be called (may it be that this does not even work at all when the case is group to group?). I need someone elses eyes on this. No properties for enemy body is set outside these code blocks.
  9. var mainState = { preload: function() { // This function will be executed at the beginning // That's where we load the game's assets game.load.image('player', 'assets/player.png'); game.load.image('wallV', 'assets/wallVertical.png'); game.load.image('wallH', 'assets/wallHorizontal.png'); game.load.image('player2', 'assets/secondplayer.png'); }, create: function() { game.stage.backgroundColor = '#3498db'; game.physics.startSystem(Phaser.Physics.ARCADE); this.player2 = game.add.sprite(200,100, 'player2'); this.player2.anchor.setTo(0.5, 0.5); game.physics.arcade.enable(this.player2); //first enable gravity this.player2.body.gravity.y = 500; //then use gravity properties. this.player = game.add.sprite(game.world.centerX, game.world.centerY, 'player'); this.player.anchor.setTo(0.5, 0.5); game.physics.arcade.enable(this.player); this.player.body.gravity.y = 500; this.cursor = game.input.keyboard.createCursorKeys(); // Create a new group this.walls = game.add.group(); // Add Arcade physics to the whole group this.walls.enableBody = true; // Create 2 walls in the group game.add.sprite(0, 0, 'wallV', 0, this.walls); // Left wall game.add.sprite(780, 0, 'wallV', 0, this.walls); // Right wall game.add.sprite(0,580, 'wallH' , 0, this.walls); //horizontal wall. this.walls.setAll('body.immovable', true); // this.createWorld(); }, //timer update: function() { game.physics.arcade.collide(this.player, this.walls); this.movePlayer(); game.physics.arcade.collide(this.player2, this.walls); }, movePlayer: function() { // If the left arrow key is pressed if (this.cursor.left.isDown) { // Move the player to the left this.player.body.velocity.x = -200; } // If the right arrow key is pressed else if (this.cursor.right.isDown) { // Move the player to the right this.player.body.velocity.x = 200; } else if (this.cursor.up.isDown) && (this.player.body.touching.wallH == true) { this.player.body.velocity.y = -500; //this.cursor.up.isDown := false } else if (this.cursor.down.isDown) { this.player.body.velocity.y = 200; } // If neither the right or left arrow key is pressed else { // Stop the player this.player.body.velocity.x = 0; //this.player.body.velocity.y = 0; } // If the up arrow key is pressed and the player is touching the ground if (this.cursor.up.isDown && this.player.body.touching.down) { // Move the player upward (jump) this.player.body.velocity.y = -320; } }, }; var game = new Phaser.Game(800, 600, Phaser.AUTO, 'gameDiv'); game.state.add('main', mainState); game.state.start('main'); Hello! I am very new to Phaser, only started out a few days ago. As you might expect, I will do some dumb mistakes. My issue here is that my character that works, (the one controllable with arrow keys) has the ability to jump to infinity. I have tried a bit of code with a double if condition to solve this, but I can't get the syntax right and I don't know how to check if the player is touching the horizontal wall or not. (I don't want it to jump unless it's touching the horizontal wall, that way I can't keep on jumping in mid air. Here's the horrible bit of code I am attempting to get to work: //if i'm pressing up AND the player is touching the wall THEN set vertical velocity to -500px. else if (this.cursor.up.isDown) && (this.player.body.touching.wallH == true) { this.player.body.velocity.y = -500; } I have attached all my actual code. I'm new here, I don't know how to write this condition, thanks for your help main.js
  10. Hey guys! I'm having another issue with my endless runner and arcade physics bodies. This time bodies seem to flicker for a frame after I have call kill/reset on their sprites. Basically I have three chunks which are laid out and scrolled on screen one other the other. Once a chunk has scrolled off the opposite side of the screen, the layout is reshuffled and it is positioned behind the previous chunks so it can scroll back on screen. Before reshuffling the layout, I forEachAlive -> member.kill(). This is because it's possible that no every child of the chunk will be used in the new layout, so I want to pool them. When I generate the new layout, I reset(x, y) the child. This seems to cause the body of the child to flicker on screen despite the chunk being off screen. I wrote an example and attached it to help demonstrate the issue I am having. example.zip
  11. I've been working on a Phaser game for a project at university. All of this is relatively new stuff to me, so I'm learning on the fly. I've managed to create a simple tilemap using Tiled, and got it to import to Phaser successfully. However, I can't make the player collide with the 'platform' layer, and I've tried just about everything I can find online. I've cut down my game code to just what's needed for you to (hopefully) point out my error, but it all runs without errors usually. I can also upload any JSON or Image files that might be needed. var SuddenGame = SuddenGame || {}; var char; var map; // GAMEPLAY STATE // SuddenGame.playState = function() {}; SuddenGame.playState.prototype = { init: function() { this.game.renderer.renderSession.roundPixels = true; }, create: function() { //Setup FPS Counter this.game.time.advancedTiming = true; //Stop game from pausing if a player tabs out this.stage.disableVisibilityChange = true; //Import and play background music music = this.game.add.audio('menumusic'); music.play('', 0, 1, true); //Create Dotted Background this.background = this.game.add.tileSprite(0, this.game.height - this.game.cache.getImage('background').height, this.game.width, this.game.cache.getImage('background').height, 'background' ); this.dots = this.game.add.tileSprite(0, this.game.height - this.game.cache.getImage('dots').height, this.game.width, this.game.cache.getImage('dots').height, 'dots' ); //Enable Physics Engine this.game.physics.startSystem(Phaser.Physics.ARCADE); //Add level one tilemap map = this.game.add.tilemap('levelone'); map.addTilesetImage('scifi_platformTiles_32x32', 'scifi_platformTiles_32x32'); backgroundTiles = map.createLayer('backgroundLayer'); Objective = map.createLayer('Objective'); Platform = map.createLayer('Platform'); this.game.add.existing(Platform); this.physics.arcade.enable(Platform); map.setCollisionBetween(1, 1000, true, 'Platform'); Platform.resizeWorld(); Platform.debug = true; this.char = this.add.sprite(50, 470, 'hero'); this.physics.arcade.enable(this.char); this.char.body.gravity.y = 1300; this.char.body.collideWorldBounds = true; this.char.scale.setTo(2, 2); //Create Player Animations var idle = this.char.animations.add('idle', [0]); var walk = this.char.animations.add('walk', [0, 1, 2, 1]); this.game.camera.follow(this.char); }, update: function() { this.game.physics.arcade.collide(char, Platform); this.physics.arcade.TILE_BIAS = 40; if (this.game.input.keyboard.isDown(Phaser.Keyboard.LEFT) && !this.char.body.touching.left) { this.char.body.velocity.x = -150; this.char.animations.play('backwalk', 10, true); } else if (this.game.input.keyboard.isDown(Phaser.Keyboard.RIGHT) && !this.char.body.touching.right) { this.char.body.velocity.x = 150; this.char.animations.play('walk', 10, true); } else if (this.game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { this.char.animations.play('die', 10, true); } else { this.char.body.velocity.x = 0; this.char.animations.play('idle', 7, true); } if (this.game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR) && this.game.time.now > jumpTimer) { { this.char.animations.play('jump', 10); this.char.body.velocity.y = -1000; jumpTimer = this.game.time.now + 750; } } //if (this.cursors.up.isDown && !this.char.body.touching.down ) { if (this.game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR) && this.game.input.keyboard.isDown(Phaser.Keyboard.LEFT) && this.char.body.touching.left && this.game.time.now > jumpTimer) { this.char.body.velocity.y = -500; jumpTimer = this.game.time.now + 1; } if (this.game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR) && this.game.input.keyboard.isDown(Phaser.Keyboard.RIGHT) && this.char.body.touching.right) { this.char.body.velocity.y = -500; this.char.body.velocity.x = -2500; //jumpTimer = this.game.time.now + 1; } //More update code here }, render: function() { this.game.debug.text(this.game.time.fps || '--', 2, 14, "#00ff00"); } } Apologies if I've missed an extremely obvious mistake!
  12. Hi! I want to make a pixel game with a resolution of 144*256 pixels. I want to keep the pixel look also when I rotate a sprite. So the player is able to see tilted pixels. So i decided to set the real dimension of the game to the full available size like 1920*1080. Then I put everything inside a Group and scale the whole Group up so that the game fits the canvas. Also I'm using the Arcade physics and there is where the problem takes place. The physics bodies are not scaled with the group and so the whole szene is useless^^ So is there a solution to scale a whole stage or the "game" up to maximal resolution but working correctly with a design resolution? The Falsh engine Starling worked like this and that was very handy cause you get the real pixel count of the device without taking care of that. Thanks in advance^^
  13. Hey guys! I'm making an endless runner and I'm running into a weird issue with Arcade physics. Because my game is an endless running, I'm anchoring my player on the screen and moving the objects towards the player instead of using the camera. My issue is that I get collision events however none of the body.blocked booleans are being set, so I know a collision happens, but I don't know which side it happens on (up, down, or left). I'm checking for collision like such: this.game.physics.arcade.collide(sprite, this.chunks[0], levelHandler, null, ctx); this.game.physics.arcade.collide(sprite, this.chunks[1], levelHandler, null, ctx); this.game.physics.arcade.collide(sprite, this.chunks[2], levelHandler, null, ctx); Basically, what I'm doing is I spawn three chunks (or segments) of objects and position them one screen length apart from each other. I then scroll each group on screen towards the player. When a chunk is scrolled off the opposite side of the screen, I reposition it back behind the last chunk in the list so it can be scrolled back on towards the player. My 'levelHandler' is being called properly, and it's giving my the object that the player collided with. Again, my issue is the object.body.blocked booleans aren't being set, so I don't know whether the player hit the left side, top, or bottom of the object. Would this be because I'm not moving the objects by applying a velocity to the object's body? I'm moving the parent group of the objects so I don't have to iterate through all my objects to do that. Is there another way to get the information I want? Or am I going to have to write my own detection to get which side was hit after the collision happened?
  14. Hey everyone, I stepped upon an interesting thing or self induced bug that seems to be happening whilst using Arcade Physics for an infinite runner. It's pretty rough around the edges, more of a proof of concept than anything else, but basically in the update function I'm doing a couple of things. First of all, the ground is a group of child sprites, each ones velocity gets nudged left per update cycle: this.ground.children.forEach(function(c) { c.body.velocity.x = -this.RUN_SPEED; }, this); Then, I check to see if any of those children have gone off screen to the left (child.body.right < 0) for example. Once that's done, I then reset that child back to the right hand side of the screen like so: child.reset(this.game.width, child.y); In between all that I just do a couple of checks to make sure none of them overlap, by using this (it also makes sure we don't try to place anything else whilst this particular piece is still leaving the right-hand area: this.ground.children.find(function(child){ return child.x < this.game.width && child.x + child.width > this.game.width || child.x >= this.game.width; }, this); Now the main problem I'm having is that there seems to be a gap between each one of the sprites when they've been resetted and are following the one that came before hand. What I find interesting is that if I set the velocity to 256, the gap between each sprite seems to be exactly 12 pixels in width. If I drop it to 128, then it drops to 6 pixels in width. I'm curious as to how the numbers might correlate, or, is there something that happens in the physics step that's making the gap outside of the main update loop? It's a bit of a weird problem, and as said earlier, it's probably just down to poor implementation. I've attached the script file if you'd fancy a perusal also. Thanks for your time everyone, take care! IFPlay.js
  15. LATEST UPDATE Hi thanks for looking, but I have figured out my issue since posting this question. Here is a codepen with Box2d Phaser physics moving the bottom sprite with a sprite resting on top , and having the top sprite's physics respond - even after it has been inactive or at rest: http://codepen.io/mgalpy/pen/qNLVdA --------------------------------- New to Phaser JS and trying to build a "simple" game; If you imagine the game brick breaker - just the base and the ball. I want to be able to move the base up and have the ball still sitting on the base. I also want to be able to tilt the base and have the ball "roll" down depending on which side is tilted. Update 2 Here is a codepen of my Box2d Phaser attempt which comes closest to what I'm trying to achieve. If you use the arrow keys immediately to move the base up,down,left, right (while coliding with the box) then physics work as expected. If you wait a few seconds after the box rests on the base, moving the base has no effect on the box; I would like the box to be effected by the base even after the initial wait:http://codepen.io/mgalpy/pen/wWRBpo Update 1 Using Phaser's default Arcade Physics, I am now able to get the up movement of the base to keep the ball sitting on-top (although there are some brief overlap's that I'd like to keep from happening and not sure how to prevent that at the moment?); I was not able to allow the ball to "roll" down either side while tilting the base. It seems that even though the base is being rotated that the collision area is not being moved and the ball does not know that it needs to "roll" down. Here is an example phaser sanbox with debugging information (move left or right to see the base rotate): http://phaser.io/sandbox/WVVnswOt/play
  16. Hey all! I'm having an issue where i'm trying to reset the player sprite, but it doesn't do anything, and the console yields no errors and i know i'm trying to reset the right thing. I recently grabbed a copy of Phaser 2.5, and yet if i switch back to the older phaser i was using (2.4.4) the reset i have works correctly. I'm a little stumped on what I'm missing here, any help would be appreciated!
  17. Hi, I'm building a little game where a ship is contained within a square in the middle of the game world and "bounces" off the walls. It's easier to just see it in action so here's what I have so far: http://mappdev.com/spin/ The ship starts in the middle of the canvas, spinning endlessly. When you click or touch the canvas, the ship moves forward in the angle it's facing. So I have a 640x960 canvas with a red background and then I draw a black 600x600 rounded rectangle in the center, then I add 4 objects on top, bottom and sides that are the "walls" meant to keep the ship within the square. I'm using a group for these walls. Right now the ship bounces off the edges of the game world but as far as I can tell it doesn't collide with the walls at all. Here's my code: var defaults = { canvasWidth: 640, canvasHeight: 960, angle: -90, velocity: 500, angularVelocity: 400, }; var game = new Phaser.Game(defaults.canvasWidth, defaults.canvasHeight, Phaser.AUTO, 'container', { preload: preload, create: create, update: update, render: render }); var walls; var ship; function preload() { game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; game.load.image('wall', 'assets/wall.png'); game.load.image('ship', 'assets/ship.png'); game.load.image('coin', 'assets/coin.png'); game.load.image('bomb', 'assets/bomb.png'); } function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = "#FF0000"; // "#37474F"; var graphics = game.add.graphics(20, 180); graphics.beginFill(0x000000, 1); graphics.drawRoundedRect(0, 0, 600, 600, 8); walls = game.add.physicsGroup(); wall_top = walls.create(0, 0, 'wall'); wall_top.scale.setTo(640, 180); wall_top.body.immovable = true; wall_right = walls.create(620, 180, 'wall'); wall_right.scale.setTo(20, 600); wall_right.body.immovable = true; wall_bottom = walls.create(0, 780, 'wall'); wall_bottom.scale.setTo(640, 180); wall_bottom.body.immovable = true; wall_left = walls.create(0, 180, 'wall'); wall_left.scale.setTo(20, 600); wall_left.body.immovable = true; ship = game.add.sprite(defaults.canvasWidth * 0.5, defaults.canvasHeight * 0.5, 'ship'); ship.scale.setTo(0.5, 0.5); ship.anchor.set(0.5, 0.5); ship.angle = defaults.angle; game.physics.arcade.enable(ship); ship.body.allowGravity = false; ship.body.immovable = true; ship.body.collideWorldBounds = true; ship.body.bounce.setTo(1, 1); ship.body.angularVelocity = defaults.angularVelocity; } function update() { game.physics.arcade.collide(ship, walls); if(game.input.activePointer.isDown) { ship.body.angularVelocity = 0; ship.body.velocity.copyFrom(game.physics.arcade.velocityFromAngle(ship.angle, defaults.velocity)); } else { ship.body.angularVelocity = defaults.angularVelocity; ship.body.velocity.set(0, 0); } if(ship.body.blocked.up || ship.body.blocked.down || ship.body.touching.up || ship.body.touching.down) { ship.angle = 0 - ship.angle; ship.body.velocity.copyFrom(game.physics.arcade.velocityFromAngle(ship.angle, defaults.velocity)); } if(ship.body.blocked.right || ship.body.blocked.left || ship.body.touching.right || ship.body.touching.left) { ship.angle = 180 - ship.angle; ship.body.velocity.copyFrom(game.physics.arcade.velocityFromAngle(ship.angle, defaults.velocity)); } } function render() { // game.debug.spriteInfo(ship, 32, 32); } Any idea what I'm missing? I'm using latest Phaser version 2.4.4 by the way.
  18. Hi, I've set up a group of sprites and they generally collide with each other fine, but if they are overlapping they don't separate (ie force each other apart). Is this only available with other physics types like Box2D or have I missed something? create() { this.enemiesGroup = this.game.add.group(); this.enemiesGroup.enableBody = true; this.enemiesGroup.physicsBodyType = Phaser.Physics.ARCADE; for(var i=0; i < 20; i++) { var enemy:Phaser.Sprite = this.enemiesGroup.create(game.rnd.integerInRange(100, 770), game.rnd.integerInRange(0, 570), "gameboy", game.rnd.integerInRange(2,5)) enemy.name="enemy"+i; enemy.body.bounce.y=0.8 enemy.body.collideWorldBounds=true; }}update() { this.game.physics.arcade.collide(group, group, this.groupCollisionHandler, null, this);}thanks J
  19. I have this Sprite that has a child Emitter. At certain points, dictated by the AI, the emitter explodes out all the particles. I collide the emitter against my tilemap's collision layer and overlap it against the player. Both the collision layer and the player are exposed as properties on my game instance. When a particle overlaps the player I set alive to false and kill the particle. That works great. The particles also successfully collide against the collision layer. However, they don't bounce. It looks like the tilemap separator code *should* be bouncing them, but it's not. Here's the emitter's creation in my Sprite constructor: var screamEmitter = game.add.emitter(0, 0, 20); screamEmitter.makeParticles('screamParticle'); screamEmitter.setAllChildren('body.allowGravity', false); screamEmitter.setXSpeed(-200, 200); screamEmitter.setYSpeed(-100, 75); screamEmitter.setAlpha(1, 0, 1500, Phaser.Easing.Quadratic.In); screamEmitter.setScale(1, 2, 1, 2, 1500, Phaser.Easing.Cubic.Out); this.addChild(screamEmitter); screamEmitter.x = 0; screamEmitter.y = -10; this.scream = screamEmitter;Here's the collision and overlap calls from my Sprite's update method: this.game.physics.arcade.collide(this.scream, this.game.collisionLayer); this.game.physics.arcade.overlap(this.scream, this.game.player, this.onScreamVsPlayerCollision, null, this);Here's how I start the emitter via a timed event off a state machine: this.scream.start(true, 1500, null, 1000);Like I said: the particles come out just fine, they collide with player and collision layer just fine... they just don't bounce. Any ideas?
  20. I'm using arcade.collide to detect collision between a single Sprite and a group of Sprites. The documentation states collide should return true if there was a successful collision. Whether there is a successful collision or not the collide function always returns false for me. I just updated to 2.4.2 to see if that would fix my issue but no luck. Here's basically what my code looks like. if (this.game.physics.arcade.collide(this, groupOfSprites, null, this.collisionProcess, this)) { console.log("Successful collision!"); } The "Successful collision!" log will not be hit even if the collision was successful. Has anyone else experienced this? Is there an alternative way to determine if a collision was successful and have separate code paths for each outcome? Some more information about my setup. Windows 10 Chrome Phaser 2.4.2 TypeScript
  21. Is it possible to adjust the arcade physics collision boxes of tiles in a tilemap? You can change the offset and size of the body for a sprite, but can you do the same with a tile?
  22. If I have a sprite standing on top of two tiles like this: The collision code will always return the one on the left as the collided tile even if most of the hitbox is standing on top of the one on the right. I want to make my character react differently based on what tile it bounces off, but players get confused when the character is bouncing mostly off a tile type A and the reaction corresponds to a tyle type B that it was barely touching.
  23. In my game, I set the mass of the player to 5 and the mass of all other sprites to zero. However, the player still slows down when he hits those sprites. Is this intended? Also, if the player has a mass greater than 20 and collides with a sprite whose mass is 1 weird things happen.
  24. Hi, I'm developing an html5 game using phaser + cocoonjs. So far there is only 1 sprite with velocity set, so basically it just moves from right to left. As simple as it sounds, running this on android device (and sometimes in chrome) I noticed that the sprite doesn't move smoothly, it's laggy! I'm not sure if there is a better way to animate the sprite that makes it smooth. Here is the code I have, I also attached the full application. /// <reference path="js/phaser.min.js" />var w = window.innerWidth;var h = window.innerHeight; var game = new Phaser.Game(w, h, Phaser.AUTO, '', { preload: preload, create: create, update: update });var speed = -250; function preload() { game.load.image('trainHead', 'img/trainHead3.png');} function create() { var globalY = game.world.height / 3; trainUnitHeight = h / 8; trainUnitWidth = w / 5; // Train head trainHead = game.add.sprite(game.world.width, globalY, 'trainHead'); trainHead.anchor.setTo(0.5); SetDimensions(trainHead, trainUnitWidth, trainUnitHeight); game.physics.arcade.enable(trainHead); trainHead.body.velocity.x = speed;} function update() {} function SetDimensions(sprite, width, height) { sprite.width = width; sprite.height = height;} Any help/suggestions are greatly appreciated! Thanks!!repro.zip
  25. Hello, I've used both individual sprites and a group (from a set of arrays). Either way once I enable Arcade physics the sprites dissapear. full code is here : https://github.com/EMC23/JiGS/blob/master/components/com_battle/views/phaser/tmpl/playstate01.js I've used same method elsewhere without issues, so I'm completely stumped. Any help appreciated. ////////////////////////place players//////players_group = game.add.group();if (typeof players_list != 'undefined') {for (var index = 0; index < players_list.length; index++) {var key = players_list[index].id//add_players[index] = game.add.sprite(players_list[index].posx, players_list[index].posy, key);players_group.create(players_list[index].posx, players_list[index].posy, key);}game.physics.enable( players_group, Phaser.Physics.ARCADE);}