[]求问sprite放大后,graphics绘制的图像位置偏移
let sprite: Sprite = new Sprite();比如我在一个sprite的中心画一个圆,用scale放大后,圆偏离中心。
let texture: Laya.Texture = Laya.loader.getRes(this.skin_img1);
sprite.graphics.drawTexture(texture, 0, 0, texture.width, texture.height);
sprite.size(texture.width, texture.height);
let x: number = 300;
let y: number = 100;
let scaleRatio: number = 1.3;
sprite.pos(x, y);
// sprite.graphics.drawCircle(texture.width/2, texture.height/2, 10, "#fff333"); //位置偏移
sprite.graphics.drawCircle(texture.width/2 - x/scaleRatio, texture.height/2 - y/scaleRatio, 10, "#fff333"); //位置正确
sprite.scale(scaleRatio, scaleRatio);
Laya.stage.addChild(sprite);
console.log(sprite.width);
console.log(sprite.height);
必须在原位置减去位置除以缩放比才能达到想要的效果。
3 个回复
cuixueying
赞同来自:
cuixueying
赞同来自:
sun9278888
赞同来自: