BattleCity game using Phaser.IO, part 4 – simple collision.

In the last part we created moving player tank in our city, but it can move anywhere through the walls without any collision. So in this part we will investigate hwo to enable collision detection between our player tank and city walls. Also we will enable and outputt some debugging information to better understand what exactly happens on our map. To enable collision between our tank and walls/city  we have to enable collision for tiles ( now we will just enable collision for all tiles of our tile set ). In  create function, after add tileset, add: [code lang="js" htmlscript="true"]map.setCollisionBetween(1, 10000);[/code] Also we have to enable player tank physics, in create function, after game add sprite, we add: [code lang="js" htmlscript="true"] game.physics.enable(player_tank); player_tank.body.collideWorldBounds = true; [/code] In update function we add collision check of player vs layer: [code lang="js" htmlscript="true"] game.physics.arcade.collide(player_tank, layer); [/code] One note: after doing all this, collision still was not working. I found that it was realated to scaling. You should change layer.scale.set(2); to layer.setScale(); and it is fixed. Debugging collision. To see collision rectangles you could add [code lang="js" htmlscript="true"] layer.debug = true; [/code] after layer creation and also add a render callback function (in…


BattleCity game using Phaser.IO, part 3 – using Visual Studio Code.

This will be a little go back to setting up development environment. I have noticed that in some networks is blocked by network providers firewall, that complicates developing using Cloud9 - you will net be able to preview your project. Another good tool you could use is Visual Studio Code. Download the tool, install it. As we already have our project in github, just select Clone Git repository, enter your repository url and credentials and that is it. To have a quick way of previewing of our project without moving to server you can go to Extensions, search for Live Server Extension. By pressing Go Live you will be able to quickly host your files and preview locally. Visual Studio Code has nice source control integration so you will be able to view your changes and commit and push them from UI.  


BattleCity game using Phaser.IO, part 2 – move it!

In this part we will create our player tank, add animation of our moving tank (moving left, right etc) and perform actual tank movement on pressing of corresponding cursor keys. In preload function we should load our spritesheet. Actually it is the same image as we used for tilesheet and same spritesheet will be used for our player and enemy tank sprites and animations. [code lang="js" htmlscript="true"] // load spritesheet for our player and enemies, all of them use same spritesheet game.load.spritesheet('tanks', 'assets/tilemaps/tiles/battlecity_general.png', 16, 16); [/code] Next we should declare some new variables, one for our player tanks and one for cursor keys. [code lang="js"] var player_tank; var cursors; [/code] In a create function we will create our player tank, define animations for our player tank movements. Also here we will create object responsible for reading cursor keys. Enable our player tank physics, set scale of our player tank sprites. [code lang="js"] //create cursor key handler cursors = game.input.keyboard.createCursorKeys(); //create our player tank, position it at x,y and use sprite sheet 'tanks' player_tank =, 448, 'tanks'); //enable physics for our player sprite so we could move it etc game.physics.arcade.enable(player_tank); //set initial frame for our player sprite player_tank.frame =…


Creating a BattleCity game using Phaser.IO, part 1

I was never a huge fan of JavaScript and I am no way front-end developer, but I like some ideas from that technology and now with dying Flash - it is definitely the future. So in this post series, I will be making famous Nintendo (NES) Battlecity game clone using Phaser.IO, just for fun, to see how it works. To make it I decided to use some online development environment, Github for source control and .. yes that is basically all that one will need. Setting up a development environment. For a development environment, i have decided to code everything online using Cloud9 and Github. First login or create your Github account. Then create a new repository. Then you have to register for the Coud9 account and create workspace there. When creating workspace select Html5 and provide your Github repository URL in "Clone from Git.." field. Also, go to Cloud9 settings, select SSH Keys, copy your key and then go to Github->Settings->SSH and..., press New SSH key, name it something like C9 and then paste your key and press Add SSH key. Setting up project workspace. In Cloud9 workspace of your project create folders: assets->tilemaps->maps assets->tilemaps->tiles js Create empty index.html…


End of content

No more pages to load