主页 > canvas引擎 > Phaser游戏引擎 >
来源:未知 时间:2023-10-26 10:13 作者:小飞侠 阅读:次
[导读] phaser3相机代码demo讲解 这是相机所看到区域 这是全画布区域预览 代码讲解: classExampleextendsPhaser.Scene{constructor(){super();}preload(){//开始加装资源大图this.load.image(map,assets/tests/camera/earthbo...
|
phaser3相机代码demo讲解 这是相机所看到区域
这是全画布区域预览
代码讲解: class Example extends Phaser.Scene
{
constructor ()
{
super();
}
preload ()
{
// 开始加装资源大图
this.load.image('map', 'assets/tests/camera/earthbound-scarab.png');
}
create ()
{
// 设置相机边界,[x,y,width,height,centerOn是否以相机为中心点(boolean)]
this.cameras.main.setBounds(0, 0, 1024, 2048);
// 添加地图图片到画布
this.add.image(0, 0, 'map').setOrigin(0);
// 设置当前相机区域映射到画布的缩放比例
this.cameras.main.setZoom(4);
// 相机默认区域,0,0表示左上角
this.cameras.main.centerOn(0, 0);
// 添加一些文本到画布
const text = this.add.text(304, 230).setText('Click to move').setScrollFactor(0);
text.setShadow(1, 1, '#000000', 2);
let pos = 0;
// 绑定画布点击事件,然后挪动相机显示区域坐标x,y
this.input.on('pointerdown', function () {
const cam = this.cameras.main;
if (pos === 0)
{
cam.centerOn(767, 1096);
pos++;
}
else if (pos === 1)
{
cam.centerOn(703, 1621);
pos++;
}
else if (pos === 2)
{
cam.centerOn(256, 623);
pos++;
}
else if (pos === 3)
{
cam.centerOn(166, 304);
pos++;
}
else if (pos === 4)
{
cam.centerOn(624, 158);
pos++;
}
else if (pos === 5)
{
cam.centerOn(680, 330);
pos++;
}
else if (pos === 6)
{
cam.centerOn(748, 488);
pos++;
}
else if (pos === 7)
{
cam.centerOn(1003, 1719);
pos = 0;
}
text.setText(['Click to move', 'x: ' + cam.scrollX, 'y: ' + cam.scrollY ]);
}, this);
}
}
const config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 800,
height: 600,
pixelArt: true,
physics: {
default: 'arcade',
},
scene: Example
};
const game = new Phaser.Game(config);以上就是phaser3相机代码demo讲解全部内容,感谢大家支持自学php网。 |
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com