开发者

Android: Using application resources

开发者 https://www.devze.com 2023-01-30 08:35 出处:网络
I\'m making a tile game. My application has an object (GraphicEngine) that handles all of the graphical operations. Each character in the game is its own object. When a character wants something drawn

I'm making a tile game. My application has an object (GraphicEngine) that handles all of the graphical operations. Each character in the game is its own object. When a character wants something drawn it sends an object (a package of sorts) to the GraphicEngine object. The GraphicEngine object stores this package in an ArrayList. Each of these packages contain x and y coordinates and a bitmap image. When the time comes GraphicEngine draws the whole list to a single bitmap and displays it.

I have programmed this, but I don't know how to get a png image from my resources folder and turn it into a bitmap. I c开发者_JAVA技巧an't find help anywhere which makes me think I'm mis-understanding the whole process.


Step #1: Call getResources() on an Activity to get a Resources object.

Step #2: Call getDrawable() on the Resources to get a Drawable for your desired resource ID.

Step #3: Have the Drawable draw itself onto the Canvas via draw().

You do not "turn it into a bitmap" normally. In a pinch, I think you can get a bitmap-backed Canvas and have the Drawable draw to it. However, that would be inefficient, AFAICT, compared to having the Drawable draw correctly in the first place.

0

精彩评论

暂无评论...
验证码 换一张
取 消