我正在尝试从随机生成的矩阵中绘制代表我的级别的小地图。
为此,我逐一绘制黑色或白色的小方块来直观地表示矩阵(我不知道这是否是使用移相器实现这一点的最佳方法,实际上,我是这个框架的初学者)。
地图绘制正确,但它的位置绑定到世界而不是相机,所以当我移动时它不再可见。
这是我用来绘制地图的代码:
generate() {
let wallsGraphics = this._scene.add.graphics({fillStyle : {color : LabyrinthConfig.MAPS.MINI_MAP.WALLS_COLOR}});
let pathGraphics = this._scene.add.graphics({fillStyle : {color : LabyrinthConfig.MAPS.MINI_MAP.PATH_COLOR}});
// Draw the map
let y = 0;
for (let line of this._matrix) {
let x = 0;
for (let cell of line) {
let rect = new Phaser.Geom.Rectangle();
rect.width = LabyrinthConfig.MAPS.MINI_MAP.CELL_WIDTH;
rect.height = LabyrinthConfig.MAPS.MINI_MAP.CELL_HEIGHT;
rect.x = LabyrinthConfig.MAPS.MINI_MAP.POSITION_X + x * LabyrinthConfig.MAPS.MINI_MAP.CELL_WIDTH;
rect.y = LabyrinthConfig.MAPS.MINI_MAP.POSITION_Y + y * LabyrinthConfig.MAPS.MINI_MAP.CELL_HEIGHT;
cell === 0 ? wallsGraphics.fillRectShape(rect) : pathGraphics.fillRectShape(rect);
x++;
} …Run Code Online (Sandbox Code Playgroud) 我正在使用 Phaser.io
我刚刚学会了如何设置碰撞器功能:
this.physics.add.collider(enemies, platforms, function (enemy) {
enemy.destroy();
gameState.score += 10;
});
Run Code Online (Sandbox Code Playgroud)
但我想在没有平台的情况下做同样的事情。我想使用世界边界而不是平台。
我知道你可以这样设置世界边界:
player.setCollideWorldBounds(true);
Run Code Online (Sandbox Code Playgroud)
我试过了:
this.physics.add.collider(enemies, this.worldBounds, function (enemy) {
enemy.destroy();
gameState.score += 10;
});
Run Code Online (Sandbox Code Playgroud)
但这行不通。
有任何想法吗?
我正在按照本教程使用 Phtomstorm 的样板构建多场景游戏模板。我在 GameScene.js 的 preload() 函数中添加的徽标图像收到 404 错误。我觉得我已经按照 T 的说明进行操作,但可能没有正确暴露 webpack 中的资源,因为我是这个工具的新手。
\n我在让这个 logo.png 显示在屏幕上时做错了什么?
\n教程 - https://phasertutorials.com/creating-a-phaser-3-template-part-1/
\n项目模板 - https://github.com/photonstorm/phaser3-project-template.git
\n索引.js
\nimport Phaser from "phaser";\nimport config from \'./Config/config\';\nimport GameScene from \'./Scenes/GameScene\';\n \nclass Game extends Phaser.Game {\n constructor () {\n super(config);\n this.scene.add(\'Game\', GameScene);\n this.scene.start(\'Game\');\n }\n}\n \nwindow.game = new Game();\nRun Code Online (Sandbox Code Playgroud)\n配置文件
\nimport \'phaser\';\n \nexport default {\n type: Phaser.AUTO,\n parent: \'phaser-example\',\n width: 800,\n height: 600\n};\nRun Code Online (Sandbox Code Playgroud)\n游戏场景.js
\nimport \'phaser\';\n \nexport default class GameScene …Run Code Online (Sandbox Code Playgroud) 在过去的几天里,我一直无法让移相器工作:只是试着测试一个hello world程序.我完全遵循了phaser网站上的指示,但它仍然不适合我.
我正在使用node.js.
这是index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Hello World</title>
<style>
#game_div {
width: 500px;
margin: auto;
margin-top: 50px;
}
</style>
<script type="text/javascript" src="phaser.min.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>
<body>
<div id="game_div"> </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是main.js:
/*jslint node: true */
"use strict";
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');
var main_state = {
preload: function () {
game.load.image('hello', 'assets/hello.png');
},
create: function () {
this.hello_sprite = game.add.sprite(200, 245, 'hello');
},
update: function () {
this.hello_sprite.angle += 1; …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个基于lessmilk.com的Flappy Bird教程的单一输入的简单游戏.在键盘上你可以通过空间来跳跃,但是在启用触控功能的设备上,我想让用户触摸画布上的任何地方进行跳跃.
查看输入文档,似乎可以直接捕获精灵的触摸输入,但我希望用户能够在任何地方单击/触摸.
什么是捕捉所有触摸事件的"Phaser方式"?我是否需要做一些hacky,比如创建一个覆盖整个画布的隐形精灵?我应该绕过移相器并只附加DOM事件处理程序吗?
我刚刚开始使用Phaser制作一个简单的平台游戏,这是我的新手。
我设法播放音乐,但无法播放,Google也没有帮助。
这是我正在使用的音频代码,有什么建议吗?
game.load.audio('hotttt', ['assets/audio/hotttt.mp3', 'assets/audio/hotttt.ogg']);
music = game.add.audio('hotttt');
music.play();
Run Code Online (Sandbox Code Playgroud) 我有一clouds组会产生两个云.每隔10秒我就要杀死那些云,并产生两个以上的云.你可以一次杀死一个组的所有元素吗?
var clouds;
var start = new Date();
var count = 0;
function preload(){
game.load.image('cloud', 'assets/cloud.png');
}
function create(){
clouds = game.add.group();
}
function update(){
if(count < 10){
createCloud();
}
}
function createCloud(){
var elapsed = new Date() - start;
if(elapsed > 10000){
var locationCount = 0;
//Here is where I'm pretty sure I need to
//kill all entities in the cloud group here before I make new clouds
while(locationCount < 2){
//for the example let's say I …Run Code Online (Sandbox Code Playgroud) 我在更新子画面时遇到问题。
我创建了一个换衣服的功能。它应该像这样工作:
// Something like this.
pet = pet_with_hat
Run Code Online (Sandbox Code Playgroud)
https://github.com/futer/pandachii上有代码js / main.js的387行。
当我写这个:
this.pet = this.game.add.sprite(90,90, 'pet_black_hat')
Run Code Online (Sandbox Code Playgroud)
发生错误:
Uncaught TypeError:无法读取未定义的属性“运行状况” GameState.update @ main.js:194 Phaser.StateManager.update @ phaser.js:16628 Phaser.Game.update @ phaser.js:23092 Phaser.RequestAnimationFrame.updateRAF @ phaser.js:41421 _onLoop @ phaser.js:41407
如何将此宠物的精灵图像更改为另一个?
我会很感激。
我正在使用移相器制作游戏.我正在加载背景图像,其信息(文件位置)存储在JSON文件中.当我尝试加载它时,背景是黑色和空的,在控制台中我得到:
Phaser.Cache.getImage:在Cache中找不到键"background0".
以下是我的代码中的相关摘录:
function create() {
//>Load JSON file and background images found inside the file
$.getJSON("levels.json", function(json) {
for (var i = 0; i < json.levels.length; i++) {
game.load.image('background' + i.toString(), json.levels[i].background);
}
game.load.start();
});
back_layer = game.add.group();
var i = 0;
var level_finished = 0;
$.getJSON("levels.json", function(json) {
if (i < json.levels.length) {
console.log("Level " + (i + 1).toString());
var current_background = back_layer.create(0, 0, 'background' + i.toString());
check = setInterval(function() {
if (level_finished == 1) {
i++;
current_background.destroy(); …Run Code Online (Sandbox Code Playgroud) phaser-framework ×10
javascript ×7
audio ×1
babeljs ×1
game-physics ×1
html5 ×1
html5-canvas ×1
node.js ×1
webpack ×1