本篇包括虚拟键盘,粒子系统
1虚拟键盘
分为两种,一种是单个虚拟键盘,另一种是多个方位虚拟键盘
1)加载虚拟键盘所需要的图片资源
private BitmapTextureAtlas mOnScreenControlTexture;
private ITextureRegion mOnScreenControlBaseTextureRegion;
private ITextureRegion mOnScreenControlKnobTextureRegion;
this.mOnScreenControlTexture = new BitmapTextureAtlas(this.getTextureManager(), 256, 128, TextureOptions.BILINEAR);
this.mOnScreenControlBaseTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mOnScreenControlTexture, this, "onscreen_control_base.png", 0, 0);
this.mOnScreenControlKnobTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mOnScreenControlTexture, this, "onscreen_control_knob.png", 128, 0);
this.mOnScreenControlTexture.load();
2.1)单个虚拟键盘
final AnalogOnScreenControl analogOnScreenControl = new AnalogOnScreenControl(0, CAMERA_HEIGHT - this.mOnScreenControlBaseTextureRegion.getHeight(), this.mCamera, this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, 200, this.getVertexBufferObjectManager(), new IAnalogOnScreenControlListener() {
@Override
public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
//pValueX ,pVlueY在[-1,1]之间,坐标系pValueX ,pVlueY交集就是方位啦 }
@Override
public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl) {
//里边的小的被点击时调用 }
});
analogOnScreenControl.getControlBase().setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
analogOnScreenControl.getControlBase().setAlpha(0.5f);
analogOnScreenControl.getControlBase().setScaleCenter(0, 128);
analogOnScreenControl.getControlBase().setScale(1.25f);
analogOnScreenControl.getControlKnob().setScale(1.25f);
analogOnScreenControl.refreshControlKnobPosition();
scene.setChildScene(analogOnScreenControl);
2.2多个虚拟键盘,下边的是两个
final AnalogOnScreenControl velocityOnScreenControl = new AnalogOnScreenControl(x1, y1, this.mCamera, this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, this.getVertexBufferObjectManager(), new IAnalogOnScreenControlListener() {
@Override
public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
physicsHandler.setVelocity(pValueX * 100, pValueY * 100);
}
@Override
public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl) {
/* Nothing. */
}
});
velocityOnScreenControl.getControlBase().setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
velocityOnScreenControl.getControlBase().setAlpha(0.5f);
scene.setChildScene(velocityOnScreenControl);
/* Rotation control (right). */
final float y2 = (this.mPlaceOnScreenControlsAtDifferentVerticalLocations) ? 0 : y1;
final float x2 = CAMERA_WIDTH - this.mOnScreenControlBaseTextureRegion.getWidth();
final AnalogOnScreenControl rotationOnScreenControl = new AnalogOnScreenControl(x2, y2, this.mCamera, this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, this.getVertexBufferObjectManager(), new IAnalogOnScreenControlListener() {//0.1f触摸响应时间为0.1秒 @Override
public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
if(pValueX == x1 && pValueY == x1) {
face.setRotation(x1);
} else {
face.setRotation(MathUtils.radToDeg((float)Math.atan2(pValueX, -pValueY)));
}
}
@Override
public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl) {
/* Nothing. */
}
});
rotationOnScreenControl.getControlBase().setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
rotationOnScreenControl.getControlBase().setAlpha(0.5f);
velocityOnScreenControl.setChildScene(rotationOnScreenControl);//两个键盘的关系
2粒子系统
1)粒子图片资源
this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
this.mParticleTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "particle_point.png", 0, 0);
this.mBitmapTextureAtlas.load();
2)粒子类型
final CircleOutlineParticleEmitter particleEmitter = new CircleOutlineParticleEmitter(ParticleSystemSimpleExample.CAMERA_WIDTH * 0.5f, ParticleSystemSimpleExample.CAMERA_HEIGHT * 0.5f + 20, 80);//粒子类型
3)粒子工场产生的粒子类型,数量等
final SpriteParticleSystem particleSystem = new SpriteParticleSystem(particleEmitter, 60, 60, 360, this.mParticleTextureRegion, this.getVertexBufferObjectManager());//粒子工厂,参数,60,60是粒子的最大与最小生成速率
4)粒子的行为方式(旋转,颜色,透明度方面的变化)
particleSystem.addParticleInitializer(new ColorParticleInitializer<Sprite>(1, 0, 0));
particleSystem.addParticleInitializer(new AlphaParticleInitializer<Sprite>(0));
particleSystem.addParticleInitializer(new BlendFunctionParticleInitializer<Sprite>(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE));
particleSystem.addParticleInitializer(new VelocityParticleInitializer<Sprite>(-2, 2, -20, -10));
particleSystem.addParticleInitializer(new RotationParticleInitializer<Sprite>(0.0f, 360.0f));
particleSystem.addParticleInitializer(new ExpireParticleInitializer<Sprite>(6));
particleSystem.addParticleModifier(new ScaleParticleModifier<Sprite>(0, 5, 1.0f, 2.0f));
particleSystem.addParticleModifier(new ColorParticleModifier<Sprite>(0, 3, 1, 1, 0, 0.5f, 0, 0));
particleSystem.addParticleModifier(new ColorParticleModifier<Sprite>(4, 6, 1, 1, 0.5f, 1, 0, 1));
particleSystem.addParticleModifier(new AlphaParticleModifier<Sprite>(0, 1, 0, 1));
particleSystem.addParticleModifier(new AlphaParticleModifier<Sprite>(5, 6, 1, 0));
5)加载粒子到Sence中
scene.attachChild(particleSystem);
6)粒子中心开始位置,开闭等
particleEmitter.setCenter(x,y );
particleSystem.setParticlesSpawnEnabled(true);
分享到:
相关推荐
AndEngine游戏引擎 2D游戏引擎
andengine游戏引擎源码及实例,想学这个的应该对你有帮助的~~
AndEngine android游戏引擎源码,绝对物有所值,android游戏开发者的杀手锏
AndEngine 游戏引擎 中文文档,AndEngine的文档很少,而且是中文的哦
AndEngine游戏引擎jar包 开发游戏的好帮手,不会使用的可以连系
AndEngine游戏引擎进阶之自定义Tiled精灵,AndEngine游戏引擎是一个开源的Android 2D游戏引擎。
andEngine是一款优秀的基于Android平台的游戏引擎,集成了Box2D物理引擎,想做愤怒的小鸟吗?就靠他了。
AndEngine游戏引擎讲解.pdf
AndEngine是一款基于OpenGL ES技术的Android游戏引擎,物理引擎同样为Box2D(标配)。可以运行在支持Android1.6及以上版本的系统当中。
AndEngine游戏开发指南-初级篇.pdf android基于AndEngine游戏引擎开发
AndEngine是一款以OpenGLES方式进行画面渲染的2D游戏引擎,可以运行在支持Android 1.6及以上版本的系统当中。应该说,相较前文介绍的Libgdx引擎,AndEngine拥有更多的游戏组件与扩展功能。并且与Libgdx不同,它在...
程序是基于AndEngine-GLES2的,使用了模拟控制器、tiledmap地图,欢迎下载,因为第一次分享资源,然后也是自己没什么积分,所以资源分设置成了10分,以后共享我会把分设置低点,但是这个资源还是物有所值的。
AndEngine游戏引擎学习入门篇,如果你想学习Android游戏开发,请从这里开始!详细的注释
andengine同样是一款基于OpenGL ES技术的Android游戏引擎,物理引擎同样为Box2D。该框架性能普通,文档缺乏,但示例较为丰富。
AndEngine游戏 DeliveryBoy 源代码,可以用来做AndEngine游戏实例教程进行参考
AndEngine 开源引擎源文件+androidExample文件
最流行的android游戏2d引擎,基于open gl 开发游戏 组建方式开发 基于libgdx
Android 2D游戏引擎AndEngine快速入门教程
AndEngine游戏开发示例 详情请链接至:http://blog.csdn.net/lan410812571/article/details/9716743
如果你的游戏准备使用物理引擎,请优先考虑AndEngine。AndEngine官方提供了数个扩展包。例如:AndEngineLiveWallpaperExtension动态壁纸扩展、AndEngineTexturePackerExtension纹理打包扩展、AndEnginePhysicsBox2...