为什么我在使用PixiJS时,stage.heightwidth是0?

问题描述 投票:0回答:1

在函数设置中,app.stage.height的值是0,为什么?validator(zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz)有一段文字

       let Application = PIXI.Application,
            Container = PIXI.Container,
            loader = PIXI.loader,
            resources = PIXI.loader.resources,
            TextureCache = PIXI.utils.TextureCache,
            Sprite = PIXI.Sprite,
            Rectangle = PIXI.Rectangle;

        let app = new Application({ 
            width: 512, 
            height: 512,                       
            antialias: true, 
            transparent: false, 
            resolution: 1
          }
        );

        document.body.appendChild(app.view);

        loader
          .add("/img/treasureHunter.json")
          .load(setup);

        function setup() {
          console.log(app.stage.height)

          let id = PIXI.loader.resources["/img/treasureHunter.json"].textures;
          let dungeon = new Sprite(id["dungeon.png"])
          let treasure = new Sprite(id["treasure.png"]);
          let explorer = new Sprite(id["explorer.png"]);
          explorer.y = app.stage.height / 2 - explorer.height / 2;
          console.log(app.stage.height)
          explorer.x = 68;


          app.stage.addChild(dungeon);
          app.stage.addChild(explorer);
          app.stage.addChild(treasure);
        }
pixi.js
1个回答
0
投票

舞台是一个Container,它的高度总是由它的子代计算的。在你没有给舞台添加任何子代之前,它的高度将为零。

另外,舞台的高度不等于画布的高度。renderer.view 高度。

© www.soinside.com 2019 - 2024. All rights reserved.