当我以图片精灵为中心时,这是我的设置:
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { init: init, preload: preload, create: create, update: update, resize: resize });
function init() {
game.scale.scaleMode = Phaser.ScaleManager.RESIZE;
game.stage.backgroundColor = '#5b0c26';
}
function create() {
pic = game.add.sprite(game.world.centerX, game.world.centerY, 'imagerectangle');
pic.anchor.set(0.5);
}
它正在工作,图像矩形居中,但当我尝试使用位图数据创建矩形时,它不是。
这是代码:
function create() {
var graphics = game.add.graphics(game.world.centerX, game.world.centerY);
graphics.lineStyle(2, 0x0000FF, 1);
graphics.drawRect(0, 0, 100, 100);
graphics.anchor.set(0.5);
graphics.x = game.world.centerX;
graphics.y = game.world.centerY;
}
试过我在某个论坛上发现的这个例子,也没有用:
var drawnObject;
var width = 100 // example;
var height = 100 // example;
var bmd = game.add.bitmapData(width, height);
bmd.ctx.beginPath();
bmd.ctx.rect(0, 0, width, height);
bmd.ctx.fillStyle = '#ffffff';
bmd.ctx.fill();
drawnObject = game.add.sprite(game.world.centerX, game.world.centerY, bmd);
drawnObject.anchor.setTo(0.5, 0.5);
如何使用位图数据创建和居中矩形?
谢谢
答案 0 :(得分:0)
解决方案是放
drawnObject.x = game.world.centerX;
drawnObject.y = game.world.centerY;
调整大小功能