使用移相器热到中心矩形?
Hot to center rectangle using phaser?
这是我将图像精灵居中时的设置:
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);
结果:
如何使用位图数据创建和居中矩形?
谢谢
解决办法是把
drawnObject.x = game.world.centerX;
drawnObject.y = game.world.centerY;
在调整大小功能中
这是我将图像精灵居中时的设置:
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);
结果:
如何使用位图数据创建和居中矩形?
谢谢
解决办法是把
drawnObject.x = game.world.centerX;
drawnObject.y = game.world.centerY;
在调整大小功能中