I want to draw a rect with a 50x50 size, however I want it to appear randomly on the x position. Where should i set the x position?

This is how i set my rectangle.

rectangle.set(50, 50, 100, 100);

I've done several changes on this setting the but I can't figure it out.

  • \$\begingroup\$ generate a random number, assign that number to x and pass x to rectange.set \$\endgroup\$
    – Lynob
    Feb 5, 2017 at 15:44

1 Answer 1


You need to do the following:

rectangle.set(randomX, 50, randomX + 50, 100);

Where randomX is the random value.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .