Completely empty Tilemaps can now be created. This allows for dynamic map generation at runtime.

Loads of updates across most the Tilemap files. Not finished yet, still CSV loading to do and a multi-tileset issue to resolve, but it's a lot more flexible now.
This commit is contained in:
photonstorm
2014-03-03 05:19:46 +00:00
parent 6f513042c1
commit d8f5832fa2
12 changed files with 396 additions and 85 deletions
+22 -2
View File
@@ -13,6 +13,7 @@ var layer;
var marker;
var currentTile;
var cursors;
function create() {
@@ -30,6 +31,8 @@ function create() {
marker.lineStyle(2, 0x000000, 1);
marker.drawRect(0, 0, 32, 32);
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
@@ -52,11 +55,28 @@ function update() {
}
}
if (cursors.left.isDown)
{
game.camera.x -= 4;
}
else if (cursors.right.isDown)
{
game.camera.x += 4;
}
if (cursors.up.isDown)
{
game.camera.y -= 4;
}
else if (cursors.down.isDown)
{
game.camera.y += 4;
}
}
function render() {
game.debug.text('Left-click to paint. Shift + Left-click to select tile.', 32, 32, 'rgb(0,0,0)');
game.debug.text('Tile: ' + map.getTile(layer.getTileX(marker.x), layer.getTileY(marker.y)), 32, 48, 'rgb(0,0,0)');
game.debug.text('Left-click to paint. Shift + Left-click to select tile. Arrows to scroll.', 32, 32, '#efefef');
}
+68
View File
@@ -0,0 +1,68 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
// var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('ground_1x1', 'assets/tilemaps/tiles/ground_1x1.png');
}
var map;
var tileset;
var layer;
var cursors;
function create() {
game.stage.backgroundColor = '#787878';
// Creates a blank tilemap
map = game.add.tilemap();
// Creates a layer and sets-up the map dimensions.
// In this case the map is 30x30 tiles in size and the tiles are 32x32 pixels in size.
map.create('level1', 30, 30, 32, 32);
// Add a Tileset image to the map
map.addTilesetImage('ground_1x1');
map.putTile(4, 1, 1)
map.putTile(10, 2, 1)
map.putTile(10, 3, 1)
map.putTile(10, 4, 1)
// Create a layer. This is where the map is rendered to.
layer = map.createLayer('level1');
// layer.resizeWorld();
// map.setCollisionBetween(1, 12);
// layer.debug = true;
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
if (cursors.left.isDown)
{
}
else if (cursors.right.isDown)
{
}
if (cursors.up.isDown)
{
}
else if (cursors.down.isDown)
{
}
}
function render() {
game.debug.cameraInfo(game.camera, 32, 32);
}
+39
View File
@@ -0,0 +1,39 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
}
var mummy;
function create() {
game.stage.backgroundColor = 0x3d4d3d;
mummy = game.add.sprite(300, 300, 'mummy', 5);
var t = game.add.tween(mummy).to( { "x": 400, "y": 400 }, 5000, Phaser.Easing.Linear.None, true);
// var t = game.add.tween(mummy).to( { "scale.x": 4, "scale.y": 4 }, 5000, Phaser.Easing.Linear.None, true);
t.onComplete.add(tweenOver, this);
}
function tweenOver(a) {
console.log('over');
console.log(a);
}
function update() {
}
function render() {
}