Question

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?

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top