【发布时间】:2014-02-23 12:01:19
【问题描述】:
我正在尝试将一个简单的 2d 图像(.png 格式)添加到我的 2d 游戏中。我的游戏由一个扩展表面视图的 Game View 类、一个控制游戏逻辑并绘制画布的 GameState 类和一个 Main Activity 组成。我的 GameState 类有这个方法:
// the draw method
public void draw(Canvas canvas, Paint paint) {
// Clear the screen
canvas.drawRGB(20, 20, 20);
// set the colour
paint.setARGB(200, 0, 200, 0);
// // draw the bats
// canvas.drawRect(new Rect(_bottomBatX, _bottomBatY, _bottomBatX
// + _batLength, _bottomBatY + _batHeight), paint); // bottom bat
}
它负责绘制游戏中的所有对象。我可以很容易地画一个矩形。但我无法弄清楚如何将图像绘制到我的游戏中。我计划让图像动态移动(如精灵)。
如何在上述方法中绘制精灵?
我不能这样做:
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
因为 GameState 没有扩展 View
谢谢
【问题讨论】: