小编Rob*_*ith的帖子

如何在 Phaser 3 中正确更新我的乐谱文本?

score在射箭游戏中更新了变量。但是,我无法正确更新分数。每次更新时,新文本都会粘贴到旧文本上。

getMedal()我在函数内部、函数外部getMedal()、函数内部都尝试过render()

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8" />
    <title>Video Game</title>
    <script src="//cdn.jsdelivr.net/npm/phaser@3.11.0/dist/phaser.js"></script>
    <style type="text/css">
        body {
            margin: 0;
        }
    </style>
</head>
<body>

<script type="text/javascript">
    //Configurations for the physics engine
    var physicsConfig = {
        default: 'arcade',
        arcade: {
            debug: false //CHANGE THIS TO TRUE TO SEE LINES
        }
    }
    //Configurations for the game itself
    var config = {
        type: Phaser.AUTO,
        width: 800,
        height: 600,
        physics: physicsConfig,
        scene: {
            preload: preload,
            create: create, …
Run Code Online (Sandbox Code Playgroud)

javascript game-engine phaser-framework

6
推荐指数
1
解决办法
4255
查看次数

Phaser 3 中特定动画完成时的回调?

我正在使用 Phaser 3 框架创建一个游戏,它有很多动画。在我的代码中,我已经有一个在播放任何动画后播放(或恢复)的动画,这很好。它的代码是

 //This keeps the rolling animation going once the push animation is done
    skater.on('animationcomplete', () => {
        skater.anims.play('roll');
    });
Run Code Online (Sandbox Code Playgroud)

但对于游戏的其余部分,我需要在相应的动画完成后执行特定的操作。是否有类似于上面的函数,我可以在其中传递动画的键或名称作为参数?

我目前在 Phaser 3 讨论板上看到的这个例子。这一切都在create()函数中。

    //Animation key
    const shuvKey = 'shuv'
    //Shuvit animation
    var shuvFrameNames = this.anims.generateFrameNames(
        'sheet', {start: 9, end: 12, zeroPad: 4,
        prefix: 'shuv/'}
    );
    this.anims.create({
        key: shuvKey, frames: shuvFrameNames, frameRate: 32, repeat: 0 
    });
    skater.once(game.Animations.Events.SPRITE_ANIMATION_KEY_COMPLETE + shuvKey, function(animation, frame) {
        score += 3;         
        }, this);
Run Code Online (Sandbox Code Playgroud)

但我得到“未捕获的类型错误:无法读取未定义的属性‘事件’”。我不确定这是否与我的游戏配置有关,所以我将在下面发布。

配置

//Configurations for the physics engine
var …
Run Code Online (Sandbox Code Playgroud)

javascript animation phaser-framework

6
推荐指数
1
解决办法
5772
查看次数

如何停止 Phaser 游戏并将其从页面中删除?

我有一个网页,我希望能够连续运行三个 JavaScript 游戏。我开始一个

//jQuery to start a game
$(document).ready(() => {
  //When the logo image is clicked
  $("#logo").click(() => {
    //Get the archery game
    $.getScript('archery.js', () => {
      //Start it
      startArchGame();
      //Remove the image from the HTML doc
      $("#logo").remove();
    });
  })
})
Run Code Online (Sandbox Code Playgroud)

然后,在内部archery.js,一旦满足条件,就会执行以下代码

$.getScript('skateboarding.js', () => {
  startSkateGame();
});
game.destroy();
Run Code Online (Sandbox Code Playgroud)

game.destroy();会阻止游戏在 Phaser 3 中运行,但下一个游戏只是在第一个游戏下方加载,因此您看不到它。我怎样才能解决这个问题?是否可以完全删除我得到的第一个脚本?

javascript jquery phaser-framework

3
推荐指数
1
解决办法
2761
查看次数