How To Scale Canvas In Android
Posted
by
Daniel Braithwaite
on Game Development
See other posts from Game Development
or by Daniel Braithwaite
Published on 2012-11-20T11:25:47Z
Indexed on
2012/11/20
17:21 UTC
Read the original article
Hit count: 318
I am writing a android game using Canvas as the way to draw everything, the problem is that when i run it on different android phones the canvas dosn't change size i tried using canvas.scale() but that didn't make a i difference. The code i use for drawing is ...
public void draw( Canvas c, int score )
{
Obstical2[] obstmp = Queue.toArray(this.o);
Coin[] cointmp = QueueC.toArray(this.c);
for( int i = 0; i < obstmp.length; i++ )
{
obstmp[i].draw(c);
}
for( int i = 0; i < cointmp.length; i++ )
{
cointmp[i].draw(c);
}
c.drawText(String.format("%d", score ), 20, 50, textPaint);
if( isWon && isStarted ) c.drawText("YOU WON", 20, 400, resPaint);
else if( isLost && isStarted ) c.drawText("YOU LOST", 20, 400, resPaint);
}
The function above calls the draw functions for the entity's on the screen, theses function are as follows
Draw Function For Obstical :
public void draw( Canvas c )
{
Log.i("D", "COIN");
coin.draw(c);
}
Draw Function For Coin :
public void draw( Canvas c )
{
obstical.draw(c);
}
How could i make the canvas re-size to it would look the same on any screen ?
Cheers Daniel
© Game Development or respective owner