首页 > 解决方案 > 向场景添加补间但不立即播放

问题描述

我正在将补间添加到场景中scene.add.tween({config}),并且添加的补间会自动播放。我怎样才能防止这种情况?

    var config = {
        type: Phaser.AUTO,
        width: 800,
        height: 600,
        physics: {
            default: 'arcade',
            arcade: {
                gravity: { y: 200 }
            }
        },
        scene: {
            preload: preload,
            create: create
        }
    };

    var game = new Phaser.Game(config);

    function preload ()
    {
        this.load.setBaseURL('http://labs.phaser.io');

        this.load.image('logo', 'assets/sprites/phaser3-logo.png');
    }

    function create ()
    {
        var logo = this.add.image(config.width / 2, config.height / 2, 'logo');
        
        var tween_logo = this.add.tween({
          targets: logo,
          duration: 1000,
          scale: 2,
          ease: 'Linear',
          yoyo: true,
          repeat: -1
        });
        


    }
<script src="https://cdn.jsdelivr.net/gh/photonstorm/phaser@3.18.1/dist/phaser.min.js"></script>

标签: phaser-framework

解决方案


在您的补间配置中添加 paused 属性并将其设置为 true。

因此,您的补间配置将是:

var tween_logo = this.add.tween({
  targets: logo,
  duration: 1000,
  paused: true,
  scale: 2,
  ease: 'Linear',
  yoyo: true,
  repeat: -1
});

是配置文档的链接,以查看其他属性:


推荐阅读