views:

33

answers:

1

Hey,

I have quite a big code here... But fortunately it is not needed to be mentioned at all. It comes down to something which... fails? So, in the end this is supposed to draw two triangles (using AS3 Graphics). It works fine with one, but when I put a second there, it looks weird. I trace debugged it, and I think the bug is in the Graphics - this is my output for the actual points drawn:

DRAW
- POINT ( 50 , -50 )
- POINT ( -50 , 50 )
- POINT ( 50 , 50 )
DRAW
- POINT ( -50 , -50 )
- POINT ( 50 , -50 )
- POINT ( -50 , 50 )

(x, y), two triangles. This would result in a square of one color (these triangles are one colored), or possibly a square split in half if I were to change the colors.

Would... It does not.

Instead, I get THIS:

alt text

OR (which is weird), when I switch the order in which the triangles are drawn: alt text

...

Any idea what is going on? I have read on another forum that functions beginFill and endFill are supposed to be called before and after drawing every shape - obviously that's what I did even before looking - the color won't be different elsehow. So - any idea?

EDIT:

The graphics calls look like this:

for (var vi:int = 0; vi < triangles.length; vi++){
    gfx.beginFill(0xFF0000, 0.5 + (0.5 * vi));
    trace("DRAW");
    trace("- POINT ( " + triangles[vi].points[0].x + " , " + triangles[vi].points[0].y + " )");
    trace("- POINT ( " + triangles[vi].points[1].x + " , " + triangles[vi].points[1].y + " )");
    trace("- POINT ( " + triangles[vi].points[2].x + " , " + triangles[vi].points[2].y + " )");
    gfx.lineTo(triangles[vi].points[0].x, triangles[vi].points[0].y);
    gfx.lineTo(triangles[vi].points[1].x, triangles[vi].points[1].y);
    gfx.lineTo(triangles[vi].points[2].x, triangles[vi].points[2].y);
    gfx.lineTo(triangles[vi].points[0].x, triangles[vi].points[0].y);
    gfx.endFill();
}
A: 

The first gfx.lineTo should be a gfx.moveTo.

Claus Wahlers
OH, now I get it. :D Forgot to call a moveTo before each triangle... This then results in a line FROM the last point of the previous triangle. Thanks anyway.
Aurel300