Added isometric tiles and scene

This commit is contained in:
2024-04-09 02:20:34 +02:00
parent c717ae64cc
commit 3fcd3e575e
6 changed files with 100 additions and 2 deletions

View File

@ -1,8 +1,26 @@
<script setup lang="ts">
import Phaser from 'phaser';
import { Game, Scene, Rectangle } from 'phavuer'
import Example from './scenes/mapScene'
const gameConfig = {
width: '100%',
height: '100%',
pixelArt: true,
type: Phaser.AUTO,
scene: Example
}
// isometric
</script>
<template>
<Game :config="gameConfig">
<Scene name="MainScene">
<Rectangle :x="100" :y="100" :width="100" :height="100" :fillColor="0xAAAAAA" />
</Scene>
</Game>
</template>
<style scoped>

51
src/scenes/mapScene.js Normal file
View File

@ -0,0 +1,51 @@
import Phaser from 'phaser';
class Example extends Phaser.Scene
{
constructor () {
super();
}
preload () {
this.load.image('tiles', '/assets/tilesets/iso-64x64-outside.png');
}
create () {
const mapData = new Phaser.Tilemaps.MapData({
width: 10,
height: 10,
tileWidth: 64,
tileHeight: 32,
orientation: Phaser.Tilemaps.Orientation.ISOMETRIC,
format: Phaser.Tilemaps.Formats.ARRAY_2D
});
const map = new Phaser.Tilemaps.Tilemap(this, mapData);
const tileset = map.addTilesetImage('iso-64x64-outside', 'tiles');
const layer = map.createBlankLayer('layer', tileset, 350, 200);
const data = [
[ 10, 11, 12, 13, 14, 15, 16, 10, 11, 12 ],
[ 13, 11, 10, 12, 12, 15, 16, 10, 16, 10 ],
[ 12, 10, 16, 13, 14, 15, 16, 16, 13, 12 ],
[ 10, 11, 12, 13, 14, 15, 16, 10, 11, 12 ],
[ 13, 11, 10, 12, 12, 15, 16, 10, 16, 10 ],
[ 12, 10, 16, 13, 14, 15, 16, 16, 13, 12 ],
[ 10, 11, 12, 13, 14, 15, 16, 10, 11, 12 ],
[ 13, 11, 10, 12, 12, 15, 16, 10, 16, 10 ],
[ 12, 10, 16, 13, 14, 15, 16, 16, 13, 12 ],
[ 10, 11, 12, 13, 14, 15, 16, 10, 11, 12 ]
];
let y = 0;
data.forEach(row => {
row.forEach((tile, x) => {
layer.putTileAt(tile, x, y);
});
y++;
});
}
}
export default Example;