Creating a MinuetoWindow
is a
fairly simple process. Your first task is to import
Minueto into your project. You will need to do this for every one of
your Minueto project.
import org.minueto.*; import org.minueto.handlers.*; import org.minueto.image.*; import org.minueto.window.*;
Once you have imported the Minueto package, you can create your MinuetoWindow
of the
desired height and width. You can also specify if
you want the window to have borders.
MinuetoWindow window; window = new MinuetoFrame(640, 480, true);
A MinuetoWindow
starts off
invisible. You need to explicitly make the
window visible once you are ready to display it.
window.setVisible(true);
The following commands will display a 640x480 window in windowed mode. Although most games run in full screen mode, it is much easier to develop (and debug) a game using windowed mode. We recommend you use windowed to build your game. You can easily switch the final product to full screen by using a MinuetoFullscreen window instead.
The last thing we need to set up is a drawing loop to
continuously update our window. Minueto draws to the screen using a
double-buffering strategy. In other words, there are two drawing
surfaces: your window itself and an off screen surface. All your
drawing occurs on the off screen surface. The content of the off screen
buffer is drawn to the screen when the render
method is called.
You might wonder why we bother with the off screen surface. Think of an artist making a painting. It is a lengthy process and the artist will on want to show the result once the painting is complete. The same situation occurs with computers and games. On average, your monitor refreshes its content 60 times a second. If the monitor updates itself before we finish drawing our frame, we will get an incoherent frame, often called image tearing. To avoid this problem, we use double-buffering and we only update the content of the screen once we finish drawing our frame. You can find more information on double buffering here.
while(true) { window.render(); }
However, because of the tight loop, our program becomes highly CPU
intensive. We need to give other processes a slice of CPU time. In
other words, we need to give other applications some breathing space.
This can be done using the Thread.yield
method.
while(true) { window.render(); Thread.yield(); }
If we put all the previous example together, our program would look something like this:
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; window = new MinuetoFrame(640, 480, true); window.setVisible(true); while(true) { window.render(); Thread.yield(); } } }