We can create a rectangle at (0,0) and height and width of 40 with mySprite.graphics.drawRect(0,0,40,40);. However, suppose it is necessary to create a rectangle that fills exactly half the screen (this is for mobile devices, so screen size will vary). How can we accomplish this?

有帮助吗?

解决方案

You first need to get the size of the screen, you can use this :

var w = stage.stageWidth;
var h = stage.stageHeight;

Then you can simply draw your rect using theses variables

mySprite.graphics.drawRect(0, 0, w / 2, h / 2);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top