[英]How to draw board of sprites in Pixi.js?
我有10個精靈的數組並從
for (var i = 0; i < 35; i++) {
this.Map.push([]);
for (var j = 0; j < 30; j++)
this.Map[i][j] = (Math.random() * 9) | 0;
}
假設您要創建矩形地圖,可以嘗試以下操作:
for(var y = 0; y < this.Map.length; y++) {
for(var x = 0; x < this.Map[y].length; x++) {
var sprite = new PIXI.Sprite.fromImage('assets/image.png');
sprite.position.x = x* tileWidth;
sprite.position.y = y* tileHeight;
yourDisplayObjectContainer.addChild(sprite);
}
}
然后,當然,您必須啟動渲染器。 它應該會顯示您的地圖。
好的,我發現了一些東西。 唯一的好方法是使用drawImage將所需的板放到畫布上,然后:
var pixiTexture = PIXI.Texture.fromCanvas(canvas);
如果木板的尺寸太大,則將其分成幾塊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.