menu

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

menu

Postby rahul7star » Tue Dec 18, 2007 5:28 am

hi
again i got stuck in menu and how to navigate with keys menu icon,
plz send me code 4 both midlet n class , i need full codes help me its urgent

just splash n then onplay next scren will come dats it
rahul7star
Regular User
 
Posts: 84
Joined: Fri Aug 17, 2007 11:22 am

Re: menu

Postby DevelopmentTeam » Tue Dec 18, 2007 6:53 am

I dont understand what exactly is your problem with menu's plz post your code or explain where your problem lies. We dont post complete codes here.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: menu

Postby rahul7star » Mon Dec 24, 2007 3:21 am

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
* A MIDlet that displays the Doggy animation.
*
* @author Mark A. Patel - Motorola, Inc.
* @author Roger Riggs - Sun Microsystems, Inc.
**/
public class DoggyMIDlet extends MIDlet implements CommandListener {
Command cmdExit;
/**
* Constructs a new DoggyMIDlet
**/
public DoggyMIDlet() {
cmdExit = new Command("Exit", Command.EXIT, 1);
}

/**
* Starts the app by creating a new Doggy instance and displaying it
**/
protected void startApp() throws MIDletStateChangeException {
Doggy d;

d = new Doggy();

d.addCommand(cmdExit);
d.setCommandListener(this);

Display.getDisplay(this).setCurrent(d);

}

protected void pauseApp() {
}

protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
}

public void commandAction(Command c, Displayable d) {
if (c == cmdExit) {
try {
destroyApp(false);
} catch (Exception e) {}
notifyDestroyed();
}
}
}
class Doggy extends Canvas implements Runnable {

/**
* Number of frames in the animation
**/
static final int FRAME_COUNT = 17;

/**
* Normal frame delay (milliseconds)
**/
static final int FRAME_DELAY = 180;

/**
* Frame delay for the last frame where the dog is sleeping
**/
static final int LAST_FRAME_DELAY = 3000;

/**
* Relative horizontal position where each of the frames
* should be rendered. 0 represents the left edge of the screen
* and 1024 represents the right edge of the run distance
* (1024 is used so that scaling can be performed using
* simple bit shifts instead of division operations).
**/
static final int[] framePositions = {
0, 50, 186, 372, 558, 744, 930, 1024, 1024,
834, 651, 465, 279, 93, 200, 0, 0
};

/**
* An Image containing the 17 frames of the dog running,
* stacked vertically.
* Using a single image is much more efficient than using several
* images with each containing a single frame.
* Each frame can be rendered seperately by setting the clip
* region to the size of a single frame and then
* rendering the image at the correct position so that the desired
* frame isaligned with the clip region.
**/
Image doggyImages = null;

/**
* Width of a single animation frame
**/
int frameWidth = 0;

/**
* Height of a single animation frame
**/
int frameHeight = 0;

/**
* Index of the current frame
**/
int frameIndex = 0;

/**
* The distance, in pixels, that the dog can run (screen width less
* the width of a single frame)
**/
int runLength = 0;

/**
* Indicates if the animation is currently running
**/
boolean running = false;

/**
* Called when this Canvas is shown. This method starts the timer
* that runs the animation sequence.
**/
protected void showNotify() {
if (doggyImages == null) {
try {
doggyImages =
Image.createImage("/image105.gif");
frameWidth = doggyImages.getWidth();
frameHeight = doggyImages.getHeight() / FRAME_COUNT;
} catch (Exception ioe) {
return; // no image to animate
}
}

runLength = getWidth() - frameWidth;
running = true;
frameIndex = 0;

new Thread(this).start();
}

/**
* Called when this Canvas is hidden. This method stops the
* animation timer to free up processing
* power while this Canvas is not showing.
**/
protected void hideNotify() {
running = false;
}

public void run() {

// Need to catch InterruptedExceptions and bail if one occurs
try {
while (running) {
Thread.sleep((frameIndex == FRAME_COUNT - 1) ?
LAST_FRAME_DELAY : FRAME_DELAY);

// Remember the last frame index so we can compute
// the repaint region
int lastFrameIndex = frameIndex;

// Update the frame index
frameIndex = (frameIndex + 1) % FRAME_COUNT;

// Determine the left edge of the repaint region
int repaintLeft = framePositions[lastFrameIndex];
int repaintRight = framePositions[frameIndex];
if (framePositions[lastFrameIndex] > framePositions[frameIndex]) {
repaintLeft = framePositions[frameIndex];
repaintRight = framePositions[lastFrameIndex];
}
// Scale the repaint coordinates to the width of the screen
repaintLeft = (repaintLeft * runLength) >> 10;
repaintRight = (repaintRight * runLength) >> 10;

// Trigger a repaint of the affected portion of the screen
// Repaint the region where the last frame was rendered
// (ensures that it is cleared)
repaint(repaintLeft, 0,
frameWidth + repaintRight - repaintLeft, frameHeight);
}
} catch (InterruptedException e) {}
}

public void paint(Graphics g) {

// Clear the background (fill with white)
// The clip region will limit the area that
// actually gets cleared to save time
g.setColor(0x00FFFF);
g.fillRect(0, 0, getWidth(), getHeight());

// Translate the graphics to the appropriate
// position for the current frame
g.translate((framePositions[frameIndex] * runLength) >> 10, 0);
// g.translate((framePositions[frameIndex] * runLength) >> 10, getHeight() - frameHeight >> 1);
//g.translate(45,45);


// Constrain the clip region to the size of a single frame
g.clipRect(60,0, frameWidth, frameHeight);

// Draw the current frame by drawing the entire image with
// the appropriate vertical offset so that the desired frame
// lines up with the clip region.
g.drawImage(doggyImages, 10, -(frameIndex * frameHeight),
Graphics.VCENTER + Graphics.HCENTER);
}
}








the image is moving 4m top left to top rihgt ok
but when i tried ti move form center left to center right it not moving
rahul7star
Regular User
 
Posts: 84
Joined: Fri Aug 17, 2007 11:22 am


Return to J2ME Games

Who is online

Users browsing this forum: No registered users and 1 guest

cron