Create Realtime Multiplayer Games with J2ME/LWUIT for Nokia Phones

Realtime Multiplayer games are very popular and form a great part of games being developed in the market today.j2me multiplayer games Create Realtime Multiplayer Games with J2ME/LWUIT for Nokia Phones The backend for such applications is very important as it provides support for real time data transfer amongst the clients and is the fundamental building block for them. Creating a multiplayer game is not an easy task because besides the Single Player logic, user has to maintain commuication between devices.

Developing Multiplayer games on entry level smartphones becomes really challenging due to limited resources on devices like RAM and processor and jar size limit.

AppWarp is a lightweight and powerful, yet simple platform for developing multiplayer real-time games and applications. It provides features which help developers to build seemingly complex applications with little effort. It seamlessly works across multiple client platforms.

Here are the steps in S40/J2ME on how to integrate AppWarp in your Midlet:

Create Midlet

1
2
3
public class StartMidlet extends MIDlet implements ConnectionRequestListener{
…...
}

midlet is the start up class for any J2ME mobile app whether it is in j2me or LWUIT or Nokia asha.

ConnectionRequestListener has been implemented in this class because we will try to connect to appwarp server in it and we can move forward once this is connected.

Defining Variables:

1
2
3
4
5
private Display display;
private Mycanvas mycanvas;
private String API_KEY = "";
private String SECRET_KEY = "";
private WarpClient warpClient;

You can get your api key and secret key by registering with ShepHertz

Instantiate Display and Appwarp

1
2
3
4
5
6
7
8
9
10
11
12
// Constructor
public StartMidlet() {
 
display=Display.getDisplay(this);
try {
WarpClient.initialize(API_KEY, SECRET_KEY);
warpClient = WarpClient.getInstance();
} catch (Exception e) {
e.printStackTrace();
}
mycanvas = new Mycanvas(this, warpClient);
}

This is to initilize AppWarp and mydisplayable class

Try to connect in startApp

1
2
3
4
5
/*
* adding connection listener before connecting to appwarp server
*/
warpClient.addConnectionRequestListener(this);
warpClient.connectWithUserName("Saurav");

As startApp is the life cycle method of midlet and it runs just after the constructor, I have added ConnectionRequestListener to specify the result of call back in same class.

Getting result in call back methods

1
2
3
4
5
6
7
8
9
10
11
public void onConnectDone(ConnectEvent event) {
if(event.getResult()==0){// success case
display.setCurrent(mycanvas);
}else{// failure case
System.out.println("Connection Failed: error code "+event.getResult());
}
 
}
public void onDisconnectDone(ConnectEvent event) {
 
}

We will get the result of the API execution whether it is a success or has failed in onConnectDone. In this step, we are getting ConnectEvent as a parameter with which we can check if the connection state is successful or not. If it’s a success case we will go forward to canvas.

Sample Code:

https://github.com/shephertz/AppWarp_JME_SDK_JAR/tree/master/WarpSample_J2ME

It would be great to hear the views from the readers of this blog. In case you have any more questions, please feel free to reach out to us at support@shephertz.com.

twitter Create Realtime Multiplayer Games with J2ME/LWUIT for Nokia Phonesfacebook Create Realtime Multiplayer Games with J2ME/LWUIT for Nokia Phonesgoogle Create Realtime Multiplayer Games with J2ME/LWUIT for Nokia Phoneslinkedin Create Realtime Multiplayer Games with J2ME/LWUIT for Nokia Phonespinterest Create Realtime Multiplayer Games with J2ME/LWUIT for Nokia Phonesreddit Create Realtime Multiplayer Games with J2ME/LWUIT for Nokia Phonesstumbleupon Create Realtime Multiplayer Games with J2ME/LWUIT for Nokia Phonestumblr Create Realtime Multiplayer Games with J2ME/LWUIT for Nokia Phones

Leave a Reply

Your email address will not be published. Required fields are marked *


− one = 5

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>