Online Camp #1: Pengenalan J2ME, Eclipse, dan Game Canvas
1. Mobile Game Developer War 4: Online Camp
MGDW4 Online Camp #1
Pengenalan J2ME, Eclipse, dan
Game Canvas
2. Mobile Game Developer War 4: Online Camp
Software pendukung
• Java JDK
(http://www.oracle.com/technetwork/java/javase/do
wnloads/jdk-7u1-download-513651.html)
• Wireless Toolkit [emulator default dari Java]
(http://www.oracle.com/technetwork/java/download-
135801.html)
• Eclipse Pulsar
(http://eclipse.org/pulsar/)
• Opsional:
– Nokia S40/S60 Emulator
– Perl [dibutuhkan oleh Nokia Emulator]
3. Mobile Game Developer War 4: Online Camp
JDK – J2ME – dan Eclipse Pulsar
• FAQ:
– Apakah saya bisa menggunakan JDK versi
1.x saya?
– Apakah saya bisa menggunakan Eclipse yang
biasa saya gunakan?
• Bisa, asal Eclipsenya bisa membuat J2ME Project
5. Mobile Game Developer War 4: Online Camp
Workspace Eclipse
1. Project Explorer 4. Console and debugger
2. Work here! 5. Eclipse Menu and Toolbars
3. Class explorer
6. Mobile Game Developer War 4: Online Camp
Menambahkan emulator ke Eclipse
• Install Wireless Toolkit atau Nokia Emulator terlebih dahulu
• Pada Eclipse, pilih Window > Preferences akan muncul menu seperti dibawah
Untuk Pulsar versi lama
pilihannya bernama Import
Pulsar terbaru
menggunakan menu
Manual Install
8. Mobile Game Developer War 4: Online Camp
Browse ke folder dimana kita menyimpan Emulatornya. Lalu tekan finish, tunggu
beberapa saat, nanti akan muncul seperti ini.
Lalu tekan OK untuk menutup Preferences
10. Mobile Game Developer War 4: Online Camp
Buat MIDlet dalam project
MIDlet adalah class utama yang akan dijalankan oleh aplikasi J2ME
11. Mobile Game Developer War 4: Online Camp
Fill detail for MIDlet
Form tersebut adalah:
• Package, mendefinisikan package
dari midlet kita nanti
• Name, nama file midlet
• Modifiers, mendefinisikan
modifiers pada file midlet tersebut
• Superclass, mendefinisikan midlet
tersebut akan inheritance terhadap
class apa
• Interface, jika file yang kita buat
akan implements terhadap suatu
interface
12. Mobile Game Developer War 4: Online Camp
Standar file MIDlet
1. TebakAngka() merupakan
konstruktor
2. startApp(), fungsi yang pertama
kali dijalankan
3. pauseApp(), fungsi yang
dijalankan ketika game dipause
4. destroyApp(), fungsi yang
dijalankan ketika game akan
diberhentikan
14. Mobile Game Developer War 4: Online Camp
Struktur MIDlet [MainMidlet.java]
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MainMidlet extends MIDlet {
public MainMidlet() {
}
protected void destroyApp(boolean arg0) throws
MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
}
}
15. Mobile Game Developer War 4: Online Camp
Running Project
Klik kanan pada project yang ingin di running, lalu Run As >
Emulated Java ME MIDlet
16. Mobile Game Developer War 4: Online Camp
Hello World!
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MainMidlet extends MIDlet {
public MainMidlet() {
}
protected void destroyApp(boolean arg0) throws
MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
System.out.println("Hello world!");
}
}
17. Mobile Game Developer War 4: Online Camp
Struktur MIDlet [MainMidlet.java]
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.Display;
public class MainMidlet extends MIDlet {
public MainCanvas canvas;
public MainMidlet() {
canvas = new MainCanvas();
}
protected void destroyApp(boolean arg0) throws
MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
Display display = Display.getDisplay(this);
display.setCurrent(canvas);
canvas.mulai(); Pada tahap ini akan
} muncul beberapa error,
} biarkan dulu.
18. Mobile Game Developer War 4: Online Camp
Buat GameCanvas
• File>New>Class
– Set superclass
– Add interface
19. Mobile Game Developer War 4: Online Camp
Struktur GameCanvas [MainCanvas.java]
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.Graphics;
public class MainCanvas extends GameCanvas implements Runnable {
public Graphics g;
Thread runner;
public static int SLEEP_TIME = 1000/30;
protected MainCanvas() {
super(false);
this.setFullScreenMode(true);
g = getGraphics();
runner = new Thread(this);
}
public void mulai(){
runner.start();
}
public void run() {
//di slide berikutnya
}
}
20. Mobile Game Developer War 4: Online Camp
Struktur GameCanvas [MainCanvas.java]
public void run() {
while(true){
System.out.println("Testing dulu yah...");
flushGraphics();
try {
Thread.sleep(SLEEP_TIME);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
21. Mobile Game Developer War 4: Online Camp
Game Loop
public void run() {
while(true){
System.out.println("Testing dulu yah...");
flushGraphics();
try {
Thread.sleep(SLEEP_TIME);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
while(!gameOver){
GetInput();
UpdateGame();
DrawGame();
flushGraphics();
try {Thread.sleep(SLEEP_TIME);}
catch (InterruptedException e){
e.printStackTrace();}
}
22. Mobile Game Developer War 4: Online Camp
Layar Device
Terdapat 2 jenis layar pada device, yaitu:
• Landscape, dimana lebar > tinggi layar
• Portrait, dimana tinggi > lebar layar
24. Mobile Game Developer War 4: Online Camp
Screen Size
• Landscape, rata – rata 320 x 240 pixel
• Portrait, rata – rata 240 x 320 pixel
25. Mobile Game Developer War 4: Online Camp
How to develop landscape game
• Emulator WTK, Qwerty Device
– Layar ada yang berlebih dibagian
bawah
– Tidak dapat menggunakan
getHeight() secara langsung
26. Mobile Game Developer War 4: Online Camp
How to develop portrait game
• Emulator WTK 2.5.2,
DefaultColorPhone
– Just use it nice and simple emulator
27. Mobile Game Developer War 4: Online Camp
Terima kasih.
• Untuk menyelesaikan materi, kunjungi
http://bit.ly/KJmFfA
• Untuk pertanyaan atau diskusi, bisa
dilakukan via forum:
http://bit.ly/mgdw4forum