• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps When to use a sprite sheet?

Yratilos

Lurker
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.

Thanks


after reading a little more, another question would be does it only go with canvas.drawBitmap();
 
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.
 
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:
public Card(Bitmap bitmap, int cardValue) {
        _bitmap = bitmap;
        _mSRectangle = new Rect (0,0,0,0);
        _coordinates = new Coordinates();
        _cardValue = cardValue;
}
inside my Card class I have a Coordinates subclass ... with a couple methods for creating a couple rects based off sprite size etc ...
Code:
public class Coordinates 
{
        private int _x = 0;
        private int _y = 0;
        
        public Rect makeRect()
        {
            int sX = _cardValue/4;
            int sY = _cardValue%4;
            _mSRectangle.top = sY*_mSpriteHeight;
            _mSRectangle.bottom = _mSRectangle.top+_mSpriteHeight;
            _mSRectangle.left = sX*_mSpriteWidth;
            _mSRectangle.right = _mSRectangle.left+_mSpriteWidth;
            return _mSRectangle;
        }
        
        public Rect destRect()
        {
            _mDestRect = new Rect(getX(), getY(), getX() + _mSpriteWidth, getY() + _mSpriteHeight);
            return _mDestRect;
        }
}
... 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:
Bitmap bitmap;
Card.Coordinates coords;
// draw the normal items
for (Card graphic : _graphics)
{
      bitmap = graphic.getBitmap();
      coords = graphic.getCoordinates();
      canvas.drawBitmap(bitmap, coords.makeRect(), coords.mDestRect(), null);
}
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...
 
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
 
Back
Top Bottom