Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old September 28th, 2010, 12:34 PM   #1 (permalink)
New Member
 
Join Date: Sep 2010
Posts: 2
 
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
Default When to use a sprite sheet?

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();

Yratilos is offline  
Last edited by Yratilos; September 28th, 2010 at 02:35 PM.
Reply With Quote
Sponsors
Old September 29th, 2010, 08:14 AM   #2 (permalink)
Senior Member
 
Join Date: Jul 2010
Posts: 977
 
Device(s): Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Thanks: 52
Thanked 199 Times in 144 Posts
Default

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.
jonbonazza is online now  
Reply With Quote
The Following User Says Thank You to jonbonazza For This Useful Post:
Yratilos (September 29th, 2010)
Old September 29th, 2010, 04:59 PM   #3 (permalink)
New Member
 
Join Date: Sep 2010
Posts: 2
 
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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...
Yratilos is offline  
Reply With Quote
Old September 30th, 2010, 02:24 AM   #4 (permalink)
New Member
 
Join Date: Sep 2010
Posts: 2
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default When to use a sprite sheet?

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
Den Rudy is offline  
Last edited by Den Rudy; January 5th, 2011 at 03:01 AM.
Reply With Quote
Reply

Bookmarks

Tags
bitmap, drawable, images, sprite sheet, sprites


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Animated Sprite Using XML? safibaba Application Development 9 September 6th, 2011 06:19 AM
MyBackupPro or Sprite Pro kgreen66 HTC EVO 4G 1 August 10th, 2010 04:00 AM
Support Some help needed on Sprite Migrate Seifer Samsung Galaxy S 0 June 19th, 2010 09:42 AM
MyBackup or Sprite? Ziani Android Applications 3 February 1st, 2010 11:28 AM
Sprite Android Backup Julian_Sprite Android Applications 0 September 1st, 2009 10:06 PM



All times are GMT -5. The time now is 11:33 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo