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