You Are Here:

Community: Developer Discussion Boards

#1 Old Series 60 FullCanvas menu over graphical background (similar to built-in Snake) - 2003-07-05, 17:56

Join Date: Jul 2003
Posts: 1,094
Location: Finland, Tampere
doctordwarf
Offline
Super Contributor
Hello

I wonder is there some not very complex way to implement menu similar to built-in Snake game.

My game uses FullCanvas, which does not allow any Commands. In Snake game pressing Soft Key while playing on full screen will show you a menu OVER a graphical image.
Is there a way to make similar in Java?

Thanx
Reply With Quote

#2 Old 2003-07-09, 12:48

Join Date: Mar 2003
Posts: 112
Location: Helsinki.FI
Send a message via AIM to tinkezione Send a message via Yahoo to tinkezione
tinkezione
Offline
Regular Contributor
Hi,

the basic idea is to paint your command items as strings on the canvas and then just go catching keypresses. Repaint the canvas after each keypress (down/up for moving and fire for menu item selection (KEY_SOFTKEY1 in case of Series 40 device)) and there you go. Of course your needs might vary from what this example offers, feel free to customize paint() method as needed. Just one approach:

package uimodel_s60;

import javax.microedition.lcdui.*;
import com.nokia.mid.ui.*;

/**
* <p>Title: Game UI Model</p>
* <p>Description: Game UI model for Series 60.</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Forum Nokia</p>
* @author tinke
* @version 1.0
*/

public class MenuFullCanvas extends FullCanvas {

private UIModelMIDlet parent = null;
private Manager manager = null;

private int WIDTH = getWidth();
private int HEIGHT = getHeight();

private int MENU_LENGTH = 6;
private String[] items = new String[MENU_LENGTH];
private int index = 1;

public MenuFullCanvas(UIModelMIDlet parent, Manager manager) {
this.parent = parent;
this.manager = manager;
items[0] = Resources.getString(Resources.ID_MAIN_CONTINUE);
items[1] = Resources.getString(Resources.ID_MAIN_NEW_GAME);
items[2] = Resources.getString(Resources.ID_MAIN_SETTINGS);
items[3] = Resources.getString(Resources.ID_MAIN_HIGH_SCORES);
items[4] = Resources.getString(Resources.ID_MAIN_HELP);
items[5] = Resources.getString(Resources.ID_MAIN_ABOUT);
if (manager.isPaused() == true) {
index = 0;
}
else {
index = 1;
}
}

protected void paint(Graphics g) {
g.setColor(0, 0, 255);
g.fillRect(0, 0, WIDTH, HEIGHT);
g.setColor(255, 255, 0);
g.setFont(manager.FONT_LARGE);
g.drawString(Resources.getString(Resources.ID_TITLE_MAIN_MENU), WIDTH/2, 2, Graphics.HCENTER | Graphics.TOP);
g.fillRect(0, 32 + (index * (manager.FONT_MEDIUM.getHeight() + 2)) - 2, WIDTH, 17);
g.setFont(manager.FONT_MEDIUM);
if (manager.isPaused() == true) {
g.setColor(0, 0, 0);
g.drawString(Resources.getString(Resources.ID_MAIN_CONTINUE), WIDTH/2 + 1, 32, Graphics.HCENTER | Graphics.TOP);
g.setColor(255, 255, 255);
g.drawString(Resources.getString(Resources.ID_MAIN_CONTINUE), WIDTH/2, 32, Graphics.HCENTER | Graphics.TOP);
}
for (int i=1; i < MENU_LENGTH; i++) {
g.setColor(0, 0, 0);
g.drawString(Resources.getString((Resources.ID_MAIN_CONTINUE + i)), WIDTH/2 + 1, 32 + (i * (manager.FONT_MEDIUM.getHeight() + 2)), Graphics.HCENTER | Graphics.TOP);
g.setColor(255, 255, 255);
g.drawString(Resources.getString((Resources.ID_MAIN_CONTINUE + i)), WIDTH/2, 32 + (i * (manager.FONT_MEDIUM.getHeight() + 2)), Graphics.HCENTER | Graphics.TOP);
}
}

protected void keyPressed(int keyCode) {
if (keyCode == KEY_SOFTKEY1) {
selectIndex(index);
}
if (keyCode == KEY_SOFTKEY2) {
parent.notifyDestroyed();
}
switch (getGameAction(keyCode)) {
case UP:
index--;
if ((index == 0 && manager.isPaused() == false) || index < 0)
index = MENU_LENGTH - 1;
repaint();
break;
case DOWN:
index++;
if (index == MENU_LENGTH) {
if (manager.isPaused() == true) {
index = 0;
}
else {
index = 1;
}
}
repaint();
break;
case FIRE:
selectIndex(index);
break;
default: break;
}
}

protected void keyRepeated(int keyCode) {
switch (getGameAction(keyCode)) {
case UP:
index--;
if ((index == 0 && manager.isPaused() == false) || index < 0)
index = MENU_LENGTH - 1;
repaint();
break;
case DOWN:
index++;
if (index == MENU_LENGTH) {
if (manager.isPaused() == true) {
index = 0;
}
else {
index = 1;
}
}
repaint();
break;
case FIRE:
selectIndex(index);
break;
default: break;
}
}

protected void hideNotify() {
// nothing here
}

protected void showNotify() {
// nothing here
}

private void selectIndex(int i) {
}

}

Kind regards,
Tinke / FN
Reply With Quote

#3 Old 2003-07-09, 15:01

Join Date: Jul 2003
Posts: 1,094
Location: Finland, Tampere
doctordwarf
Offline
Super Contributor
tinkezione, thank you.

I had a look at your example - looks like a good start for most arcade games :)
However, it doen't compile at once. If ypu would like this thread to be used by novice developers it would be useful to place full code here (link to it) or place only very essential part of the code, with minimal references to other classes.

Now about my case. I might use your approach for the very main game menu. But in my game there is lot's of local, context-based menus. That's why I would like to implement them as standard context-based menu. The ideal variant would be like Snake Ex menu. Now I show just a List.

I can imagine painting menu looking like a standard one on the FullCanvas and shading content behind the menu. But it would be much easier if there is some ready template for it or some more standardized approach. E.g. if I could switch from FullCanvas to Canvas AND open Commands menu manually.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ