Search the Community
Showing results for tags 'collide'.
-
Hi, I saw the code presented in the link https://playground.babylonjs.com/#1NQTNE#11 and played many times. I felt "moveWithCollisions" is full of magic . it seems that with the help of "movewithCollisions" the mesh can smartly move and move little by little and finally manage to find its path to reach its destination. I checked the code but was not able to figure out how to use it exactly, there is few comment or remarks to tell what's the purpose of some important lines . so I listed these important lines that I didn't understand as below. can anyone please help to explain what's the purpose of these critical lines? (please notice that I use "//" to bring up what my question is ) // move to clicked coordinates ............ if(meshPlayer.destination) { var moveVector = meshPlayer.destination.subtract(meshPlayer.position); if (moveVector.length() > 1.1) { //1.why use 1.1 ,other than 2.2 or 0.8 or any length else? is it related to the player size 1 while downcasting a ray ? moveVector.y = GRAVITY; //2.GRAVITY is -0.5 as defined earlier, but why moveVector.y must be -0.5? what's the purpose to assign moveVector.y ? moveVector = moveVector.normalize();//3.what's the purpose of "normalize"?what's the benefit of doing this? is this line mandatory? moveVector = moveVector.scale(0.2); //4.why to shrink the moveVector to 1/5 of its original size? why not 0.1 or 2 or some number else? if(meshFound.distance > 1.1){moveVector.y = GRAVITY;} //5.why 1.1 again? meshPlayer.moveWithCollisions(moveVector); } else { meshPlayer.destination = null; } } .......... It's really appreciated for your time. Edit Your content will need to be approved by a moderator
-
- avoid obstables
- subtract
- (and 5 more)
-
Hello everyone, I'm starting in the development of game with Phaser. I'm trying to create a game whose the goal is for the player to avoid cubes which are spreading. At the moment, I'm trying to detect the collision between the player and the spreading, but it doesn't work. I use this line de code : game.physics.arcade.collide(monSprite, ennemies, restartGame()); And according to tutos, it seems correct. However, when I put this line in my code, the game restart all of the time, it's boring var game = new Phaser.Game(800,600,Phaser.AUTO,'content',{preload: preload, create: create,update:update}); var counter = 0; var text = 0; function preload(){ game.load.image('main_character','asset/main_character.png'); game.load.image('ennemy','asset/ennemy.png'); } function create(){ game.physics.startSystem(Phaser.Physics.ARCADE); //initialisation du compteur counter = 0; text = 0; //add sprite ofe main character, position monSprite=game.add.sprite(0,0,'main_character'); monSprite.anchor.setTo (0.5,0.5); monSprite.x=400; monSprite.y=300; monSprite.angle=0 game.physics.enable(monSprite,Phaser.Physics.ARCADE); //add sprite of main ennemy, position //ennemy = game.add.sprite(0,0,'ennemy'); //variable qui compte le nombre de tour de la fonction update i = 0; //variable qui compte le nombre de vague de propagation i_spreading = 0; //groupe pour les ennemies //variable qui permet d'accélérer ou de ralentir la propagation a = 15; //variable qui correpond au nombre de boucle avant que la propagation s'arrete end_spreading = 100; //Text du temps text = game.add.text(game.world.centerX, game.world.centerY, 'Temps: 0', { font: "30px Arial", fill: "#ffffff", align: "center" }); text.anchor.setTo(-1, 7.5); game.time.events.loop(Phaser.Timer.SECOND, updateCounter, this); // Create an empty group ennemies = game.add.group(); } function update(){ //vérifie si le joueur ne quitte pas le terrain exit(); //Déplacement move(); //variable qui vaut 0 si i/a n'a pas de reste tempo = i%a; //variable qui correpond au nombre de boucle avant que la propagation commence start_spreading = 10; //condition qui agit différemment en fonction du nombre de fois que la fonction update est appelée //apparition du première ennemie //compteur i = i +1; if(i == start_spreading){ //game.physics.arcade.collide(monSprite, ennemies, restartGame()); //position initiale de l'ennemie différente de celle du joueur do{ x = Math.floor(Math.random() * 800); y = Math.floor(Math.random() * 600); }while(x != monSprite.x && y != monSprite.y); add_ennemy(x,y); } //propagation if(début de la propagation, fin de la propagation, tempo == 0 ne doit pas être changé) if(i>start_spreading && i<end_spreading && tempo == 0){ //variable qui prendre des valeurs entre 0 et 3 random = Math.floor(Math.random() * 3); //En fonction de la varaiable aléatoire on ajoute ou soutrait 10px switch (random) { case 0: x = x + 10; break; case 1: x = x - 10; break; case 2: y = y -10; break; case 3: y = y +10; break; } if(x>800 || x<0 || y<0 || y>600){ ennemies.removeAll(); i = 0; } add_ennemy(x,y); } //Si la propagation quitte le terrain on relance une nouvelle propagation //Si on arrive dans la dernière boucle alors on initialise le compteur i et incrémente le compteur de propagation et on le détruit if(i == (end_spreading-1)){ ennemies.removeAll(); i = 0; i_spreading = i_spreading + 1; end_spreading = end_spreading +100; if(a>2){ a = a -1; } } game.physics.arcade.collide(monSprite, ennemies, restartGame()); } function add_ennemy(x,y){ ennemy = ennemies.create(x,y,'ennemy') game.physics.enable(ennemy,Phaser.Physics.ARCADE); // Add the pipe to our previously created group //ennemies.add(ennemy); } //function which allows to main character to move function move(){ if (game.input.keyboard.isDown(Phaser.Keyboard.D)==true || game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)==true){ monSprite.x=monSprite.x+2 monSprite.angle=monSprite.angle=90 } if (game.input.keyboard.isDown(Phaser.Keyboard.Q)==true || game.input.keyboard.isDown(Phaser.Keyboard.LEFT)==true){ monSprite.x=monSprite.x-2 monSprite.angle=monSprite.angle=-90 } if (game.input.keyboard.isDown(Phaser.Keyboard.S)==true || game.input.keyboard.isDown(Phaser.Keyboard.DOWN)==true){ monSprite.y=monSprite.y+2 monSprite.angle=monSprite.angle=0 } if (game.input.keyboard.isDown(Phaser.Keyboard.Z)==true || game.input.keyboard.isDown(Phaser.Keyboard.UP)==true){ monSprite.y=monSprite.y-2 monSprite.angle=monSprite.angle=180 } } //fonction qui relance le jeu si on quitte le fond de jeu function exit(){ if(monSprite.x < 0 || monSprite.x > 800 || monSprite.y < 0 || monSprite.y > 600){ restartGame(); } } //Fonction qui relance le jeu function restartGame(){ // Start the 'main' state, which restarts the game console.log('Restart'); this.game.state.restart(); } //incrémente les secondes function updateCounter() { counter++; text.setText('Temps: ' + counter); } Thus, I don't understand how I can use the function collide, and perhaps I have made mistakes in my code before, so it doesn't work. Here, the files of the games : https://github.com/Fatavis/game_summer_irobotechart I hope that you will able to help me, and if you need more details or you have have questions, don't hesitate ^^ Thank you in advance PS: I'm french therefore I'm sorry for the mistakes in my english
-
Code pen: I am moving a NPC back and forth on a plattform by checking if the end tile is one of the tiles that are edges in the tilemap and if so swicthing the x velocity. I am having trouble with getting the moving sprite to move equally as far out of the edge of the plattform on both sides, but it seems the sprite is only colliding with one tile at the time, namely the tile that is touching the right bottom corder of the sprite, can I set the collide to be on the tile that is under the middle of the sprite?
-
Hi, I am making a snake vs block clone.So obviously the snake and block should collide.When blocks falls on snake collision is working(i mean separation is working).But when i drag snake to a block ,there is no separation when collision happens(only overlapping).Please help me.
-
(posted in phaser 3 instead of the phaser forum by mistake) Hi I'm hoping someone can hep me, I'm trying to create basic map using an array with 2 different images, one is a wall, the other is a floor. I've created twp groups but when i use this.game.physics.arcade.collide(this.player, this.blocks, null, this.hitBlock, this); I've used the collide function before on other games with no issues - this is my first time using a 2d array but I can't see where the issue is happening code below : cursor controls to move link example :http://html5gamer.mobi/projects/6/ var GameHipster = GameHipster || {}; GameHipster.GameState = { init : function() { //keyboard controls this.cursors = this.game.input.keyboard.createCursorKeys(); this.upKey = this.game.input.keyboard.addKey(Phaser.Keyboard.W); this.downKey = this.game.input.keyboard.addKey(Phaser.Keyboard.S); this.leftKey = this.game.input.keyboard.addKey(Phaser.Keyboard.A); this.rightKey = this.game.input.keyboard.addKey(Phaser.Keyboard.D); this.actionKey = this.game.input.keyboard.addKey(Phaser.Keyboard.P); this.PLAYER_SPEED = 400; this.BULLET_SPEED = 500; this.score = 0; }, // end init preload : function() { },//end preload //executed after everything is loaded create: function() { blockdata = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,1,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], ]; this.blocks = this.add.group(); this.blocks.enableBody = true; this.floors = this.add.group(); this.floors.enableBody = true; var floor, block, i, j, col; var ROWS = blockdata.length; var COLS = blockdata[0].length; //console.log('R : ' + ROWS + ' C : ' + COLS); //console.log(blockdata[2][3]); for (i =0; i < COLS; i++) { for (j =0; j < ROWS; j++){ //col =1; col = (blockdata[j]); if (col ==0){ floor = this.floors.create( 1 + (i*64),1 +(j*64), 'block' + col); floor.anchor.setTo(0.5); } if (col ==1){ block = this.blocks.create( 1 + (i*64),1 +(j*64), 'block' + col); block.anchor.setTo(0.5); block.body.immovable =true; } } }; this.player = this.add.sprite(this.game.world.width / 2, this.game.world.height / 2, 'player'); this.player.anchor.setTo(0.5); this.player.scale.setTo(0.2); this.game.physics.arcade.enable(this.player); this.player.body.immovable = true; //ui this.uiBlocked = false; //text var style = {font : '20pt Arial', fill : '#fff'}; this.scoreLabel = this.add.text(10,10, 'SCORE : ', style); this.scoreText = this.add.text(130,10, '0', style); this.refreshStats(); }, //executed multiple times per second update: function() { this.player.body.velocity.x = 0; this.player.body.velocity.y = 0; this.game.physics.arcade.collide(this.player, this.blocks, null, this.hitBlock, this); this.keyboardControls(); }, // end update keyboardControls : function(){ //init keyboard controls if (this.cursors.left.isDown|| this.leftKey.isDown){ //this.player.angle += 5; this.player.body.velocity.x = -this.PLAYER_SPEED; } else if (this.cursors.right.isDown || this.rightKey.isDown){ //this.player.angle -= 5; this.player.body.velocity.x = this.PLAYER_SPEED; } if (this.cursors.up.isDown || this.upKey.isDown){ //thrust this.player.body.velocity.y = -this.PLAYER_SPEED; } if (this.cursors.down.isDown || this.downKey.isDown){ //thrust this.player.body.velocity.y = this.PLAYER_SPEED; } if (this.actionKey.isDown){ this.fireBullet(); } },// end function hitBlock : function(player, block){ console.log('hit'); }, endGame : function(player, enemy){ this.game.state.start('GameState'); }, refreshStats : function(){ this.scoreText.text = this.score; } }; Any help is appreciated Eric
-
Hello, I am actually trying to make my very first game with Phaser ! Saddly, I am not able to get it work. Actually, the game is simple : There is a ground, a character (player), and a "coin" that fall from the top of the game to the ground. If the player hit it, the score increase by 1. All of this work fine. But I want to end the game if the "coin" hit the grounds. For this, I want the coin to collide with the ground. But unfortunally, the player collide with the ground, and the coin pass through the ground. I don't understand why. Demo here. Keep in mind that this code & game is only for testing PHASER. Here is the full code : Could you please help ? ;...; xxx lol EDIT : I got the problem solved, just misstake to place it : Now I wonder why my function endGame() isn't call when gold hit the ground. EDIT² : I got my second problem solved with this code : But I don't understand the difference between my code and game.physics.arcade.overlap();. Can someone explain me ? Code updated aswell !
-
Hi all, Been banging my head against the wall for ages with this. Default P2 collision works, I clearShapes() on each sprite to get rid of these boundary boxes and loadPolygon() to get my custom boundaries (defined in sprite_physics.json). However the collision groups appear not to be working as my player sprite goes straight through/under the enemy. Can anyone see where I'm going wrong? // in index.html (function() { var game = new Phaser.Game(1024, 768, Phaser.AUTO, null) game.state.add('Game', Game); game.state.start('Game'); })(); // in game.js var Game = function (game) { }; Game.prototype = { preload: function () { this.game.load.image('player', 'assets/player.png'); this.game.load.image('enemy', 'assets/enemy.png'); this.game.load.physics('sprite_physics', 'assets/sprite_physics.json'); }, create: function () { this.game.physics.startSystem(Phaser.Physics.P2JS); this.playerCollisionGroup = this.game.physics.p2.createCollisionGroup(); this.enemyCollisionGroup = this.game.physics.p2.createCollisionGroup(); this.createPlayer(); this.createEnemy(); }, update: function () { // <snip> do some steering stuff </snip> }, createPlayer: function () { this.player = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY + 300, 'player'); this.game.physics.p2.enable(this.player, true); // so I can see the polygon's boundaries // Gets rid of current bounding box this.player.body.clearShapes(); // BUT THEN need to add collision cos default p2 collision is wiped with clearShapes() // Add boundary shape from PhysicsEditor this.player.body.loadPolygon('sprite_physics', 'player'); // Seems to do nothing :( this.player.body.setCollisionGroup(this.playerCollisionGroup); this.player.body.collides([ this.enemyCollisionGroup ]); }, createEnemy: function () { this.enemy = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'enemy'); this.game.physics.p2.enable(this.enemy, true); this.enemy.body.clearShapes(); this.enemy.body.loadPolygon('sprite_physics', 'enemy'); this.enemy.body.setCollisionGroup(this.enemyCollisionGroup); this.enemy.body.collides([ this.playerCollisionGroup ]); } }
-
Hi guys i have a tilemap with 4 layers(ground, water, roads, others) and a sprite with my character. how i do would for my character can collide with everything inside on others(layer),every layer use a different sprite, example ground use ground.png, water water.png etc, i have this code ( i use https://github.com/lean/phaser-es6-webpack): /* globals __DEV__ */ import Phaser from 'phaser' import Mushroom from '../sprites/Mushroom' import Link from 'phaser-link' export default class extends Phaser.State { super() { } init () {} preload () { this.load.image('terrain', '../../assets/sprites/tileset_basic_terrain.png', 16, 16) this.load.image('this.others', '../../assets/sprites/tileset_other.png', 16, 16) this.load.image('water', '../../assets/sprites/tileset_water.png', 16, 16) this.load.tilemap('tilemap', '../../assets/map/overworld_01.json',null,Phaser.Tilemap.TILED_JSON) this.load.spritesheet('character', '../../assets/sprites/character.png', 16, 32, 1) } create () { this.map = this.game.add.tilemap('tilemap') this.map.addTilesetImage('tileset_basic_terrain', 'terrain', 16, 16) this.map.addTilesetImage('tileset_other', 'this.others', 16, 16) this.map.addTilesetImage('tileset_water', 'water', 16, 16) this.ground = this.map.createLayer('Ground') this.ground.resizeWorld() this.water = this.map.createLayer('Water') this.water.resizeWorld() this.others = this.map.createLayer('Others') this.others.resizeWorld() this.game.physics.arcade.enable(this.others) console.log(this.map.layers[3]) this.roads = this.map.createLayer('Roads') this.roads.resizeWorld() this.map.setCollisionBetween(0,1000, true, this.others) this.physics.startSystem( Phaser.Physics.ARCADE ) this.link = this.add.existing(new Link({ game: this.game, key: 'character', controls: true, })) this.game.camera.follow(this.link); } update() { this.game.physics.arcade.collide(this.link, this.others); } render () { if (__DEV__) { //this.debug.body(this.player,16, 32) } } } But sometime when i try test the collision between the player and layer others, this don't work correctly, collide in a blank block in somewhere place for example left and top place, but in bottom and right place the collide work correctly. for create my map i use tilemap editor 1.0.3 Images of example: there i can't move more to right: there i can't move more to bottom: there work correctly Sorry for my bad english. and thanks overworld_01.json
-
Hello, I've started using phaser just recently, I'm making a RPG game, and so far I've been learning how to make tilemaps, use spritesheets, animate sprites, and I'm falling in love with the framework, I just have a little problem. My player is set to collide with World Bounds, and it works for every bound, except the top one. I'm using the es6 webpack template, here's my, so far piece of code. create() method of my Game.js class. (I have nothing else in update, since I manage that in my own Sprite Class) this.game.world.setBounds(0, 0, 100 * 32, 100 * 32) this.game.physics.startSystem(Phaser.Physics.P2JS) this.game.time.advancedTiming = true this.game.stage.smoothed = false this.game.physics.p2.setImpactEvents(true) /* SET GAME MAP */ this.map = game.add.tiledmap('map') this.player = new Player({ game: this.game, x: 0, y: 0, lookId: 0, health: 100, mana: 100 }) this.game.world.setBounds(0, 0, 100 * 32, 100 * 32) Sprite Class import Phaser from 'phaser' import { Outfits } from './Outfits' const IMAGES = '../../assets/images/' const LOOK = { UP: 0, DOWN: 4, RIGHT: 2, LEFT: 6 } export default class extends Phaser.Sprite { constructor ({ game, x, y, lookId, health, mana }) { super( game, x * 32, y * 32, Outfits[lookId].sheets[0], Outfits[lookId].frame ) this.outfit = Outfits[lookId] this.mana = mana this.health = health this.smoothed = false this.anchor.setTo(1, 1) game.physics.p2.enable(this) this.body.setRectangle(32, 32) this.body.debug = true this.body.fixedRotation = true this.body.offset.x = -16 this.body.offset.y = -16 this.cursors = game.input.keyboard.createCursorKeys() game.camera.follow(this) game.add.existing(this) } /** * SETS A NEW FRAME TO THE PLAYER SPRITE LOOKING */ playerPosition (difference) { let spriteId = this.outfit.frame + difference let lastSprite = 143 if (spriteId > lastSprite) { this.loadTexture(this.outfit.sheets[1]) return spriteId - lastSprite } else { this.loadTexture(this.outfit.sheets[0]) return spriteId } } update () { this.body.setZeroVelocity() console.log('World position', this.worldPosition) // this.animations.play('moveUp', 5, true) if (this.cursors.up.isDown) { this.frame = this.playerPosition(LOOK.UP) // if (this.worldPosition.y <= 0) return this.body.moveUp(1000) // this.animations.play('up', 5, true) } if (this.cursors.right.isDown) { this.body.moveRight(1000) // this.animations.play('right', 5, true) this.frame = this.playerPosition(LOOK.RIGHT) } if (this.cursors.down.isDown) { this.body.moveDown(1000) this.frame = this.playerPosition(LOOK.DOWN) // this.animations.play('down', 5, true) } if (this.cursors.left.isDown) { this.body.moveLeft(1000) this.frame = this.playerPosition(LOOK.LEFT) // this.animations.play('left', 5, true) } // // if (this.game.camera.atLimit.x) { // console.log('LimitX', this.game.world) // // starfield.tilePosition.x -= (ship.body.velocity.x * game.time.physicsElapsed); // } // // if (this.game.camera.atLimit.y) { // console.log('LimitY', this.game.world) // // starfield.tilePosition.y -= (ship.body.velocity.y * game.time.physicsElapsed); // } // this.game.input.keyboard.onUpCallback = e => { // this.player.animations.stop() // if (e.keyCode == Phaser.Keyboard.UP) { // this.player.frame = this.playerStartingFrame + 3 // } // if (e.keyCode == Phaser.Keyboard.DOWN) { // this.player.frame = this.playerStartingFrame // } // if (e.keyCode == Phaser.Keyboard.LEFT) { // this.player.frame = this.playerStartingFrame + 9 // } // if (e.keyCode == Phaser.Keyboard.RIGHT) { // this.player.frame = this.playerStartingFrame + 6 // } // } } } In summary my player does collide with world bounds but only bottom, left and right, not top.
-
Hi, I need some help with my code, I am trying to create a fenced in area for my character to go in, but he cannot fit through because of the objects that he collides with. How do I change the area that the character collides with? can I reduce the size of the collidable area? The hole in the fence seems quite large enough, but he just won't go through. My game.js // variables for items, walls, etc. var walls; var house; var game = new Phaser.Game(550, 540, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); //add house to game function addHouse(image) { house = game.add.physicsGroup(); house.create(-250, -240, 'greenhouse'); house.setAll('body.immovable', true); } // add fences/walls to the game function addWalls(image) { walls = game.add.physicsGroup(); // fences up top walls.create(-90, -200, 'fencefront'); walls.create(5, -200, 'fencefront'); walls.create(100, -200, 'fencefront'); walls.create(195, -200, 'fencefront'); // fences to right walls.create(288, -200, 'fenceright'); walls.create(288, -135, 'fenceright'); walls.create(288, -70, 'fenceright'); walls.create(288, -5, 'fenceright'); // fences at bottom walls.create(-90, 59, 'fencefront'); walls.create(5, 59, 'fencefront'); walls.create(100, 59, 'fencefront'); walls.create(195, 59, 'fencefront'); // fences to left walls.create(-91, -200, 'fenceright'); walls.create(-91, -135, 'fenceright'); walls.create(-91, -70, 'fenceright'); // set the walls to be static walls.setAll('body.immovable', true); } // preload items, walls, players, etc. function preload() { // preload player game.load.spritesheet('player', 'hero.png', 64, 64); // preload houses game.load.image('greenhouse', 'greenhouse.png'); // preload fences game.load.image('fencefront', 'fencefront.png'); game.load.image('fenceleft', 'fenceleft.png'); game.load.image('fenceright', 'fenceright.png'); } // variables for character var cursors; var player; var left; var right; var up; var down; // add what will be in game function create() { game.world.setBounds(-250, -250, 550, 550); // set background color game.stage.backgroundColor = ('#3c6f42'); // add player image and place in screen player = game.add.sprite(-232, -100, 'player', 1); player.smoothed = false; player.scale.set(1); // player will "collide" with certain images like walls and houses player.collideWorldBounds = true; // ANIMATION FOR PLAYER CONTROLS down = player.animations.add('down', [0,1,2,3], 10, true); left = player.animations.add('left', [4,5,6,7], 10, true); right = player.animations.add('right', [8,9,10,11], 10, true); up = player.animations.add('up', [12,13,14,15], 10, true); // enable physics in the game (can't go through walls, gravity, etc.) game.physics.enable(player, Phaser.Physics.ARCADE); game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.enable(player); // make sure to add this code to add items/walls/buildings addHouse(); addWalls(); // enable keyboard arrows for controls cursors = game.input.keyboard.createCursorKeys(); // camera will follow the character game.camera.follow(player); } // what happens when player does something function update() { // player will now collide with these images rather than pass over them game.physics.arcade.collide(player, house); game.physics.arcade.collide(player, walls); // PLAYER CONTROLS player.body.velocity.set(0); // player presses left key if (cursors.left.isDown) { player.body.velocity.x = -100; player.play('left'); } // player presses right key else if (cursors.right.isDown) { player.body.velocity.x = 100; player.play('right'); } // player presses up key else if (cursors.up.isDown) { player.body.velocity.y = -100; player.play('up'); } // player presses down key else if (cursors.down.isDown) { player.body.velocity.y = 100; player.play('down'); } // player does not press anything else { player.animations.stop(); } } function render() { } The HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Simple Canvas Game</title> <link href="https://fonts.googleapis.com/css?family=Syncopate:700" rel="stylesheet"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> html { background: black } canvas { margin: auto; } h1 { font-family: 'Syncopate', sans-serif; color: rgb(194, 68, 91); text-align: center; margin: 0 auto; font-size: 25px; } </style> </head> <body> <header> <h1>Crafty Heroes</h1> </header> <script src="phaser.js"></script> <script src="game.js"></script> </body> </html>
-
Hello, I am making a simple haxball clone and I have a problem. I have a player and a ball on the field, and there are field lines on top, left, right and bottom. When player hits the ball, the ball sometimes goes out of the lines (it goes the other side when it should hit the line and come back). It generally happens when the ball goes fast. I thought it is a bug but I probably miss something because I am newbie on Phaser. This is how I implemented a line: this.topLine = this.add.sprite(400, 40, 'line'); this.topLine.scale.setTo(760, 2); this.physics.p2.enable(this.topLine); this.topLine.body.static = true; And here is the ball implementation: this.ball = this.add.sprite(400, 250, 'ball'); this.physics.p2.enable(this.ball, true); this.ball.body.setCircle(10); this.ball.body.damping = 0.7; I also added the images. Thanks in advance.
-
Hi guys, this is my first topic in this amazing community, so I would be glad if you can enlighten my doubts as a nice welcome :). I'm programming a survival horror game, and everything is working great except when it comes to colliding among two or three objects. I can't describe the behavior properly because for example: If the main character collides a barrel for example, it works great but It doesn't happen the same when an enemy is moving randomly and suddenly rans into a barrel, because it's like there is no barrel, the enemy just goes through. Here is the index.html file so that you can help me out on this, it's not a large code at all, it's very simple but it's driving me crazy until now. <!doctype html> <html> <head> <meta charset="UTF-8" /> <title>Rescate</title> <script type="text/javascript" src="js/libs/phaser/phaser.min.js"></script> <style type="text/css"> body { margin: 0; } </style> </head> <body> <script type="text/javascript"> //---------------------------------------------------------------------------------------------------------------- //Crea la pantalla principal del juego var game = new Phaser.Game(640,480, Phaser.AUTO, '', { preload: preload, create: create, update: update }); //Cargo fondo, pisos, estrellas y personaje function preload() { game.load.image('fondo', 'assets/MAPA.png'); game.load.image('ground', 'assets/platform.png'); game.load.image('barril','assets/barril.png',30,40); game.load.spritesheet('dude', 'assets/personaje.png', 64, 64); game.load.spritesheet('mummy', 'assets/momia37x45.png', 37, 45, 18); } //---------------------------------------------------------------------------------------------------------------- var player; var platforms; var cursors; var stars; var fondo; var fondo_movil; var score = 0; var scoreText; var background=1; //PARA LA MOMIA var mummy; var anim; var last_direction=9; //Variables para la animacion de la momia var barril,barril2, barril3; //---------------------------------------------------------------------------------------------------------------- function create() { //Se activa la fisica para el juego de tipo ARCADE game.physics.startSystem(Phaser.Physics.ARCADE); //Fondo para el juego fondo_movil = game.add.tileSprite(0,0,640,480,'fondo'); //plataformas donde se para el personaje platforms = game.add.group(); //se activa la fisica para cualquier objeto creado en este grupo platforms.enableBody = true; //Se crea el piso var ground = platforms.create(0, game.world.height - 2, 'ground'); //Escalado ground.scale.setTo(2, 2); //Esto impide caer al piso cuando el personaje lo pisa ground.body.immovable = true; // El jugador y sus caracteristicas player = game.add.sprite(32, game.world.height - 150, 'dude'); //Se habilita la fisica al jugador game.physics.arcade.enable(player); //Creo el enemigo (momia) mummy = game.add.sprite(380, 400, 'mummy', 5); mummy.scale.set(1.5 ); mummy.smoothed = false; mummy.enableBody = true; game.physics.arcade.enable(mummy); mummy.body.collideWorldBounds = false; barril = game.add.tileSprite(490,430,30,40,'barril'); barril.enableBody = true; game.physics.arcade.enable(barril); barril.body.immovable = true; barril2 = game.add.tileSprite(300,430,30,40,'barril'); barril2.enableBody = true; game.physics.arcade.enable(barril2); barril2.body.immovable = true; //Propiedades físicas del jugador. Se le da al jugador un pequeño rebote. player.body.bounce.y = 0.2; player.body.gravity.y = 400; player.body.collideWorldBounds = true; player.smoothed = true; //Las dos animaciones, caminando a la izquierda y a la derecha player.animations.add('left', [0, 1, 2, 3,4,5,6,7,8], 10, true); player.animations.add('right', [10,11,12,13,14,15,16,17,18], 10, true); //El puntaje scoreText = game.add.text(16, 16, 'Puntos 0', { fontSize: '32px', fill: '#000' }); //Nuestros controles cursors = game.input.keyboard.createCursorKeys(); anim = mummy.animations.add('walk'); anim.onStart.add(animationStarted, this); anim.onLoop.add(animationLooped, this); anim.play(10, true); } //---------------------------------------------------------------------------------------------------------------- function update() { mummy.position.x -= 1; //Colision del jugador con la plataforma y otras cosas game.physics.arcade.collide(player,mummy); game.physics.arcade.collide(player,barril); game.physics.arcade.collide(player,barril2); game.physics.arcade.collide(player,platforms); game.physics.arcade.collide(mummy,barril); game.physics.arcade.collide(mummy,barril2); game.physics.arcade.collide(mummy,platforms); // Resetea la velocidad a cero player.body.velocity.x = 0; // Movimiento de la momia. //Si el cursor izquierdo esta presionado if (cursors.left.isDown) { //fondo movil derecha if(player.x < 0.3 *game.world.width){ fondo_movil.tilePosition.x += background; barril.position.x += background ; barril2.position.x += background ; if(player.x < 0.2 *game.world.width){ player.x = 0.2 *game.world.width; } } // Moverse a la izquierda player.body.velocity.x = -90; last_direction=0; player.animations.play('left'); } //Si el cursor derecho esta presionado else if (cursors.right.isDown) { //Moverse a la derecha player.body.velocity.x = 90; player.animations.play('right'); //fondo movil derecha if(player.x > 0.5 *game.world.width){ fondo_movil.tilePosition.x += -background; barril.position.x -= background ; barril2.position.x -= background ; if(player.x > 0.8 *game.world.width){ player.x = 0.8 *game.world.width; } } last_direction=9; } else { //Sino mantenerse quieto player.animations.stop(); player.frame = last_direction; } // Permite al jugador saltar si este esta tocando el piso if (cursors.up.isDown && player.body.touching.down) { player.body.velocity.y = - 250; } } //---------------------------------------------------------------------------------------------------------------- //Animacion de la momia function animationStarted(sprite, animation) { /* game.physics.arcade.collide(player, platforms); game.physics.arcade.collide(mummy, platforms); game.physics.arcade.collide(player,barril); game.physics.arcade.collide(player,barril2); game.physics.arcade.collide(player,mummy); */ //game.add.text(32, 32, 'Animation started', { fill: 'white' }); } function animationLooped(sprite, animation) { /*if (animation.loopCount === 1) { loopText = game.add.text(32, 64, 'Animation looped', { fill: 'white' }); } else { loopText.text = 'Animation looped x2'; //animation.loop = false; }*/ } </script> </body> </html> See you guys, hope you are great!
-
Hello everyone, I am beginner with phaser, i am French and my english is not very nice. I need your help, i am blocked on a collide function. I want my character to collide with my second layer (tree, montain, statue..). (i use tiled map editor and export in json). my code : function preload: game.load.tilemap('map', 'assets/tilemaps/maps/map.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', 'assets/tiles/tiles.png'); game.load.spritesheet('perso', 'assets/sprite/spritetest.png', 32, 47); function create : game.physics.startSystem(Phaser.Physics.ARCADE); map = game.add.tilemap('map'); map.addTilesetImage('tiles'); layer = map.createLayer('layer1'); layer2 = map.createLayer('layer2'); layer2.resizeWorld(); map.setCollisionBetween(0,2000); //PLAYER // ajout player et parametre player = game.add.sprite(250, 50, 'perso'); // We need to enable physics on the player game.physics.arcade.enable(player, Phaser.Physics.ARCADE); function update : game.physics.arcade.collide(player, layer2); i show an image for understand my problem. Thx to read my message
-
H, I'm just beginning a Boulder Dash type of game to teach myself phaser...so far seems to be a fun and easy library but I've found myself unable to make the player sprite collide with the tilemap representing the level. Perhaps the answer is pretty obvious, but I can't manage to see it. I will share my code: /** * Super fun gamez */ // Main namespaces and definitions var Engine; var Game = Game || {}; Game.name = "_lepdash"; Game.version = "0.1"; Game.width = 800; Game.height = 600; /*User*/ Game.tileSize = 32; // Load assets state Game.loadState = { preload: function() { console.info(Game.name + " loading assets"); // Put your assets loader logic here... /*User*/ Engine.add.text(10, 10, "Loading...", { font: "20px Arial", fill: "#ffffff" }); //Engine.load.image('bg', 'img/bg0.png'); Engine.load.spritesheet("player", "img/player.png", Game.tileSize, Game.tileSize); Engine.load.spritesheet("terrain", "img/terrain.png", Game.tileSize, Game.tileSize); Engine.load.tilemap("map", "maps/map1.json", null, Phaser.Tilemap.TILED_JSON); }, create: function() { Engine.state.start("main"); } }; // Main menu state Game.mainState = { preload: function() { console.info(Game.name + " main menu"); }, create: function() { // Create your main menu logic here... /*User*/ // Draw main menu Engine.add.text(10, 10, Game.name, { font: "20px Arial", fill: "#ffffff" }); Engine.add.text(10, 50, "press space to start", { font: "12px Arial", fill: "#ffffff" }); // Set game parameters Game.level = 1; Game.score = 0; Game.lives = 3; // Wait for user input var key = Engine.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); key.onDown.addOnce(function() { Engine.state.start("play"); }, this); } }; // Play loop state Game.playState = { cursors: null, //player: null, preload: function() { console.info(Game.name + " play loop"); }, // Create your play logic here /*User*/ create: function() { console.info("Game params", Game); Engine.physics.startSystem(Phaser.Physics.ARCADE); // build map Game.map = Engine.add.tilemap("map"); Game.map.addTilesetImage("tiles", "terrain"); //"tiles name in JSON", "tileset" defined in preload state Game.map.setCollision(1, "map" + Game.level); /*Game.map.setTileIndexCallback(2, function(a, b, c) { console.info("callback", this, a, b, c) }, this);*/ Game.layer = Game.map.createLayer("map" + Game.level); Game.layer.resizeWorld(); Game.layer.debug = true; // add player Game.player = this._createPlayer(); Game.player.animations.play("tap"); Engine.physics.enable(Game.player); //Game.player.body.setSize(10, 14, 2, 1); this.cursors = Engine.input.keyboard.createCursorKeys(); // add HUD Game.HUD = Engine.add.text(10, Game.height - 15, "", { font: "15px Arial", fill: "#ffffff" }); }, update: function() { Engine.physics.arcade.collide(Game.player, Game.layer); this._checkInput(); this._updateHUD(); }, render: function() { Engine.debug.body(Game.player); }, _updateHUD: function() { Game.HUD.text = "Map:" + Game.level + " Score: " + Game.score + " Lives: " + Game.lives; }, _checkInput: function() { Game.player.body.velocity.set(0); if (this.cursors.left.isDown) { Game.player.body.velocity.x = -100; Game.player.play("left"); } else if (this.cursors.right.isDown) { Game.player.body.velocity.x = +100; Game.player.play("right"); } else if (this.cursors.up.isDown) { Game.player.body.velocity.y = -100; Game.player.play("up"); } else if (this.cursors.down.isDown) { Game.player.body.velocity.y = 100; Game.player.play("down"); } else { Game.player.play("still"); } }, _createPlayer: function() { var player = Engine.add.sprite(Game.tileSize, Game.tileSize, "player"); player.animations.add("left", [ 7, 8, 9, 10, 11, 12, 13 ], 20, false); player.animations.add("right", [ 14, 15, 16, 17, 18, 19, 20 ], 20, false); player.animations.add("up", [ 7, 8, 9, 10, 11, 12, 13 ], 20, false); player.animations.add("down", [ 14, 15, 16, 17, 18, 19, 20 ], 20, false); player.animations.add("still", [ 0 ], 10, false); player.animations.add("blink", [ 0, 1, 2, 1 ], 10, false).onComplete.add(function() { player.animations.play("still"); }); player.animations.add("tap", [ 3, 4, 3, 4, 5, 6, 5, 4, 3, 4, 3, 4, 5, 6, 5, 4 ], 10, false).onComplete.add(function() { player.animations.play("still"); }); return player; } }; // Setting up main states Engine = new Phaser.Game({ //enableDebug: false, width: Game.width, height: Game.height, renderer: Phaser.AUTO, antialias: false, //transparent: true, parent: "game" }); //Engine = new Phaser.Game(Game.width, Game.height, Phaser.AUTO, "game"); Engine.state.add("load", Game.loadState); Engine.state.add("main", Game.mainState); Engine.state.add("play", Game.playState); // Let's roll window.onload = function() { console.info(Game.name + " init"); Engine.state.start("load"); }; Attached are the assets I'm using for this project. Thanks in advance map.tmx map1.json
-
Hi! Like I said in another topic I have a problem with parenting pyhsicsImposter and thier collides. I finally prepared a playground to show the problem! http://www.babylonjs-playground.com/#ZENDZ2 You can throw a bullet(ball) with key E and move the mouse while holding left mouse button. Try to throw the bricks and change the color of all bricks! It dont works because you hit a some other brick physicsImpostor. Why? I want to hit each brick while they are parenting and dynamically add new objects (bricks). Edit: I want also remember to this parenting bug: Other Topic Maybe this problem depends on this.
- 1 reply
-
- collide
- physicsimpostor
-
(and 1 more)
Tagged with:
-
Hi all, I have a problem with collision. All my game is based on these codes: game.physics.arcade.collide(bullets, chest2,collision_handler); And it works. But... how to code collision two identical bullets? When I write like this: game.physics.arcade.collide(ebullets, ebullets, collision_handler); Only one of them is dying. How to do it? function collision_handler (object1, object2) { object1.kill(); object2.kill(); }
-
Okay so I have a rectangle boundary and I have 4 circles. Each of which I want to collide within this boundary. Is there a way to collide each sprite within this boundary without using p2? var rectangleBoundary = new Phaser.Rectangle(0, 120, 900, 1800); var c1 = game.add.sprite(200, 350, 'qcircle'); var c2 = game.add.sprite(500, 190, 'qcircle'); var c3 = game.add.sprite(120, 30, 'qcircle'); var c4 = game.add.sprite(590, 120, 'qcircle');
-
Hi everyone, I am using arcade physics and my collisions are definer by a Tiled layer. this.collisionLayer = collisionLayer; this.map.setCollisionByExclusion([], true, this.collisionLayer); I have a sprite attached to my cursor, but it seems that (in update) if (this.phaserGame.physics.arcade.collide(this.marker, this.collisionLayer)) { console.log('hey, cursor is over collide area !!'); } won't work because Phaser check if a Sprite is gonna collide, not if it's actually colliding. What I simply need is to know if my marker (or directly my input.activePointer) is colliding. Any clues ? EDIT : Actually : when updating marker position, I get the tile below my cursor. If there is a tile AND his property 'canCollide' is set to true, I did not update marker position. private setMarker() { let marker: Phaser.Sprite = this.marker, tilePointBelowPointer: Phaser.Point = this.pointToTilePosition(); // get tile coordinate below activePointer let tileBelowPointer: Phaser.Tile = this.map.getTileWorldXY(tilePointBelowPointer.x, tilePointBelowPointer.y, 16, 16, this.collisionLayer); if (tileBelowPointer && tileBelowPointer.canCollide) { // do something if you want } else { marker.x = tilePointBelowPointer.x; marker.y = tilePointBelowPointer.y; } }
-
Hi people! As i already discussed in an another topic in this forum, i'm having troubles with the collide function of the standard physic: I've checked with some log and apparently it is never called, even if the bodies on the scene push each other congruently with the collisionGroups and the collideAganist. Any ideas about what i'm missing? Thanks!
-
Hello, I am trying to make a platformer and have loaded my sprite with atlas, it works perfectly until I add collision. to keep the example simple I am using collideWorldBounds and the problem is that the sprite is colliding in the center and not the bottom where the little feet are. here are some screenshots and code snippets. var game = new Phaser.Game(300, 200, Phaser.AUTO, 'game', { preload: preload, create: create, update: update, render: render}); function preload() { this.game.load.atlas('player', 'assets/player/player_full.png', 'assets/player/player_full.json'); game.load.image('bg', 'assets/bg.jpg'); game.load.image('ground', 'assets/world/ground.png'); } var player; var facing = 'right'; function create() { // START game.physics.startSystem(Phaser.Physics.ARCADE); // ADD SPRITES game.add.image(0, 0, 'bg'); game.stage.backgroundColor = "#4488AA"; // PLAYER player = game.add.sprite(10, 176, 'player'); game.physics.enable(player, Phaser.Physics.ARCADE); player.animations.add('idle_right', ['idle_1_right.png', 'idle_1_right.png', 'idle_2_right.png', 'idle_3_right.png'], 4, true); player.animations.add('running_right', ['running_1_right.png', 'running_2_right.png', 'running_3_right.png', 'running_4_right.png', 'running_5_right.png', 'running_6_right.png'], 9.5, true); player.animations.add('idle_left', ['idle_1_left.png', 'idle_1_left.png', 'idle_2_left.png', 'idle_3_left.png'], 4, true); player.animations.add('running_left', ['running_1_left.png', 'running_2_left.png', 'running_3_left.png', 'running_4_left.png', 'running_5_left.png', 'running_6_left.png'], 9.5, true); player.animations.add('jump_right', ['jump_1_right.png', 'jump_2_right.png', 'jump_3_right.png', 'jump_3_right.png', 'jump_4_right.png', 'jump_5_right.png', 'jump_6_right.png'], 11, true); player.animations.add('jump_left', ['jump_1_left.png', 'jump_2_left.png', 'jump_3_left.png', 'jump_3_left.png', 'jump_4_left.png', 'jump_5_left.png', 'jump_6_left.png'], 11, true); player.animations.play('idle'); // WORLD game.physics.arcade.gravity.y = 250; game.physics.enable(player, Phaser.Physics.ARCADE); player.body.collideWorldBounds = true; } function update() { player.body.velocity.x = 0; if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { facing = 'right'; player.body.velocity.x = 90; player.animations.play('running_right'); }else if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { facing = 'left'; player.body.velocity.x = -90; player.animations.play('running_left'); }else if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { if (facing == 'right') { player.animations.play('jump_right'); }else{ player.animations.play('jump_left'); } }else{ if (facing == 'right') { player.animations.play('idle_right'); }else{ player.animations.play('idle_left'); } } }
-
Hi, Im making a platformer in Phaser and have successfully loaded a tilemap but my player doesn't collide with the tilemap layer. Here's my code. var game = new Phaser.Game(304, 208, Phaser.AUTO, 'game', { preload: preload, create: create, update: update, render: render}); function preload() { this.game.load.atlas('player', 'assets/player/player_full.png', 'assets/player/player_full.json'); game.load.image('bg', 'assets/bg-LONG.jpg'); // TILEMAP game.load.tilemap('world', 'assets/tilemaps/world.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('world_tiles', 'assets/tilemaps/world.png'); } var player; var facing = 'right'; var map; var tileset; var layer; function create() { // START PHYSICS game.physics.startSystem(Phaser.Physics.ARCADE); // ADD SPRITES game.add.tileSprite(0, 0, 900, 200, 'bg'); game.world.setBounds(0, 0, 900, 200); // PLAYER player = game.add.sprite(10, 176, 'player'); player.animations.add('idle_right', ['idle_1_right.png', 'idle_1_right.png', 'idle_2_right.png', 'idle_3_right.png'], 4, true); player.animations.add('running_right', ['running_1_right.png', 'running_2_right.png', 'running_3_right.png', 'running_4_right.png', 'running_5_right.png', 'running_6_right.png'], 9.5, true); player.animations.add('idle_left', ['idle_1_left.png', 'idle_1_left.png', 'idle_2_left.png', 'idle_3_left.png'], 4, true); player.animations.add('running_left', ['running_1_left.png', 'running_2_left.png', 'running_3_left.png', 'running_4_left.png', 'running_5_left.png', 'running_6_left.png'], 9.5, true); player.animations.add('jump_right', ['jump_1_right.png', 'jump_2_right.png', 'jump_3_right.png', 'jump_4_right.png', 'jump_5_right.png', 'jump_6_right.png'], 7, true); player.animations.add('jump_left', ['jump_1_left.png', 'jump_2_left.png', 'jump_3_left.png', 'jump_4_left.png', 'jump_5_left.png'], 7, true); // WORLD game.physics.arcade.gravity.y = 600; game.physics.enable(player, Phaser.Physics.ARCADE); player.body.collideWorldBounds = true; player.body.height = 24; // OTHER game.camera.follow(player); // TILEMAP map = game.add.tilemap('world'); map.addTilesetImage('world', 'world_tiles'); layer = map.createLayer('Tile Layer 1'); layer.resizeWorld(); } function update() { player.body.velocity.x = 0; game.physics.arcade.collide(player, layer); if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { facing = 'right'; player.body.velocity.x = 90; player.animations.play('running_right'); }else if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { facing = 'left'; player.body.velocity.x = -90; player.animations.play('running_left'); } if (game.input.keyboard.isDown(Phaser.Keyboard.UP) && player.body.onFloor() && game.input.keyboard.addKey(Phaser.Keyboard.UP).downDuration(1)) { if (facing == 'right') { player.animations.play('jump_right'); player.body.velocity.y = -230; }else{ player.animations.play('jump_left'); player.body.velocity.y = -230; } } if (player.body.velocity.x == 0 && player.body.onFloor() && player.body.velocity.y == 0) { if (facing == 'right') { player.animations.play('idle_right'); }else{ player.animations.play('idle_left'); } } } function render(){ game.debug.spriteInfo(player, 10, 20); }
-
Hi All Quick question, I am scratching my head on this for the last day - what am I doing wrong ? I have created a basic car driving on a highway and to avoid the cars. I hae created an enemies grou fornthe car and my car is a player object http://html5gamer.mobi/phaser2/carChase/index.html sample of script : in create I have : //player this.player = this.add.sprite(this.game.world.centerX, this.game.world.height - 200, 'player'); this.player.anchor.setTo(0.5); this.game.physics.arcade.enable(this.player); this.player.body.collideWorldBounds = true; this.player.customParams = {}; this.initEnemies(); this.scheduleEnemies = this.game.time.events.loop(Phaser.Timer.SECOND * 1, this.initEnemies, this); in update I have : // kill enemies when out of screen if (this.enemies.y > this.game.height){ this.enemies.kill(); } //player and enemy hit this.game.physics.arcade.overlap(this.player, this.enemies, this.killPlayer, null, this); rest of the functions : initEnemies: function(){ this.enemies = this.add.group(); this.enemies.enableBody = true; this.createEnemy(); }, createEnemy: function(){ // create a random lane for the cars to drive down - 4 lanes var carRandom = Math.floor((Math.random() * 4) + 1); ; if (carRandom == 1){ //console.log('1st lane'); this.laneX = 50; this.laneY = -150; this.vel = 400; } else if (carRandom == 2){ //console.log('2nd lane'); this.laneX = 220; this.laneY = -150; this.vel = 400; } else if (carRandom == 3){ //console.log('3rd lane'); this.laneX = 500; this.laneY = -150; this.vel = 900; } else if (carRandom == 4){ //console.log('4th lane'); this.laneX = 660; this.laneY = -150; this.vel = 900; } // creat random cars var key = Math.floor((Math.random() * 4) + 1); ; // create enemy if one exists in the enemies group var enemy = this.enemies.getFirstExists(false); if (!enemy){ enemy = this.add.sprite(this.laneX,this.laneY, 'car' + key); } else { enemy.reset(this.laneX,this.laneY, 'car' + key); } // make the cars move towards the bottom enemy.body.velocity.y = this.vel; // add enemy to enemies group this.enemies.add(enemy); if (carRandom > 2){ // reverse the car image in the last 2 lanes enemy.scale.setTo(-1); } }, killPlayer: function(player, enemy) { cosnole.log('HIT !'); this.player.kill(); this.game.state.start('GameState'); }, Thanks for any help in adavnce Eric
-
Hi, I prepare simple playground : http://www.babylonjs-playground.com/#UP2O8#33 You can see I have registered a CollideObservable in sphere, but when another box cross it, it dosen't execute callback function. Can anybody show me how to use onCollideObservable method?
-
Question Is there a way to log were body.blocked.left comes from? The "other" Object? - which is unknown? Explanation (why) There is something wrong. But I don't know what - haha the best posts start with that sentense. My character moves automatically and since body is blocked left || right he turns: now there is no object in the level, just nothing and he turns on an invisible object all the time... the behavior does even get stranger: if I let the character collide (on an placed object) in the other direction he would then pass the "invisible" object.. but if I then remove the "placed object to collide with", the invisible object seems to be there again (The invisible collision happens far of the placed object - it has nothing to do with it; I just placed it to see whats happening). This does not happen there only. I've got another game using Tilemaps, done with tiled were this is happening too.. -> I completely debugged the TileMap data but there is no collision object on that certain points were this happens. regards
-
Hello, I'm new at Phaser and i'm trying to make a map in Tiled and use it in my game, but the collide isn't working. My json Data: "data":[100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 89, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 91, 100, 100, 100, 100, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 100, 100, 100, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 100, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 100, 100, 102, 0, 0, 0, 0, 0, 0, 0, 0, 85, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 86, 86, 86, 86, 86, 86, 86, 86, 86, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 100, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 86, 86, 86, 86, 86, 86, 86, 86, 86, 87, 86, 86, 86, 86, 86, 86, 86, 86, 100, 100, 100, 100, 100, 100, 100, 100, 100, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100], map.setCollisionBetween(0, 999, true); Already tyied everything... Any solutions?! Thanks in advance!