Search the Community

Showing results for tags 'phaser2'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Platform
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Website URL





Found 56 results

  1. I am trying to add a simple countdown timer to a Phaser game. When the timer ends I want the game to restart. After adding the timer code there are no errors in the console but I can't get the timer to appear on the screen. Where I am going wrong please? I am new to Phaser and am still learning Javascript - any help would be greatly appreciated! Please see my code below (for clarity, I have only pasted the relevant code, not the whole thing). Thanks for any help in advance. PlayState = {}; PlayState.init = function () { //.... }; PlayState.preload = function () { //.... }; PlayState.create = function () { //TIMER CODE: this.timeInSeconds = 120; this.timeText =,, "0:00",{font: '15px Arial', fill: '#FFFFFF', align: 'center'}); this.timeText.anchor.set(0.5, 0.5); this.timer =, this.updateTimer, this); }; PlayState.update = function () { //..... }; PlayState.updateTimer = function() { this.timeInSeconds--; var minutes = Math.floor(this.timeInSeconds / 60); var seconds = this.timeInSeconds - (minutes * 60); var timeString = this.addZeros(minutes) + ":" + this.addZeros(seconds); this.timeText.text = timeString; if (this.timeInSeconds == 0) {; } }; //add leading zeros to any number less than 10 //for example turn 1 to 01 PlayState.addZeros = function(num) { if (num < 10) { num = "0" + num; } return num; }; window.onload = function () { let game = new Phaser.Game(1280, 800, Phaser.CANVAS, 'game'); game.state.add('play', PlayState); game.state.start('play'); };
  2. Hello, I am just new to phaser2. I want to develop a billiard game, more similar like this:- But I don't know how to start with as there are many physics components in phaser. Any guide or tutorial to develop this game in phaser2?
  3. Hello, I`m just getting started with game development and I`m trying to make a copy of Tetris that can be played on mobile phone as well. I want to be able to move the blocks with left/right/up arrows(from keyboard) and with 3 buttons that are displayd on the screen. Here I`m declaring the buttons(inside create function): create: function(){ //.... rotate_bricks = this.add.button(350, 180, 'rotate-shape', Tetris.Blocks.rotate, this); left_arrow = this.add.button(345, 240, 'left-arrow', Tetris.Blocks.moveLeft, this); right_arrow = this.add.button(345, 300, 'right-arrow', Tetris.Blocks.moveRight, this); //... }, And here is the moveLeft function: Tetris.Blocks = { moveLeft: function(game) { let points = 0; /*make a local variable, if all of the 4 blocks can be moved 30 px left/right then move it, if some of them will get out of the box, then don`t move Test for all blocks available on the map */ for(let i = 0; i < Tetris.allBlocks.children.length; i++) { //test if blocks collide with each others for(let j =0 ; j < Tetris.allBlocks.children[i].children.length; j++) { if(!(Tetris.allBlocks.children[i].children[j].body.velocity.y === 0) || Tetris.allBlocks.children[i].children[j].body.y > 370) { if(Tetris.allBlocks.children[i].children[j].body.x - 30 > 0) { points++; } else { break; } } } } for(let i = 0; i < Tetris.allBlocks.children.length; i++) { //test if blocks collide with each others for(let j =0 ; j < Tetris.allBlocks.children[i].children.length; j++) { if(!(Tetris.allBlocks.children[i].children[j].body.velocity.y === 0) || Tetris.allBlocks.children[i].children[j].body.y > 370) { if(points === 4) { console.log(Tetris.allBlocks.children[i].children[j].body.x);//for test Tetris.allBlocks.children[i].children[j].body.x = Tetris.allBlocks.children[i].children[j].body.x - 30; console.log(Tetris.allBlocks.children[i].children[j].body.x); } else { break; } } } } console.log("moved left"); }, the problem is that the console.log function is executed but the position isn`t changed(I know it works because when I use the keyboard everything is fine, I call the same function) The variable Tetris.allBlocks is declared globally(inside Tetris.Game as: var Tetris.allBlocks = ...); What it`s wrong? I couldn`t find an answer online
  4. Hello, I have an issue which keeps me stuck and I could not yet figure it out after being stuck for quite some time. I have a simple game in which obstacles ( spirtes of other cars) drop down from the top of the screen and I am trying to avoid those with my own car not to crash into them. The issue is that on some mobile devices the cars drop WAY faster than on my own device, I tested this from several different phones, the velocity differs depending on the phone, on some the obstacles drop faster on some they drop really slow. What oculd cause such an issue? I can provide code if it helps. Thanks,
  5. Hi, Is it relevant to apply a pooling system to Phaser's Tweens in optic to reduce the garbage collector invocation ? Because this subject as already been asked but dont find a clear answer : Thanks
  6. Hello! I am trying to make a player to collide with the ground. But the ground has been imported from a tilemap using the tiled program. The collision is not working This is the important part of my code: collisionLayer = map.createStaticLayer('collisionLayer', tileset); var players = findObjectsByType('player', map, 'objectsLayer'); player = this.physics.add.sprite(players[0].x, players[0].y, 'dude'); this.physics.add.collider(player, collisionLayer); findObjectsByType is not a phaser native method, but it is working. The code runs without errors, but the collision is not working. I have attached the code. Thanks!
  7. Question about keyboard controls. I'm working on a simple action game in Phaser CE, the player touches certain parts of the screen to do various actions. The mouse/touch input parts work fine and now I also want to support keyboard input for people playing on desktop. The problem is; the game is running inside an iframe and the keyboard input works correctly until the canvas loses focus. The game pauses which is correct behaviour, then I click inside canvas again, game continues and mouse input still works. But now the keyboard input is not working anymore. When the game is not running inside an iframe this is not a problem, the keyboard continues to work after losing focus, pausing and then continuing. Do I have to use something other than "game.input.keyboard.addCallbacks" to check for keyboard input? This is my code mygame.GameState.prototype = { create: function() { this.stage.backgroundColor = "#f0f"; this._levelindex = 0; // .. // etc. // game input for mouse and keyboard, this); // mouse/touch, this.doGameKeyInput, null, null); // keyboard // .. }, onGameMouseDown: function(evt) { // code.. ok works fine }, doGameKeyInput: function(key) { var kc = key.keyCode; var action = 0; if (kc == 32) {action = 1}; // space if (kc == 90) {action = 2}; // Z if (kc == 88) {action = 3}; // X // etc. this works until canvas loses focus } } FYI i'm using Windows 10 and Chrome
  8. Hi, Is there any method to reset an emitter properly to be reused ? because i reuse a set of emitters but sometimes when i reuse a previously used emitter it show quickly his last state (repartition of particules in their last coordinates) and then restart his animation, so i wonder if is it a bug or a bad use. EDIT : It's a bad. Code used to instanciate the emitters in the poolEmitter (extended instance : em = game.add.emitter(10,16,30) // some emitter settings (minRotation, setXSpeed,makeParticles...) em.kill() this.add(em) Code used in the poolEmitter instance to get a free (dead) emitter : let obj = this.getFirstDead(false) obj.revive() obj.x = x obj.y = y return obj Code used for exploitation of the emitter : let em = poolEmitter.create(player.x ,player.y) em.explode(800,30) setTimeout(function(){ em.kill() em.on = false em.visible = false /* em.forEach(function(p) { // I try this to hide the particule manually to avoid to be showed in their last coord when reuse the emitter, but dont work p.alpha = 0 })*/ },900) Thanks
  9. help in my game I eliminate an enemy with enemy.kill () and deasa appears but the associated weapon keeps firing .. and enemy.destroy () gives me an error ..
  10. Welcome to online Math Mahjong Relax. Math Mahjong Relax is a traditional solitaire game where you have to take apart the construction made of dice. The game helps to improve your attention, speed and math skills. Dice differ in the image on the upper edge. With one move, you can get only two same and open dice. The dice is considered open if its left or right face is open. The game includes 36 levels from simple to complex ones. In the beginner levels you will learn the rules, find out which dice differ and which ones can be interchangeable. Online Math Mahjong Relax iOS Math Mahjong Relax Android Math Mahjong Relax
  11. Hello! I want to use method BringToTop for layer data item. But it doesnt work for me. I have some layers, and i want to hide my character behind some sprites. I need something like that: But i have got it: Here is my code: this.parent.Location.location ='map'); if (!this.parent.Location.props.images) { console.error('Images are empty or undefined read for information'); return false; } _.each(this.parent.Location.props.images, (layer, index) => { this.parent.Location.location.addTilesetImage(,; this.parent.Location[layer.layer] = this.parent.Location.location.createLayer(layer.layer); this.parent.Location[layer.layer].resizeWorld(); if (_.size(layer.bringToTop)) { this.bringToTop(index, layer.bringToTop); // 0, [6,7] } }); bringToTop(index, bringToTopArray) { let gid = this.parent.Location.location.tilesets[index].firstgid; _.each(bringToTopArray, (itemBring) => { _.each(this.parent.Location.location.layers[index].data, (layerData) => { _.each(layerData, (layerDataItem) => { if ((itemBring + gid) === layerDataItem.index) { let timeAfterLoad =, () => {;; }); } }); }) }); } If you know another ways how i can resolve that problem, let me know please.
  12. Here is my issue: Uncaught TypeError: Cannot read property 'getFrameIndexes' of null at i.AnimationManager.add (phaser.min.js:3) at Object.create (hub.js:45) at i.StateManager.loadComplete (phaser.min.js:3) at i.StateManager.preUpdate (phaser.min.js:3) at i.Game.updateLogic (phaser.min.js:3) at i.Game.update (phaser.min.js:3) at i.RequestAnimationFrame.updateRAF (phaser.min.js:3) at window.requestAnimationFrame.forceSetTimeOut._onLoop (phaser.min.js:3) Here is my code: if(game.spawn == 0){ player = game.add.sprite(500, 800, 'guy'); } else if(game.spawn == 1){ player = game.add.sprite(1700, 1002, 'guy'); } horn = 0; player.scale.setTo(1,1); game.physics.arcade.enable(player); player.body.collideWorldBounds = true; up = game.input.keyboard.addKey(Phaser.Keyboard.W); down = game.input.keyboard.addKey(Phaser.Keyboard.S); left = game.input.keyboard.addKey(Phaser.Keyboard.A); right = game.input.keyboard.addKey(Phaser.Keyboard.D); y = game.input.keyboard.addKey(Phaser.Keyboard.Y); n = game.input.keyboard.addKey(Phaser.Keyboard.N); f = game.input.keyboard.addKey(Phaser.Keyboard.F); f.onDown.add(hub.gofull, this); q = game.input.keyboard.addKey(Phaser.Keyboard.Q); q.onDown.add(, this); game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT;, Phaser.Camera.FOLLOW_LOCKON, 0.1, 0.1); player.animations.add('right', [14,16], 6, true); player.animations.add('left', [20,22], 6, true); player.animations.add('down', [2,4], 6, true); player.animations.add('up', [10,8], 6, true);
  13. Hello, I am working on a project where i can drag an object in X-direction only(like in a abacus). Is it possible to drag objects in one direction only? I created a simple task where i can move two objects with mouse (link here). The issue is that objects are pushing inside each other if i drag one object to another. I need them to be hard like diamond. Can i achieve that with p2 js or i have to use box2d plugin (like here). Also is box2d will be availabe in phaser v3. Thanks
  14. Всем привет! Если мы напишем let enabled =['UIAtlas', 'InGameAtlas']); в первом состоянии текстуры отображаются нормально. При изменении состояния.'InGame'); текстуры исчезают. информация об отладке в чем проблема? Благодаря!
  15. I'm trying to zoom camera (change its scale) while focused on a player on a tilemap. const speed = 0.01; if (this.cursors.up.isDown) {, speed); } else if (this.cursors.down.isDown) {, -speed); } This is how I create the map: this.map16 ="tilemap16"); this.map16.addTilesetImage("xrpg_tileset", "tileset16"); this.wallsLayer = this.map16.createLayer('Walls'); Both player object and the map layers are placed in the World. But it seems that tilemap layer's position is affected by camera's zoom which looks wrong: To check if something is wrong with the scene I replaced the map with an image and zoom worked correctly: The behaivor is identical in 2.6.2 and 2.10.3.
  16. CodePen I feel confusing when i use Tween.from. Using Tween.from without repeat param the animation shows correctly.It move from (100,0) to (0,0).But when i use Tween.from with repeat param. The repeat is from (0,0) to (100,0).Why?I think it would repeat always from (100,0) to (0,0)
  17. I am learning Phaser CE API and i cannot understand the param `alphaThreshold` in the method enableDrag. Anybody can tell me how to use it correctly?
  18. Hey, So I am working on a car game and I have 1 issue with the speed at which car drops. My friend who owns a IPhone s6 complains that on his device the cars drop too fast, while on my Samsung s7 edge the car seems to drop slow enough. I dont know what might cause it. My obstacle velocity is set to 1200; // OBSTACLES vars var obstacleSpeed = 1200; var obstacleDelay = 400; var platforms; var score; And this is my Loop + update function // OBSTACLES OF THE CAR, function(){ var obstacleSpeed = 1200; var obstacleDelay = 400; for(var i = 0; i < 1; i++){ if(game.rnd.between(0, 1) == 1){ var obstacle = new Obstacle(game, i); obstacle.scale.setTo(scaleRatio, scaleRatio); game.add.existing(obstacle); obstacleGroup.add(obstacle); } } }); // Game on touch move car game.input.onTap.add(function() { if (game.input.x < w / 2 ){ if( canMove && goleftonce == 2 || goleftonce == 1) { canMove = false; goleftonce++; gorightonce--; game.add.tween(car).to({ angle: -30}, 100, Phaser.Easing.Linear.None, true).onComplete.addOnce(function(){ game.add.tween(car).to({ angle: 0}, 100, Phaser.Easing.Linear.None, true); canMove = true; }, this); game.add.tween(car).to({x: car.x - w/3}, 100, Phaser.Easing.Linear.None, true); } } else { if( canMove && gorightonce == 2 || gorightonce == 1) { canMove = false; goleftonce--; gorightonce++; game.add.tween(car).to({ angle: 30}, 100, Phaser.Easing.Linear.None, true).onComplete.addOnce(function(){ game.add.tween(car).to({ angle: 0}, 100, Phaser.Easing.Linear.None, true); canMove = true; }, this); game.add.tween(car).to({x: car.x + w/3}, 100, Phaser.Easing.Linear.None, true); } } }); }, update: function() { // Collide the car and with the obstacles aka other cars game.physics.arcade.collide(car, obstacleGroup, function(){ canMove = true; countcars = 0; goleftonce = 2; gorightonce = 2; game.state.start('gameover'); }); } } // Position where the obstacle spawns Obstacle = function (game) { var position = game.rnd.between(0, 2);, game, (w/3) * position + 130 , 0, "obstacle"); game.physics.enable(this, Phaser.Physics.ARCADE); }; Obstacle.prototype = Object.create(Phaser.Sprite.prototype); Obstacle.prototype.constructor = Obstacle; Obstacle.prototype.update = function() { this.body.velocity.y = obstacleSpeed; if(this.y > game.height){ countcars++; score.setText("Score: " + countcars); this.destroy(); } };
  19. Hello, I am at my first game ever and I choose phaser2, latest CE version. Basically I have 3 lanes and I am trying to spawn cars on these lanes, and the player must avoid crashing into them. The game orientation I choose is portrait. I have a few questions that maybe you guys can help me with, if you are willing of course 1. I am using the default Phaser arcade Physics. Should I choose something else? I am unhappy with the collision point between the cars at the moment. 2. On Iphones and tablets I have issues with the scaling. The collision between cars is huge (I am talking about the area of collison). I have this in the index.html <meta name="viewport" content="width=device-width, initial-scale=1"> Then I am using this in my main js. scaleRatio = window.devicePixelRatio / 3; // Get device sizes var w = window.innerWidth * window.devicePixelRatio; var h = window.innerHeight * window.devicePixelRatio; var game = new Phaser.Game(w, h, Phaser.CANVAS, '', { init: init, preload: preload, create: create, update: update, render: render }); function init() { // make the game occuppy all available space, but respecting // aspect ratio – with letterboxing if needed = Phaser.ScaleManager.SHOW_ALL; = true; = true; = '100%'; = '100%';; } // Creating the car car =; // We will enable physics for any object that is created in this group car.enableBody = true; // Designate the car sprite to the VAR car car = game.add.sprite(0 , 0, 'car'); car.anchor.set(0.5); car.scale.setTo(scaleRatio, scaleRatio); game.physics.arcade.enable(car); car.x =; car.y = - car.height; // car.body.collideWorldBounds = true; // car.checkWorldBounds = true; // car.body.bounce.setTo(car.x + w/3, 0); // OBSTACLES obstacleGroup =; obstacleGroup.enableBody = true; obstacleGroup.scale.setTo(scaleRatio, scaleRatio); This would be it from now. If you can pinpoint me to some articles that can help me with my car game or have any advices I would be happy to hear them. Thanks,
  20. How to smooth the tween animation in the android devices.
  21. Hey all, I'm using tween for my game in the android device it is too lacking and slowly working tween, then i tried with physics both too slow how to solve.
  22. How to detect if current window tab is not active in the phaser
  23. This is something I put together this afternoon for my students to play with. Live demo.
  24. Hello, Im making a game where you have to jump some cars, you only lose if you touch the left side of a car. the problem is when the character lands over a car both sprites overlap, and if another car comes behind you will collide with it instead of pass over it I'm using arcade physics. I'll let you a couple screenshoots of this. Is there some way to avoid this?
  25. How to make number tiles with colors for example: array[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; I need to show into these box