문제

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