Results 1 to 4 of 4
- 12-15-2010, 08:06 AM #1
Member
- Join Date
- May 2010
- Posts
- 14
- Rep Power
- 0
Implementing bluetooth/network code (beginners).
*duplicate post, but nobody can help in the New to Java forum so am trying here instead*
Hi folks - as a learning exercise, I'm trying to write a very simple J2ME game project (pong) playable via bluetooth, however hopefully my problem is high level enough that it can be answered by non-J2ME'ers too.
What I have up to now is 2 'sub' projects, the pong game and also a skeleton bluetooth client/server. Both of which are fairly straightforward and are working, in their own separate right.
Now however I want to 'plug' the bluetooth Client code (I'll keep Server as a separate class for now) into the game code, but I'm a bit stumped how & more specifically where to do it.
Up to now, for instance, my game Midlet looks like this...
And then in pongCanvas is the game thread :Java Code:public class Pong extends MIDlet { public Pong() { pongCanvas = new PongCanvas(); } public void startApp() { Display display =Display.getDisplay(this); pongCanvas.start(); display.setCurrent(pongCanvas); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } private static PongCanvas pongCanvas; }
My assumption is I need to add an output.write() (or similar) call in the game loop, to write out whatever info I want sending as part of the game.Java Code:public void run() { while(true) { updateScreen(getGraphics()); try { Thread.sleep(sleepTime); } catch (Exception e) { } } } public void start() { initSprites(); Thread runner = new Thread(this); runner.start(); }
What I don't know, or am failing miserably to grasp, is how to get the Client up and running alongside the game, and how to then access the client methods from within my game class.
Do I need to start the Client in the Midlet class code, or should I just add the Client methods to my game class, and make one big game/client hybrid class?
I'm confused on the structure really, how & where do you generally plug network code into your game. I'm struggling to 'visualise' how the final Midlet/Game/Client classes should look, if that makes any sense.
thanks in advance for any tips.
- 12-20-2010, 08:33 AM #2
Member
- Join Date
- May 2010
- Posts
- 14
- Rep Power
- 0
68 views but nobody has any suggestions? :(
- 12-20-2010, 06:11 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 49
- Rep Power
- 0
1. Start game
2. Search for available devices
3. Attempt to establish connection
4. Once connected start passing data
So looking at what you provided I would place it in PongCanvas in start(). First searching for device, then connecting and only after that start with sprites and other bits associated with game.
PS: Moaning about not getting reply wouldn't help you. There is no restriction that people cannot view it if they do not know answer.
PS2: Just foreword warning, I'm holidays so there is possibility that my next reply will come only after 29th Dec.
- 12-22-2010, 12:59 PM #4
Member
- Join Date
- May 2010
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
Generic question on implementing bluetooth/net code
By SM2010 in forum New To JavaReplies: 2Last Post: 12-14-2010, 04:10 PM -
Server is in a network using an IP, but router in network carries the external IP(www
By lse123 in forum NetworkingReplies: 7Last Post: 05-02-2010, 10:35 PM -
java code for bluetooth.
By rainfan in forum Java AppletsReplies: 4Last Post: 01-13-2010, 05:11 AM -
Transfering files over Bluetooth (with javax.bluetooth)
By weber10 in forum CLDC and MIDPReplies: 0Last Post: 02-26-2009, 08:14 PM -
Trouble implementing part of code into GUI
By Flaresplitz in forum New To JavaReplies: 1Last Post: 12-21-2008, 07:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks