notes/Phaser basic tile map jumper with collision-DUMcctGA.sh
var game = new Phaser.Game(480, 320, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update});
function preload() {
game.load.tilemap('map', 'level.csv', null, Phaser.Tilemap.CSV);
game.load.image('tiles', 'tiles64.png');
game.load.image('player', 'player.png');
}
var map;
var layer;
var cursors;
var player;
function create() {
// Because we're loading CSV map data we have to specify the tile size here or we can't render it
map = game.add.tilemap('map', 32, 32);
// Now add in the tileset
map.addTilesetImage('tiles');
map.setCollisionBetween(3, 4);
// Create our layer
layer = map.createLayer(0);
// Resize the world
layer.resizeWorld();
// Player
player = game.add.sprite(32,32,"player");
player.scale.setTo(.5,.5);
game.physics.enable(player, Phaser.Physics.ARCADE);
game.camera.follow(player);
game.physics.arcade.gravity.y = 200;
//keep player on screen
//player.body.collideWorldBounds=true;
//enable keyboard input
cursors = game.input.keyboard.createCursorKeys();
//fullscreen on click
game.input.onDown.add(go_fullscreen, this);
}
function update() {
game.physics.arcade.collide(player, layer);
playerControls();
}
function playerControls(){
if (cursors.up.isDown && player.body.blocked.down)
{
player.body.velocity.y = -300;
}
else if (cursors.down.isDown)
{
//player.body.velocity.y = 550;
}
if (cursors.left.isDown)
{
player.body.velocity.x = -150;
}
else if (cursors.right.isDown)
{
player.body.velocity.x = 150;
}else{
player.body.velocity.x = 0
}
}
function go_fullscreen(){
game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL;
game.scale.startFullScreen();
}