在Android中扩展Bitmap类?
有没有办法在Android中扩展Bitmap类?我有一种感觉你不能,但我想为代表下落对象的位图创建一个类(会有不确定数量的该对象从屏幕顶部落下,每个对象都必须执行一些操作)某种碰撞检测)。我可以扩展/实现位图类来创建我想要的自定义类吗?
Is there a way to extend the Bitmap class in Android? I have a feeling you can't, but I would like to create a class for a bitmap which represents a falling object ( there will be an indeterminate number of this objects falling from the top of the screen, and each will have to perform some sort of collision detection). Can I extend/implement the bitmap class to create this custom class that I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法扩展 Bitmap,因为它被声明为
final
。您能做的最好的事情就是创建一个包装位图的类。You can't extend Bitmap, because it is declared
final
. The best you can do is create a class that wraps a Bitmap.位图甚至不知道它应该放置在屏幕上的哪个位置。
即使在进入动画之前,您似乎也需要使用一些“SceneObject”对象或其他可以表示场景中具有坐标的对象的模型来表示场景。这些对象中的每一个都将有一个
Bitmap
作为实例变量。完成该步骤后,为对象设置动画可能只是使用附加功能扩展“SceneObject”类。
您的渲染函数将根据模型中的信息解释场景和布局位图。
A
Bitmap
doesn't even know where it should be placed on the screen.Even before you get into animation, it seems like you need to represent your scene using a few "SceneObject" objects or some other model that can represent objects with coordinates in your scene. Each of these objects would have as an instance variable a
Bitmap
.Once that step is complete, animating your objects may just be extending your "SceneObject" class with additional functionality.
Your rendering function would interpret your scene and layout bitmaps according to the information in your models.