Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Jun 2010

    Unhappy Sprite not showing when i use MathFP class in JavaME

    Hi to all,
    I have posted this post on code-guru forum. But after posting i thought this is more suitable forum for java ME. So now i put my post here

    Hope you all will be fine.I am making a cricket game. Every things work fine when i use integers in my game, say to set the position of the sprite. But when i switch to floating point and then set the position of my sprite using floating point then sprite doesn't appear on the screen. Here is my code to set the position of the sprite.

    import net.jscience.math.kvm.MathFP;
    public class DemoGameCanvas extends GameCanvas implements Runnable {
        private int ballXFP = MathFP.toFP(140);     //  x position (as a MathFP)
        private int ballYFP = MathFP.toFP(100);     //  y position (as a MathFP)
        private int direction ;                                  //  current direction in degrees
        private LayerManager lm;
        private int viewPortX = 0;
        private int viewPortY = 0;
        private int ballX = 140;
        private int ballY = 100;
        public DemoGameCanvas() {
            try {
            } catch (IOException ioe) {
        } // constructor  DemoGameCanvas()
         * Initialize the Game Design, then load all layers and start animation threads.
        private void init() throws IOException {
            //For all sprites positions
            lm = new LayerManager();
            timer = new Timer();
            gameDesign = new GameDesign();
            ballImage = gameDesign.getBall5px();     // ball image is 5 x 5 pixels
            ballSprite = gameDesign.getWhiteBall();
           // ballSprite.setRefPixelPosition(ballXFP, ballYFP);
            ballSprite.defineReferencePixel(3, 3);
        } //  init()
        private void adjustViewPoint(int x, int y) {
            //adjust the viewport
            this.lm.setViewWindow(viewPortX, viewPortY, getWidth(), getHeight());
        public void run() {
            Graphics g = getGraphics();
            while (!interrupted) {
                try {
                } catch (InterruptedException ie) {
            } // while (!interrupted)
        } //run()
        private void updateScreen(Graphics g) {
            ballSprite.setRefPixelPosition(ballXFP, ballYFP);    // not working
            // ballSprite.setRefPixelPosition(ballX, ballY);        // working
        } // updateScreen()
        private void createBackGround(Graphics g) {
            lm.paint(g, 0, 0);
            flushGraphics(0, 0, getWidth(), getHeight());
    } // class DemoGameCanvas
    Please tell me what i am doing wrong. Why it is not working with MathFP class. Please help.


  2. #2
    Regular Contributor
    Join Date
    Jun 2010

    Re: Sprite not showing when i use MathFP class in JavaME

    hey problem solved . The line should be

    ballSprite.setRefPixelPosition(MathFP.toInt(ballXFP), MathFP.toInt(ballYFP));

Similar Threads

  1. Sprite Class
    By phil_mw60 in forum Mobile Java General
    Replies: 2
    Last Post: 2010-04-11, 22:38
  2. About MATHFP class
    By deepakskole2006 in forum Mobile Java General
    Replies: 0
    Last Post: 2006-12-08, 06:01
  3. Sprite problem (RWsSprite class)
    By SudhaYellapantula in forum Symbian User Interface
    Replies: 2
    Last Post: 2006-03-08, 06:41
  4. Sprite GameCharacter Movement & Sprite Deletion
    By bloodyknight in forum Mobile Java General
    Replies: 2
    Last Post: 2004-07-10, 02:34
  5. which class for showing popup
    By apitoman in forum Symbian
    Replies: 0
    Last Post: 2004-06-17, 11:14

Posting Permissions

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