Search the Community

Showing results for tags 'phaser'.



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 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 3,282 results

  1. Created a plain simple breakout game as an exercise to play around with Phaser v2.0.5. Designed two version: 1. A desktop version, control with arrow keys 2. Mobile version, play by pressing the left part or the right part of the canvas Desktop version: http://monsterenterprise.com/plain_breakout Mobile version: http://monsterenterprise.com/mobile_breakout
  2. LZY

    Super Coin Box (extended)

    Hi folks! I decided to make the modification of the @thomaspalef's "Discover Phaser" book example game. It still in progress with adding more levels, enemies types, etc. But it's ready in general. http://dmaslov.github.io/super-coin-box What you think about? Any feedback! Thanks in advance!
  3. darcys22

    Params to a listener

    I am trying to remove the physics effect on items in a group (shifts) when they are dragged. I am pretty much following the Arcade Physics: Gravity and Drag example. I have the following code: GameState.prototype.box = function(x, y, size) { ... blah ... var box = this.game.add.sprite(x,y,bmd); ... more blah ... box.events.onDragStart.add(this.startDrag, this); box.events.onDragStop.add(this.stopDrag(box), this); this.shifts.add(box);}GameState.prototype.startDrag = function() { //sprite.body.moves = false;}GameState.prototype.stopDrag = function(sprite) { sprite.body.moves = true;}startDrag doesn't give any errors (without the param) but I can't do anything with it. The problem I am having is when trying to pass a parameter (like with stopDrag) I get this error: [17:08:21.446] Error: listener is a required param of add() and should be a Function. @ http://localhost:8000/js/phaser.min.js:7Not really sure if I am missing something or if there is a better way of doing it. I am pretty new to both js and Phaser.
  4. rajeev90km

    How to remove textures from memory

    Hi, I have a phaser game and i'm using cocoon js to port it to android and IOS. unfortunately in IOS, since I am loading many images, it leads to a memory low warning and the app crashes. How do i delete the textures from the memory? Is there any way to clear the memory? I have tried cache.removeImage, cache.destroy and textureImage.destroy but doesnt seem to help much. Any help would be greatly appreciated. Thanks
  5. Salvatore

    Rotate Camera

    How to rotate the camera?? Is there a angle method?
  6. Hi there, i'm using Phaser for the first time and i have some problems understanding how it works. I'm developing a platformer in which the main character plays a different animation for each action (run, jump, etc). When a new animation is played the width/height values of the sprite body are not updated, instead the values of the first animation added are maintained. This is a problem when the frame's width/height of each animation are not the same. In my case the frame's height of an animation is less than the previous one, so it looks like the character is floating. Am i using Phaser the wrong way? Is there any workaround to fix this other than change the values manually?
  7. I am trying to move an image using tween. On the computer, It moves well but on smartphone it jumps and moves very slow, and also you cannot see the whole movement.
  8. wesleyorama

    Bullets not dying.

    I know you guys have seen a million of these before. I have read a couple of responses to older posts, checked the examples, and found other demos where what I am trying to do is working. Basically what I am seeing is, if there is only one bullet on the screen then when that bullet hits the player on the right it dies. However if there is more than one bullet then the last bullet fired is killed and the others just pile up. You can see it in action here: http://thedatacloset.com/project/ WASD moves the player on the right, while SHIFT shoots. Arrow keys move the player on the left, while Space shoots. Only one player is currently coded to take "damage" and kill the bullet. That is the player to the left. My code is attached below. I have been banging my head against it for a while now, so the code is a little jumbled. <!doctype html><html> <head> <meta charset="UTF-8" /> <title>hello phaser!</title> <script src="js/phaser.min.js"></script> </head> <body> <script type="text/javascript"> window.onload = function() { var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload() { game.load.image('sky', 'assets/sky.png'); game.load.image('ground', 'assets/platform.png'); game.load.image('bullet', 'assets/star.png'); game.load.spritesheet('dude', 'assets/dude.png', 32, 48);} var player;var platforms;var cursors;var mob;var facing;var mobFacing;var player1 = 0;var player2 = 0;var scoreText;var spaceKey;var bullet;var wKeyvar aKeyvar sKeyvar dKeyvar shiftKey function create() { // We're going to be using physics, so enable the Arcade Physics system game.physics.startSystem(Phaser.Physics.ARCADE); // A simple background for our game game.add.sprite(0, 0, 'sky'); // The platforms group contains the ground and the 2 ledges we can jump on platforms = game.add.group(); // We will enable physics for any object that is created in this group platforms.enableBody = true; // Here we create the ground. var ground = platforms.create(0, game.world.height - 64, 'ground'); // Scale it to fit the width of the game (the original sprite is 400x32 in size) ground.scale.setTo(2, 2); // This stops it from falling away when you jump on it ground.body.immovable = true; // Now let's create two ledges var ledge = platforms.create(400, 400, 'ground'); ledge.body.immovable = true; ledge = platforms.create(-150, 250, 'ground'); ledge.body.immovable = true; // The player and its settings player = game.add.sprite(32, game.world.height - 150, 'dude'); // We need to enable physics on the player game.physics.arcade.enable(player); // Player physics properties. Give the little guy a slight bounce. player.body.bounce.y = 0.2; player.body.gravity.y = 300; player.body.collideWorldBounds = true; // Our two animations, walking left and right. player.animations.add('left', [0, 1, 2, 3], 10, true); player.animations.add('right', [5, 6, 7, 8], 10, true); mob = game.add.sprite(750, 400, 'dude'); game.physics.arcade.enable(mob); mob.body.bounce.y = .02; mob.body.gravity.y = 300; mob.body.collideWorldBounds = true; mob.animations.add('left', [0,1,2,3], 10, true); mob.animations.add('right', [5,6,7,8], 10, true); // The score p1ScoreText = game.add.text(16, 16, 'Player1: 0', { fontSize: '32px', fill: '#000' }); p2ScoreText = game.add.text(600, 16, 'Player2: 0', { fontSize: '32px', fill: '#000' }); cursors = game.input.keyboard.createCursorKeys(); spaceKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); wKey = game.input.keyboard.addKey(Phaser.Keyboard.W); aKey = game.input.keyboard.addKey(Phaser.Keyboard.A); sKey = game.input.keyboard.addKey(Phaser.Keyboard.S); dKey = game.input.keyboard.addKey(Phaser.Keyboard.D); shiftKey = game.input.keyboard.addKey(Phaser.Keyboard.SHIFT); bullets = game.add.group(); bullets.enableBody = true; bullets.physicsBodyType = Phaser.Physics.ARCADE; bullets.createMultiple(30, 'bullet', 0, false); bullets.setAll('anchor.x', 0.5); bullets.setAll('anchor.y', 0.5); bullets.setAll('outOfBoundsKill', true); bullets.setAll('checkWorldBounds', true); } function update() { // Collide the player and the stars with the platforms game.physics.arcade.collide(player, platforms); game.physics.arcade.collide(mob, platforms); game.physics.arcade.collide(player, mob); game.physics.arcade.collide(bullets, platforms); game.physics.arcade.collide(bullets, player, p1Damage, null, this); game.physics.arcade.collide(bullets, mob); // Reset the players velocity (movement) player.body.velocity.x = 0; mob.body.velocity.x = 0; if (cursors.left.isDown) { // Move to the left player.body.velocity.x = -150; player.animations.play('left'); facing = 'left'; } else if (cursors.right.isDown) { // Move to the right player.body.velocity.x = 150; player.animations.play('right'); facing = 'right'; } else { // Stand still player.animations.stop(); player.frame = 4; } // Allow the player to jump if they are touching the ground. if (cursors.up.isDown && player.body.touching.down) { player.body.velocity.y = -350; } if (aKey.isDown) { mob.body.velocity.x = -150; mob.animations.play('left'); mobFacing = 'left'; }else if (dKey.isDown) { mob.body.velocity.x = 150; mob.animations.play('right'); mobFacing = 'right'; }else{ mob.animations.stop(); mob.frame = 4; } if (wKey.isDown && mob.body.touching.down) { mob.body.velocity.y = -350; } if (shiftKey.isDown) { mobShoot(); } if (spaceKey.isDown) { shoot(); }}var shotTimer = 0;function shoot() { if (shotTimer <game.time.now) { shotTimer = game.time.now + 275; if (facing =='right') { bullet = bullets.create(player.body.x + player.body.width / 2 + 20, player.body.y + player.body.height / 2 - 4, 'bullet'); }else{ bullet = bullets.create(player.body.x + player.body.width / 2 - 20, player.body.y + player.body.height / 2 - 4, 'bullet'); } bullet.body.velocity.y = 0; if (facing == 'right') { bullet.body.velocity.x = 400; }else{ bullet.body.velocity.x = -400; } }}var mobShotTimer = 0;function mobShoot(){ if (mobShotTimer<game.time.now) { mobShotTimer = game.time.now + 275; bullet = bullets.getFirstExists(false); if (bullet) { if (mobFacing =='right') { bullet = bullets.create(mob.body.x + mob.body.width / 2 + 20, mob.body.y + mob.body.height / 2 - 4, 'bullet'); }else{ bullet = bullets.create(mob.body.x + mob.body.width / 2 - 20, mob.body.y + mob.body.height / 2 - 4, 'bullet'); } bullet.body.velocity.y = 0; if (mobFacing == 'right') { bullet.body.velocity.x = 400; }else{ bullet.body.velocity.x = -400; } } }}function destroyBullet(){ bullet.kill();}function p1Damage(player, bullet){ destroyBullet() player2 +=1 p2ScoreText.text = 'Player2: ' + player2;} }; </script> </body></html>
  9. Hello Phaser community. I have set up a simple example http://www.oddskill.net/coding/fullscreentest/ that shall go in NO_SCALE fullscreen mode when clicking the start button . That only works in chrome. In firefox 31.0 and ie 11.0.11, tested on Win 7 and Win 8.1. the game fills the entire screen when pressing the start button, and sprite is not clickable anymore. Same issue occurs when using SHOW_ALL as scale mode, regardless of the screens aspect ratio. Can anybody confirm that behaviour, is it a Phaser bug, or do i do something wrong in my code? I s there a way to scale the game "area" in fullscreen mode by hand using something like. ******************************************* this.scale.minWidth = 320;this.scale.minHeight = 480;this.scale.maxWidth = 640;this.scale.maxHeight = 960;this.scale.setScreenSize(true);******************************************which at first glance seems to work in NOT fullscreen mode ? Any help would really be appreciated as by now i really spend to much time playing around with that fullscreen issue. best regards Chris PS: sourcecode below var game = new Phaser.Game(640, 480, Phaser.CANVAS, 'container', { preload: preload, create: create, update: update });var img;var spriteexplosion;var sound;var startbutton;function preload() { game.load.image('cow', './assets/cow.png'); game.load.audio('explosionsfx', 'assets/explosion.wav'); game.load.spritesheet('explosiongfx', 'assets/explosion.png', 128, 128, 16); game.load.spritesheet('control_startbtn', 'assets/control_startbutton.png', 107, 41, 1);}function create() { game.scale.fullScreenScaleMode = Phaser.ScaleManager.NO_SCALE; game.stage.backgroundColor = '#00ff00'; game.physics.startSystem(Phaser.Physics.ARCADE); img = game.add.sprite(20, 20, 'cow'); game.physics.enable(img, Phaser.Physics.ARCADE); img.body.velocity.x=100; img.body.velocity.y=100; img.body.collideWorldBounds = true; img.body.bounce.set(1); img.anchor.setTo(0.5, 0.5); img.inputEnabled = true; img.input.start(0, true); img.events.onInputDown.add(select); sound = game.add.audio('explosionsfx',1,true); startbutton = game.add.button(game.world.centerX, 100, 'control_startbtn', goFull, this, 0, 0, 0); startbutton.name = 'btn_startbtn'; startbutton.anchor.setTo(0.5, 0.5); }function update() { }function goFull(){ game.scale.startFullScreen();}function select(img, pointer) { img.destroy(); sound.play('',0,1,false); spriteexplosion = game.add.sprite(img.x, img.y, 'explosiongfx'); spriteexplosion.anchor.setTo(0.5, 0.5); spriteexplosion.animations.add('explosiongfx_anim'); spriteexplosion.animations.play('explosiongfx_anim', 20, false);}
  10. Brad P. Taylor

    Text wrapping to shapes?

    Anyone got a bit of code for Phaser (or PIXI.Text) that does text wrapping to fit inside simple geometry or better yet arbitrary masks?
  11. Brad P. Taylor

    FlickrSprite (flickr + phaser.Sprite)

    Hello Everyone, I was in need of some temporary art for a project and it dawned on me hey Flickr's API has the ability to search on tags and licenses... lightbulb moment - hey wouldn't it be great if I could just ask Flickr for an image with a set of tags and get sprite back (or a list of related images you can find the gist here http://goo.gl/lYJ9FX oh yeah you need to have a flickr api key and there are limits to the number of images you can pull down an hour, so it probably makes sense to implement some sort of local caching system. (or you could just copy them from your browser cache like I did after getting them...) Cheers, -bpt
  12. Hello Everyone, This is a question, possible answer and a feature request all rolled into one. First the question: For my UI I need a way to set a specific sprite (or set of sprites) to be the only ones with active inputHandlers, Basically setCapture/releaseCapture... I spent a fair amount of time looking over the input system and didn't see this feature? My 'answer' http://goo.gl/3aUk2y This code adds setCapture, releaseCapture and getCapture to the Phaser.Input class. setCapture takes a single inputHandler or an array of them and will push the currently active notion of interactiveItems making the arguments the current set of interactive elements. The releaseCapture method restores things to the state before the push and of course getCapture returns the inputHandlers that have captured input. The feature request My hack works enough for now, but it seems clunky and woe to me if I ever need enable/disable sprite inputs while inside a capture mode. A more robust event bubbling system for sprites (and groups), would be really handy. I know this isn't a trivial request but it would probably make things easier for making certain types of UI. Cheers, brad
  13. Jippe joosten

    Phaser Scaling bug

    Hey guys, I made a minigame in Phaser. This game was working fine until you try to resize the browser. What i want is that the hole game is scaling to the browsers canvas. here is some code and the pictures of what is going wrong: When the games startup: window.addEventListener('load', function() { window.EMS.requestFullscreen(); setTimeout(function() { scale = Math.min(window.innerWidth / 1920, window.innerHeight / 1080); scaleWidth = scale;//(window.innerWidth / 1920); scaleHeight = scale;//(window.innerHeight / 1080); game = new Phaser.Game(1920, 1080, Phaser.AUTO, 'area', { preload: preload, create: create, update: update, render: render }); }, 1);});Then for the resize i used: function resizeGame() { scale = Math.min(window.innerWidth / 1920, window.innerHeight / 1080); scaleWidth = scale;//(window.innerWidth / 1920); scaleHeight = scale;//(window.innerHeight / 1080); // game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; game.scale.maxWidth = window.innerWidth; game.scale.maxHeight = window.innerHeight; worldWidth = game.world.width * scale; worldHeight = game.world.height * scale; BG.width = worldWidth; BG.height = worldHeight; //game.stage.bounds.width = window.innerWidth; //game.stage.bounds.height = window.innerHeight; //game.renderer.resize(window.innerWidth, window.innerHeight); //game.camera.setSize(window.innerWidth, window.innerHeight);}This is what happend: http://puu.sh/b8CDC/09916cdfe9.png http://puu.sh/b8CD8/8064a1140d.png I hope some of you understands what went wrong here and can help me out.
  14. hello guys i'm newbie in phaser framework so i have questiion to finish a game my game is the same with ninja fruit but i have a problem with the animation when the players cut the object in the game for example fruit i do it when the player touch the object it kill but me i like to add some animation like those in ninja fruit when you touch the fruit he show knife but the fruit and then divided them into parts of the place of the cut (lump it) me i create the game the some of this http://examples.phaser.io/_site/view_full.html?d=particles&f=collision.js&t=collision and i add when the player touch any fruit the fruit will kill and be invisible but i like to add animation like ninja fruit i Explained it in the top so help me , and thanks
  15. Here's my current code: function create(level) {¬ phaser.physics.startSystem(Phaser.Physics.NINJA); game.map = phaser.add.tilemap('tilemaps_' + level); game.map.addTilesetImage('images_tiles_' + level); game.layer = game.map.createLayer('tilemaps_' + level + '_layer'); game.layer.resizeWorld(); if (level == 'fire') { game.map.setCollision(1); // the array at the end isn't actually optional; bug in Phaser methinks game.collideLayer = phaser.physics.ninja.convertTilemap(game.map, game.layer, [1, 1, 1, 1, 1, 1, 1, 1]); } ...} function update(level) { ... if (level == 'fire') phaser.physics.ninja.collide(game.player, game.collideLayer); ...} It just won't work. The player flies right through the ground tiles that he's supposed to walk on. I've tried every possible combination of game.layer, game.currentLayer, game.map.layer, etc., but none of them seem to be working. I can see the tileset load correctly, and everything else is working fine. So why won't this work?
  16. super001

    problem using phaser in meteor

    Hi, I wanted to use phaser in meteor following this guide http://www.html5gamedevs.com/topic/4886-how-to-use-phaser-with-meteor/ but I have a problem. when I create a meteor project and then run "meteor add phaserio" I get this: mrt add phaserio✓ phaserio tag: https://github.com/t...aser.git#v0.0.1 Done installing smart packages Stand back while Meteorite does its thing Done installing smart packages Ok, everything's ready. Here comes Meteor! => Errors while scanning packages: While building package `phaserio`:error: File not found: phaser/build/phaser.js /usr/lib/node_modules/meteorite/lib/command.js:41 throw "Command exited with " + code + "/" + signal; ^Command exited with 1/null can anybody help me, please?
  17. cdrch

    Collision Suddenly Stops

    I'm relatively new to Phaser (only a few months of experience with it), so it didn't come up until recently that I attempted using tilemaps (which in this case are JSON files generated with Tiled) that have multiple layers. My code works fine with a single layer, but all collision between a layer and anything else stops working when I modify the code to add a second layer. In addition, creating sprites from the object layer (createFromObject) doesn't seem to work either. In my simplest test, the only change was adding a second layer to the map file (both layers share a single tileset), and the only change in the code is adding: var layer2; layer2 = map.createLayer('Tile Layer 2'); Both layers display properly, but collision stops working. I thought I had read that Phaser could handle multiple tile layers now. Is there something I'm missing that I need to have to get this to work?
  18. Brad P. Taylor

    limiting child sprite input

    Hi All, While working on the ui for my project I needed to disable input for sprites that were clipped to a smaller scrolling view (think scrolling list), I peeked around the Input and InputHandler code and didn't see an way to restrict the input for the child from a parent (or grandparent)? Anyway I cobbled together a way to clip input for decedents. The code can be found in a small gist here http://goo.gl/LTfFOy It's pretty simple it modifies the prototype for InputHandler, by adding an ancestor search after any truthy result returned by the original checkPointerDown or CheckPointerOver. This allows any ancestor to define a property (defaults to 'input_clipping_rect') which will can be used to reject false positives (ie things outside the smaller view but inside the child). Here is the code too just in case the gist isn't available. (function(property) { var local = new Phaser.Point(); function askAncestors( child, pointer ) { for ( var parent = child.parent; parent; parent = parent.parent ) { var clip = parent[property]; if ( !clip ) continue; parent.game.input.getLocalPosition( parent, pointer, local); var cx = local.x - clip.x, cy = local.y - clip.y; return (0 <= cx) && (cx < clip.width) && (0 <= cy) && (cy < clip.height); } return true; } var _checkPointerDown_ = Phaser.InputHandler.prototype.checkPointerDown; Phaser.InputHandler.prototype.checkPointerDown = function(pointer, fastTest) { if ( !_checkPointerDown_.call( this, pointer, fastTest ) ) return false; return askAncestors( this.sprite, pointer ); } var _checkPointerOver_ = Phaser.InputHandler.prototype.checkPointerOver; Phaser.InputHandler.prototype.checkPointerOver = function(pointer, fastTest) { if ( !_checkPointerOver_.call( this, pointer, fastTest ) ) return false; return askAncestors( this.sprite, pointer ); } })( 'input_clipping_rect' );
  19. hi, I just started using Phaser. it's awesome, really easy to learn and use. I was wondering how to set up a project. I know there are many ways: the easy one is to have a index.html file, a .js file and the phaser.min.js. I'm currently making a game but the .js file has reached 300 lines of code, that is not a good thing as it could be a bit counfusing, expecially for someone who wants to contribute. so my question is how can I set up a Phaser projects making it easy understandable? P.S. I need i detailed guide/explanation if possible thanks a lot.
  20. Hello ! I'm working on a micro game that can be tested on this page : http://le-carre-noir.net/click-the-black-squares-beta/ On a mouse-in on my button GO, the frame is changed, so it goes green... But it doesn't go back white on mouse-out... Here is my code : this.button = this.game.add.button(this.game.world.centerX, 525, 'startBtn', this.actionOnClickStartButton, this, 1, 0, 0);Here is the git repository : https://github.com/robomatix/click-the-black-squares My code is the line 33 of game/states/menu.js Can someone please help me to do a rollover effect as on the web...
  21. Hi, I was wondering how could I deploy my Phaser app and pubblicate it on Play Store / App Store etc... Is it possible? Thanks
  22. end3r

    Triskaidekaphobia

    I've created a game called Triskaidekaphobia to promote the js13kGames competition. The name of the game means "the fear of the number 13", so I thought it would be perfect for this gig. The story is simple: you are in the dark forest full of terrors and have to run away from the vicious Thirteens. Tap to jump between branches to avoid them. You can PLAY THE GAME HERE. As usual: the game was created using Phaser, you can read very short "making of" blog post about it. How do you like the minimalistic art style? Any feedback will be much appreciated.
  23. Hey folks, I'm new around here and very new to Game Development. I'm a web developer but have started learning game development with Phaser and HTML5. I am also new to Javascript. Never the less, here is my first game that I have ever made on any platform...ever! (Be gentle). SLIME BALL. Play Here: http://webheed.com/games/slime-ball/ Any feedback would be much appreciated. I am also planning on making it mobile friendly and then adding to the app store. If anyone knows any goo tuts on how to use the accelerometer with Phaser then I would be very grateful. Cheers, Kieran. www.webheed.com
  24. jjimenez

    Collision shapes

    Hi, the latest weeks I have been working on a little game. This is my first game using Phaser, so at the begining I started using the arcade physic system. But, with the arcade physic, it's just possible to handle sprite collisions by boxes. As far as I know, to create a sprite with other kind of collision shape, you need to use another physic system, like ninja. I was looking some info in the internet, and seeing some examples in the phaser official page. The only way I found to do that, was to use ninja physic, and create a tile with it in this way: game.physics.ninja.enableTile(sprite, TILE_SHAPE);Reading the code in the examples, I understood that, the possible tile shapes are those in this picture: http://examples.phaser.io/assets/physics/ninja-tiles128.png My problem was that my sprite didn't fit any shape in the picture. So finally, what I did was to create a group with two sprites, each of the sprites has it's own tile with a different shape (in my case, these shapes were 21 and 22). And then, apply the movement and all required properties to the group or to all the sprites in the case i needed it. My question is, is this the right way of doing this? Or is there any better way (cleaner, efficient, etc.) of doing this? Thanks in advance!
  25. steve228uk

    Collision Groups Not Working

    Hi Guys, I've just started playing with Phaser and am loving it. I seem to be having some problems with collision groups though. I'm using game.physics.p2.convertCollisionObjects method but can't seem to get my player to collide with my platforms. I've uploaded what I've got so far and was hoping someone would be able to shed some light on this. Any help is extremely appreciated. http://steve228uk.webfactional.com/game/ Cheers! Steve Edit: It's probably easier if I post the code here too: var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, 'game');var mainState = { preload: function() { game.load.tilemap('map', 'assets/level1.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', 'assets/tilemap50.png'); game.load.spritesheet('dude', 'assets/dude.png', 32, 48); game.load.image('bg', 'assets/bg.jpg'); }, create: function() { this.setup(); this.createMap(); this.createPlayer(); }, setup: function(){ game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.setImpactEvents(true); game.physics.p2.restitution = 0.8; var bg = game.add.sprite(0, 0, 'bg'); bg.fixedToCamera = true; this.cursors = game.input.keyboard.createCursorKeys(); }, createMap: function(){ game.stage.backgroundColor = '#787878'; this.map = game.add.tilemap('map'); // The first parameter is the tileset name, as specified in the Tiled map editor (and in the tilemap json file) // The second parameter maps this name to the Phaser.Cache key 'tiles' this.map.addTilesetImage('Tilemap50', 'tiles'); this.platforms = this.map.createLayer('Level1'); this.platforms.resizeWorld(); this.createCollisions(); }, createCollisions: function(){ this.collisionGroups = { player: game.physics.p2.createCollisionGroup(), platforms: game.physics.p2.createCollisionGroup(), }; var lines = game.physics.p2.convertCollisionObjects(this.map, 'Collisions', false); for(var line in lines){ lines[line].setCollisionGroup(this.collisionGroups.platforms); lines[line].collides(this.collisionGroups.player); } game.physics.p2.updateBoundsCollisionGroup(); }, createPlayer: function(){ this.player = game.add.sprite(32, 0, 'dude'); game.physics.p2.enable(this.player); // Player physics properties. Give the little guy a slight bounce. this.player.body.enable = true; this.player.body.gravity.y = 300; this.player.body.collideWorldBounds = true; this.player.body.setCollisionGroup(this.collisionGroups.player); console.log(this.collisionGroups.player); console.log(this.collisionGroups.platforms); this.player.body.collides(this.collisionGroups.platforms, function(){ console.log('collided'); }); game.camera.follow(this.player); // Our two animations, walking left and right. this.player.animations.add('left', [0, 1, 2, 3], 10, true); this.player.animations.add('right', [5, 6, 7, 8], 10, true); }, update: function() { // game.physics.p2.collide(this.player, this.collisions); this.handleInput(); }, handleInput: function(){ this.player.body.velocity.x = 0; if (this.cursors.left.isDown) { // Move to the left this.player.body.velocity.x = -150; this.player.animations.play('left'); } else if (this.cursors.right.isDown) { // Move to the right this.player.body.velocity.x = 150; this.player.animations.play('right'); } else { // Stand still this.player.animations.stop(); this.player.frame = 4; } // Allow the this.player to jump if they are touching the ground. if (this.cursors.up.isDown && this.player.body.touching.down) { // this.player.body.velocity.y = -350; } }};// Add and start the 'main' state to start the gamegame.state.add('main', mainState);game.state.start('main');