The Source for Java Technology Collaboration

Home » java.net Forums » Mobile & Embedded » LWUIT

Thread: LWUIT for Games?

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 4 - Last Post: Jan 16, 2009 2:58 AM by: Shai Almog
joetheelf

Posts: 2
LWUIT for Games?
Posted: Jan 9, 2009 2:36 AM
  Click to reply to this thread Reply

Do you think it would be possible to create a real-time game (20-30fps) within the LWUIT framework? Ideally, I would like to mix LWUIT components with a "Canvas" to which I could draw graphics and listen to game action keys (up, down, left, right and fire).

Obviously, I could extend Container and use the paint() method to perform whatever drawing operations I like, but I suspect the threading model used in LWUIT (implemented for stability over performance?), may prevent smooth graphics updates.

Would very frequent calls to redraw would essentially block the EDT? Are real-time games something that just shouldn't be done with LWUIT (should I look to Kuix or other UI library). Any advise or help much appreciated.

Message was edited by: joetheelf

vprise

Posts: 317
Re: LWUIT for Games?
Posted: Jan 10, 2009 10:24 PM   in response to: joetheelf
  Click to reply to this thread Reply

You can look at Display.setFramerate method but generally we don't recommend LWUIT for "in game graphics". People are using LWUIT for the graphics around the game (controls etc.) but generally game developers want finer control.
You can try hacking the LWUITImplementation subclass to get direct access to whatever you want, this might be a problem though if you want to port your game to BlackBerry, CDC etc..

joetheelf

Posts: 2
Re: LWUIT for Games?
Posted: Jan 15, 2009 9:09 AM   in response to: vprise
  Click to reply to this thread Reply

Thanks for the response, it was very helpful.

However, I still have a few questions. You say other people are using graphics around the game and I think that's what I want to do also. Support for devices other than MIDP2, CLDC1.1 is not necessary in my case. Essentially, I want LWUIT to handle menus, transitions etc. and then when the game start I need to obtain a section of the Canvas real-estate (or the whole screen) that I can obtain basic keystates for, draw to and update without going through the EDT. It might be that my lack of understanding of the LWUIT architecture is holding me back here, so forgive my ignorance.

On the latest blog entry by Shai Almog (http://lwuit.blogspot.com/2009/01/lwuit-on-tv-video.html) there's a demonstration of a Pac-Man game implemented within LWUIT, so it seems possible somehow (or is this just a hack?). On another forum thread Shai states that LWUIT is not designed with games in mind at the moment, but shouldn't the framework be generic enough to support all kinds of application (this is not a criticism, just a question)?

myinstinct

Posts: 276
Re: LWUIT for Games?
Posted: Jan 15, 2009 9:25 AM   in response to: joetheelf
  Click to reply to this thread Reply

I have a game written in LWUIT that works fine - albeit is not real graphics intensive.

My main form is BorderLayout where I utilize the NORTH for a title, the SOUTH is used for the menu - in the CENTER, I crammed in a class named MyCanvas that extends container and implements runnable and overrides the paint method.

my main form instantiates the MyCanvas class and starts that thread running.

Again - mine is a very simple graphics based Tic-Tac-Toe game - LWUIT works fine for it. No need to use LCDUI or anything else.

Shai Almog
Re: LWUIT for Games?
Posted: Jan 16, 2009 2:58 AM   in response to: joetheelf
  Click to reply to this thread Reply

My blog specifically stated that the pac man game was a native AWT
game and not written in LWUIT (although its technically not difficult
to write something like this in LWUIT).
The need for direct access depends on the graphic intensity of your
game, if it is a simple game (e.g. cards, pac man etc.) there
shouldn't be a problem with just using a component and overriding
paint(Graphics).
If you need anything more elaborate you might want direct access to
the native MIDP graphics for which you will probably want to override
implementation and use features such as Sprites from the MIDP game
API. This shouldn't be a problem with LWUIT in general, just take a
look in GameCanvasImplementation.java.

> Thanks for the response, it was very helpful.
>
> However, I still have a few questions. You say other people are
> using graphics around the game and I think that's what I want to do
> also. Support for devices other than MIDP2, CLDC1.1 is not
> necessary in my case. Essentially, I want LWUIT to handle menus,
> transitions etc. and then when the game start I need to obtain a
> section of the Canvas real-estate (or the whole screen) that I can
> obtain basic keystates for, draw to and update without going
> through the EDT. It might be that my lack of understanding of the
> LWUIT architecture is holding me back here, so forgive my ignorance.
>
> On the latest blog entry by Shai Almog (http://lwuit.blogspot.com/
> 2009/01/lwuit-on-tv-video.html) there's a demonstration of a Pac-
> Man game implemented within LWUIT, so it seems possible somehow (or
> is this just a hack?). On another forum thread Shai states that
> LWUIT is not designed with games in mind at the moment, but
> shouldn't the framework be generic enough to support all kinds of
> application (this is not a criticism, just a question)?
> [Message sent by forum member 'joetheelf' (joetheelf)]
>
> http://forums.java.net/jive/thread.jspa?messageID=326258
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]





 XML java.net RSS