Jump to content
  • Advertisement
Sign in to follow this  
patrickboss

[java] j2me

This topic is 3700 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I every body.Please i need help,i have problem whith sprite.This is a part of my code.When i start the run,it build successfull but when i launch the midlet in the emulator,nothing happen.When i remove the part in brackets and launch again the midlet every thing's okay i don't understand where there is an error on that part. Thanks to answer,nice day."I use netbeans 6.1 and all import method are added" public class Jeu extends GameCanvas implements Runnable { private int width; private int height; rivate Image minImg; private Sprite minSprite; private int minX; private int minY; public Jeu() { super(false); width=getWidth(); height=getHeight(); minX = (width*5)/100; minY = (height * 75) / 100; } public void run() { while (true) { updateScreen(getGraphics()); try { Thread.sleep(sleepTime); } catch (Exception e) { } } } public void start() { >>((( try { minImg = Image.createImage("/min.png"); } catch (IOException ioex) { System.out.println(ioex); } minSprite = new Sprite(minImg, 3, 3); minSprite.setRefPixelPosition(minX, minY); )))<< Thread runner = new Thread(this); runner.start(); } private void createBackground(Graphics g) { g.setColor(0xFFFFFF); g.fillRect(0, 0, getWidth(), getHeight()); } private void updateScreen(Graphics g) { createBackground(g); minSprite.setRefPixelPosition(minX, minY); minSprite.paint(g); flushGraphics(); } private int sleepTime = 30; }

Share this post


Link to post
Share on other sites
Advertisement
Is it failing to load the image? Is anything being sent to the console?

Also i notice the slash in front of the file name, should it be there?

Share this post


Link to post
Share on other sites
Use getGraphics() only once! Otherwise, it will allocate a new graphics context every time the main loop executes (that means the loop in your run() method).

Also, add a Thread.yield() at the end of the main loop to make the app more responsive.

I am not sure, but you have a "start()" method in your canvas. This method is NOT called in the code snippet you gave. Call this start() method in your MIDlet's startApp() method. Also make sure you instantiate a Canvas object in the startApp() method, and set it as the current Displayable ... something along the lines of Display.getDisplay(mymidletinstance).setCurrent(mycanvasinstance)

Otherwise, what will happen is, you image is not loaded, and you will be causing NullPointerExceptions before flushGraphics() will be called, meaning in your case that the thread will die before the screen is updated.

Quote:
Original post by ssjx
Also i notice the slash in front of the file name, should it be there?

Yes, it's most likely correct, assuming the image is inside the root of the JAR file.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!