Android 如何实现气泡选择动画,食堂大妈看完都会了

本文介绍了在Android中如何创建无锯齿的圆,并利用OpenGL ES进行图像和文本的平滑显示,实现气泡选择动画。通过JBox2D库实现物理特性,模拟圆的动态移动,并结合用户触摸事件响应,创建出互动的气泡效果。同时,文章提供了完整的代码示例,适合有一定Android开发经验的工程师参考学习。
摘要由CSDN通过智能技术生成

有锯齿的圆

解决方案是 smoothstep。它根据到 texture 与背景的变换起始点的距离平滑的从01变化。因此距离 0 到 0.49 时 texture 的透明度为 1,大于等于 0.5 时为 00.49 和 0.5 之间时平滑变化,如此圆的边就平滑了。

image

无锯齿圆

OpenGL 中如何使用 texture 显示图像和文本?在动画中圆有两种状态 —— 普通和选中。在普通状态下圆的 texture包含文字和颜色,在选中状态下同时包含图像。因此我需要为每个圆创建两个不同的 texture

我使用 Bitmap 实例来创建 texture,绘制所有元素。

fun bindTextures(textureIds: IntArray, index: Int) {

texture = bindTexture(textureIds, index * 2, false)

imageTexture = bindTexture(textureIds, index * 2 + 1, true)

}

private fun bindTexture(textureIds: IntArray, index: Int, withImage: Boolean): Int {

glGenTextures(1, textureIds, index)

createBitmap(withImage).toTexture(textureIds[index])

return textureIds[index]

}

private fun createBitmap(withImage: Boolean): Bitmap {

var bitmap = Bitmap.createBitmap(bitmapSize.toInt(), bitmapSize.toInt(), Bitmap.Config.ARGB_4444)

val bitmapConfig: Bitmap.Config = bitmap.conf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值