簡體   English   中英

移相器和Web音頻API-定向精靈

[英]Phaser and Web Audio API - orientate sprite

我正在嘗試將相位器與網絡音頻API結合使用,但無法弄清楚如何將子圖形x,y,z和旋轉值轉換為方向矢量和向上矢量。 我該怎么做?

 ctx.setPosition(sprite.x, sprite.y, sprite.z); ctx.setOrientation(0,0,0,0,0,0); ctx.setVelocity(0, 0, 0); 

我很確定我已經解決了,這是代碼:

function updateWithSprite(sprite)
    if (sprite.body) {
        var rot = sprite.body.rotation + Math.PI / 2;
        this.setPosition(sprite.body.x, body.y, 0);
        this.setOrientation(Math.cos(rot), Math.sin(rot), 0);
        this.setVelocity(sprite.body.velocity.x, sprite.body.velocity.y, sprite.body.velocity.z);
    } else {
        var rot = sprite.rotation + Math.PI / 2;
        this.setPosition(sprite.x, sprite.y, 0);
        this.setOrientation(Math.cos(rot), Math.sin(rot), 0);
        this.setVelocity(0, 0, 0);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM