This site requires JavaScript, please enable it in your browser!
Greenfoot back
kitkatsxp
kitkatsxp wrote ...

2015/11/7

How do I make a loop to draw triangles at different (not random) places

kitkatsxp kitkatsxp

2015/11/7

#
I'm trying to make mountains for the project i'm working on, but i'm stuck. I know how to make triangles and fill them and what not, but I need 4 triangles and they have to be the same, but i need them in different places along the bottom on the world, and I need to use a loop. I know that I have to do something to change the xvalues of the triangle, but i'm lost/confused with the technical part of that.
danpost danpost

2015/11/7

#
kitkatsxp wrote...
I know that I have to do something to change the xvalues of the triangle, but i'm lost
It is not the x values of the triangle, but the x values of where the triangles are drawn onto your world background. There are two main values of importance here -- the x value for where the left-most triangle is drawn at (call it 'x0') and the distance between where each triangle is drawn (call it 'xOffset'). If the iterator is 'i' and counts from zero to less than four, then the x values would compute to:
int xToDrawAt = x0 + i * xOffset;
You need to login to post a reply.