Reputation: 101
I'm currently working on a small game for Android. I'm using Canvas and its drawBitmap method to draw the game-level. For this I have somewhat ported the XNA principle (so Update - Draw Loop and so on).
I have also added a "drawStaticParts" method. I use this method to draw certain parts only once. This method is called before the Update-Draw Loop starts. In this method I draw (with a Canvas) onto a Bitmap. This Bitmap is later used to "restore" the old state in Draw before I draw the dynamic parts (just like a call to drawColor(Color.Black) would).
This works perfectly fine. But only for the background, which is also drawn with the drawBitmap method. As soon as I try to add other bitmaps, they won't get displayed. I already checked if the background may override the other bitmaps, but the background draw call happens way before any other drawBitmap call. I also don't get any exceptions or similar.
Here is the code-fragment in question:
public void drawStaticParts(Canvas c) {
c.drawBitmap(TextureManager.getTexture(Element.getBackgroundID(), backgroundImg), null, new RectF(0, 0, Element.getResolution_width(), Element.getResolution_height()), null);
for(int i = 0; i < width; i++)
{
for(int j = 0; j < height; j++)
{
Element temp = spielfeld[i][j];
if(temp != null)
{
if(Element.isStatic(temp))
{
float x = i * Element.getElement_width();
float y = j * Element.getElement_height();
RectF place = new RectF(x, y, Element.getElement_width(), Element.getElement_height());
Log.w("MS:doDraw", "Draw at " + x + ", " + y + " with w=" + Element.getElement_width() + " and h=" + Element.getElement_height());
c.drawBitmap(TextureManager.getTexture(temp.getTextureID(), sceneryID), null, place, null);
}
}
}
}
}
I checked all values in question: everything is fine. The width and height is each 40 as supposed, the coordinates fit as well. I don't know any further.
I shall be eternally gratefull for any kind of help/advice. Thank you in advance.
PS: I also tried some of the solutions mentioned in threads with similar problems but nothing worked.
Upvotes: 0
Views: 609
Reputation: 55
you can't draw the static parts only once..
you should draw them every loop
because even if they are static every time you draw the dinamic parts you are overriding the current canvas and therefore you cant see the static parts..
EDIT: then the problem should be in the
TextureManager.getTexture(temp.getTextureID(), sceneryID)
check the parameters...
Upvotes: 2