將小精靈放置在特定的位置
function setup() {
var cat = new Sprite(resources["images/cat.png"].texture);
// 改變小精靈對象 cat 的 x,y 坐標(biāo)
cat.x = 96;
cat.y = 96;
stage.addChild(cat);
renderer.render(stage);
}
值得注意的是,小精靈的 x,y 兩個坐標(biāo)指的是圖片左上角的點的坐標(biāo),而不是圖片中心的坐標(biāo)
拉伸小精靈
function setup() {
var cat = new Sprite(resources["images/cat.png"].texture);
// 改變小精靈對象 cat 的 x,y 坐標(biāo)
cat.x = 96;
cat.y = 96;
// 改變小精靈的寬高
cat.width = 100;
cat.height = 200;
stage.addChild(cat);
renderer.render(stage);
}
另一種方法
sprite.scale.set(0.5, 0.5) // 寬高變?yōu)樵瓉淼囊话?
旋轉(zhuǎn)小精靈
cat.rotation = 0.5 // 以正上方為起點,圖片左上角為旋轉(zhuǎn)中心,順時針轉(zhuǎn)動 0.5 弧度
設(shè)置旋轉(zhuǎn)中心為圖片中心,此時小精靈的 x,y 坐標(biāo)也變?yōu)閳D片的中心的坐標(biāo)
sprite.anchor.set(x, y);