大小和比例

widthheight属性来改变它的大小。这是怎么把width调整成80像素,height调整成120像素的例子:

  1. cat.width = 80;cat.height = 120;

setup函数里面加上这两行代码,像这样:

  1. function setup() { //Create the `cat` sprite let cat = new Sprite(resources["images/cat.png"].texture); //Change the sprite's position cat.x = 96; cat.y = 96; //Change the sprite's size cat.width = 80; cat.height = 120; //Add the cat to the stage so you can see it app.stage.addChild(cat);}

结果看起来是这样: 你能看见,这只猫的位置(左上角的位置)没有改变,只有宽度和高度改变了。 scale.xscale.y属性,他们可以成比例的改变精灵的宽高。这里的例子把猫的大小变成了一半:

  1. cat.scale.x = 0.5;cat.scale.y = 0.5;

Scale的值是从0到1之间的数字的时候,代表了它对于原来精灵大小的百分比。1意味着100%(原来的大小),所以0.5意味着50%(一半大小)。你可以把这个值改为2,这就意味着让精灵的大小成倍增长。像这样:

  1. cat.scale.x = 2;cat.scale.y = 2;

scale.set方法。

  1. cat.scale.set(0.5, 0.5);

如果你喜欢这种,就用吧!