Domanda

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?

È stato utile?

Soluzione

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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top