×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    14

    Cool DIsplay a character animation from a simgle image strip.

    Hi friends,
    I am working on a game and the designer has designed the character and placed his different positions in a single image strip to reduce the memory space.
    I need to pick up the different poses from single image strip and display them sequentially. I know this is naive but I need help.

    Regards,
    Ravi S.Gohil

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: DIsplay a character animation from a simgle image strip.

    Welcome to Forum Nokia!

    This is easiest, if the frames are evenly spaced in equally-sized cells.

    Code:
    private Image heroAnimationStrip;
    private static final int HERO_FRAMES = 12;
    
    protected void paint(Graphics g) {
        paintFrame(g, x, y, heroAnimationStrip, HERO_FRAMES, 4);
    }
    
    private static void paintFrame(Graphics g, int x, int y, Image strip, int frameCount, int frame) {
        // I'm assuming that the strip is one frame tall...
        int frameHeight = strip.getHeight();
        // ...and "frameCount" frames wide, with all frames the same width
        int frameWidth = strip.getWidth() / frameCount;
    
        // use the clip region to prevent more than one frame from painting
        g.setClip(x, y, frameHeight, frameWidth);
    
        // line up the right frame in the image with the clip region
        g.drawImage(strip, x - (frameWidth * frame), y, Graphics.LEFT | Graphics.TOP);
    }
    Note that this gets all the sizes from the image itself, so you can change the size of the image (for example, to suit a different screen size) without any code change.

    This is based on the strip being one frame high. Beware of making images that are very large (say, more than 1024 pixels) in any one direction.

    Graham.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    14

    Re: DIsplay a character animation from a simgle image strip.

    Thank you graham,
    I am able to pick up certain image from the image strip. Actually can I stored the clipped image in another image object after setClip so it would be easy for me to use ahead in the code.

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,085

    Re: DIsplay a character animation from a simgle image strip.

    Quote Originally Posted by ravi_gohil999 View Post
    Actually can I stored the clipped image in another image object after setClip so it would be easy for me to use ahead in the code.
    Yes, you can do this and once you have the new clipped image objects you can set the main image strip object to null to reduce the overall runtime memory needs of your app.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    14

    Re: DIsplay a character animation from a simgle image strip.

    Thanks Amit for the reply but can you tell me how to store the clipped image in an image object.
    I have tried directly as Image xyz = g.drawImage(strip, x - (frameWidth * frame), y, Graphics.LEFT | Graphics.TOP); , I knew this won't work but I tried. I didn't work.
    Where and how can I store this clipped image?

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    14

    Re: DIsplay a character animation from a simgle image strip.

    Also I have tried other method to store the clipped image but I m getting a white background in the image.
    this is the method I have used.
    public Image getImageRegion(.......)
    {
    Image result = Image.createImage(width,height);
    result.getGraphics().drawImage(src,x,y,Graphics.TOP|Graphics.LEFT);
    return result;
    }
    I am able to retrieve the image and store it in an image object but with a white background. PLz reply,

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    14

    Re: DIsplay a character animation from a simgle image strip.

    I have found the answer to my problem. The white background can be removed. Use this method in your code.
    public Image getImageRegion(Graphics g,Image src,int x,int y,int width,int height)
    {
    Image result = Image.createImage(src,0,0,width,height,Sprite.TRANS_NONE);
    return result;
    }
    this method will return a result image. Store it in an image object.

    I thank everyone for who have replied to my question.
    Regards,
    Ravi S.Gohil

Similar Threads

  1. Replies: 2
    Last Post: 2009-08-01, 18:01
  2. Replies: 3
    Last Post: 2009-07-29, 14:00
  3. how to display special character from localisation file
    By tabletennistayo in forum Symbian
    Replies: 3
    Last Post: 2007-09-12, 07:13
  4. Plz tell me easy method to cut image from the strip
    By mwm786 in forum Mobile Java General
    Replies: 1
    Last Post: 2005-02-01, 10:12
  5. Im getting background color while cropping an image from a strip
    By gaziani007 in forum Mobile Java General
    Replies: 1
    Last Post: 2005-02-01, 05:20

Posting Permissions

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