1. Check out our companion app, Forums for Android! Download from Google Play

When to use a sprite sheet?

Discussion in 'Application Development' started by Yratilos, Sep 28, 2010.

  1. Yratilos

    Yratilos New Member
    Thread Starter

    Sep 28, 2010
    I was hoping that someone could help shed a little light on something. When developing a game that would contain something like a deck of cards, is it best to use an individual image for each card, or would it be best to use a sprite sheet image and draw only a portion of the image. I think it would make more sense to use the sprite sheet, but I'm not sure how to draw only a portion of an image.

    If using a sprite sheet, then inside the constructor for a Card class I would imagine this...

    public Card(Bitmap bitmap)
    _bitmap = bitmap;

    but how to make it draw only one portion of the sheet...

    I am very new to developing on android and would greatly appreciate some assistance.


    after reading a little more, another question would be does it only go with canvas.drawBitmap();


  2. jonbonazza

    jonbonazza Well-Known Member

    Jul 13, 2010
    I have never personally done it, but I am sure that there is a method for cropping a bitmap somewhere int he SDK... likely under the Bitmap class, but could be other places too. Java has methods like this, so I would assume android does to.

    Oh and to answer your initial question, yes a spritesheet is better.
    Yratilos likes this.
  3. Yratilos

    Yratilos New Member
    Thread Starter

    Sep 28, 2010
    thanks jonbonazza, for your response. This is what I have ended up with, after pulling from a few different tutorials and development sites... and it seems to work well ... now for mem testing :)

    my Card class constructor pulls in the bitmap and the int representing the card

    Code (Text):
    1. public Card(Bitmap bitmap, int cardValue) {
    2.         _bitmap = bitmap;
    3.         _mSRectangle = new Rect (0,0,0,0);
    4.         _coordinates = new Coordinates();
    5.         _cardValue = cardValue;
    6. }
    inside my Card class I have a Coordinates subclass ... with a couple methods for creating a couple rects based off sprite size etc ...
    Code (Text):
    2. public class Coordinates
    3. {
    4.         private int _x = 0;
    5.         private int _y = 0;
    7.         public Rect makeRect()
    8.         {
    9.             int sX = _cardValue/4;
    10.             int sY = _cardValue%4;
    11.             _mSRectangle.top = sY*_mSpriteHeight;
    12.             _mSRectangle.bottom = _mSRectangle.top+_mSpriteHeight;
    13.             _mSRectangle.left = sX*_mSpriteWidth;
    14.             _mSRectangle.right = _mSRectangle.left+_mSpriteWidth;
    15.             return _mSRectangle;
    16.         }
    18.         public Rect destRect()
    19.         {
    20.             _mDestRect = new Rect(getX(), getY(), getX() + _mSpriteWidth, getY() + _mSpriteHeight);
    21.             return _mDestRect;
    22.         }
    23. }
    ... and then in my onDraw for my view ... I pull the resource out of my array and draw using drawBitmap and the rects associated with each object ..

    Code (Text):
    2. Bitmap bitmap;
    3. Card.Coordinates coords;
    4. // draw the normal items
    5. for (Card graphic : _graphics)
    6. {
    7.       bitmap = graphic.getBitmap();
    8.       coords = graphic.getCoordinates();
    9.       canvas.drawBitmap(bitmap, coords.makeRect(), coords.mDestRect(), null);
    10. }
    I'm not sure if this is the best way to pull this off ... but it seems to work. Any advice would be greatly appreciated...
  4. Den Rudy

    Den Rudy New Member

    Sep 30, 2010
    Ahh. I know how to make sprites.. but you should get adobe illustrator for that. But... you should go to panelmonkey.org

    There are WHOLE spritesheets there. And you can simply use those for mugen, i play mugen too.

    If you could, message me your mugen file folder, id like to play it with your characters, or something, would sound fun.

    Hope i helped!


    MySpace Layouts

Share This Page