We will assume that
you know how to import Minueto into your project and how to
create a MinuetoWindow
.
If this is not the case, please read How
to build your first game
Window?.
To draw a line on a MinuetoWindow
, you need to call the drawLine
method.
window.drawLine(MinuetoColor.RED, 0, 0, 200, 200);
This will draw a red line from (0,0) to (200,200).
Unfortunately, drawing a line is an expensive operation, much slower
than drawing an image. If you wish to repetitively draw the same line,
it might be wise to cache the lines. To do this, you build build an empty
MinuetoImage
and draw your lines
over this transparent surface.
You can then draw this "image of the lines" on the MinuetoWindow
without any performance cost.
The following code would create a 50 by 50 image containing a red X.
MinuetoImage redX; redX = new MinuetoImage(50,50); redX.drawLine(MinuetoColor.RED, 0, 0, 49, 49); redX.drawLine(MinuetoColor.RED, 0, 49, 49, 0);
To better illustrate how to cache your line draws, here is an example
of an application that caches drawLine
operations.
import org.minueto.*; import org.minueto.handlers.*; import org.minueto.image.*; import org.minueto.window.*; public class Demo { public static void main(String[] args) { MinuetoWindow window; MinuetoImage redX; window = new MinuetoFrame(640, 480, true); redX = new MinuetoImage(50,50); redX.drawLine(MinuetoColor.RED, 0, 0, 49, 49); redX.drawLine(MinuetoColor.RED, 0, 49, 49, 0); window.setVisible(true); while(true) { window.draw(redX, 10, 10); window.render(); Thread.yield(); } } }