import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.modifier.MoveModifier;
import org.andengine.entity.primitive.Line;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.entity.util.FPSLogger;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.atlas.bitmap.BuildableBitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureAtlasBuilder;
import org.andengine.opengl.texture.atlas.buildable.builder.ITextureAtlasBuilder.TextureAtlasBuilderException;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.color.Color;
import org.andengine.util.modifier.ease.EaseBackIn;
import org.andengine.util.modifier.ease.EaseBackInOut;
import org.andengine.util.modifier.ease.EaseBackOut;
import org.andengine.util.modifier.ease.EaseBounceIn;
import org.andengine.util.modifier.ease.EaseBounceInOut;
import org.andengine.util.modifier.ease.EaseBounceOut;
import org.andengine.util.modifier.ease.EaseCircularIn;
import org.andengine.util.modifier.ease.EaseCircularInOut;
import org.andengine.util.modifier.ease.EaseCircularOut;
import org.andengine.util.modifier.ease.EaseCubicIn;
import org.andengine.util.modifier.ease.EaseCubicInOut;
import org.andengine.util.modifier.ease.EaseCubicOut;
import org.andengine.util.modifier.ease.EaseElasticIn;
import org.andengine.util.modifier.ease.EaseElasticInOut;
import org.andengine.util.modifier.ease.EaseElasticOut;
import org.andengine.util.modifier.ease.EaseExponentialIn;
import org.andengine.util.modifier.ease.EaseExponentialInOut;
import org.andengine.util.modifier.ease.EaseExponentialOut;
import org.andengine.util.modifier.ease.EaseLinear;
import org.andengine.util.modifier.ease.EaseQuadIn;
import org.andengine.util.modifier.ease.EaseQuadInOut;
import org.andengine.util.modifier.ease.EaseQuadOut;
import org.andengine.util.modifier.ease.EaseQuartIn;
import org.andengine.util.modifier.ease.EaseQuartInOut;
import org.andengine.util.modifier.ease.EaseQuartOut;
import org.andengine.util.modifier.ease.EaseQuintIn;
import org.andengine.util.modifier.ease.EaseQuintInOut;
import org.andengine.util.modifier.ease.EaseQuintOut;
import org.andengine.util.modifier.ease.EaseSineIn;
import org.andengine.util.modifier.ease.EaseSineInOut;
import org.andengine.util.modifier.ease.EaseSineOut;
import org.andengine.util.modifier.ease.EaseStrongIn;
import org.andengine.util.modifier.ease.EaseStrongInOut;
import org.andengine.util.modifier.ease.EaseStrongOut;
import org.andengine.util.modifier.ease.IEaseFunction;
import android.graphics.Typeface;
import android.util.DisplayMetrics;
/**
* 各个IEaseFunction的效果演示
*/
public class EaseFunctionActivity extends SimpleBaseGameActivity
{
private static int winWidth = 854;
private static int winHeight = 480;
private BuildableBitmapTextureAtlas mBuildableBitmapTextureAtlas;
private TextureRegion mNextTextureRegion,mBadgeTextureRegion;
private Sprite[] mBadgeSprite = new Sprite[3];
private int mEaseFunctionsIndex = 0;
private Text[] mEaseFunctionNameTexts = new Text[3];
//当前是第几组IEaseFunction
private Text mIndexText;
//字体
private Font mFont,mIndexFont;
private static IEaseFunction[][] mEaseFunctions = new IEaseFunction[][]
{
new IEaseFunction[]
{
EaseLinear.getInstance(),
EaseLinear.getInstance(),
EaseLinear.getInstance()
},
new IEaseFunction[]
{
EaseBackIn.getInstance(),
EaseBackOut.getInstance(),
EaseBackInOut.getInstance()
},
new IEaseFunction[]
{
EaseBounceIn.getInstance(),
EaseBounceOut.getInstance(),
EaseBounceInOut.getInstance()
},
new IEaseFunction[]
{
EaseCircularIn.getInstance(),
EaseCircularOut.getInstance(),
EaseCircularInOut.getInstance()
},
new IEaseFunction[]
{
EaseCubicIn.getInstance(),
EaseCubicOut.getInstance(),
EaseCubicInOut.getInstance()
},
new IEaseFunction[]
{
EaseElasticIn.getInstance(),
EaseElasticOut.getInstance(),
EaseElasticInOut.getInstance()
},
new IEaseFunction[]
{
EaseExponentialIn.getInstance(),
EaseExponentialOut.getInstance(),
EaseExponentialInOut.getInstance()
},
new IEaseFunction[]
{
EaseQuadIn.getInstance(),
EaseQuadOut.getInstance(),
EaseQuadInOut.getInstance()
},
new IEaseFunction[]
{
EaseQuartIn.getInstance(),
EaseQuartOut.getInstance(),
EaseQuartInOut.getInstance()
},
new IEaseFunction[]
{
EaseQuintIn.getInstance(),
EaseQuintOut.getInstance(),
EaseQuintInOut.getInstance()
},
new IEaseFunction[]
{
EaseSineIn.getInstance(),
EaseSineOut.getInstance(),
EaseSineInOut.getInstance()
},
new IEaseFunction[]
{
EaseStrongIn.getInstance(),
EaseStrongOut.getInstance(),
EaseStrongInOut.getInstance()
}
};
/**
* 设置屏幕大小
*/
private void setScreenDisplay()
{
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
winWidth = displayMetrics.widthPixels;
winHeight = displayMetrics.heightPixels;
}
/**
* (1)
*/
@Override
public EngineOptions onCreateEngineOptions()
{
System.out.println("onCreateEngineOptions()");
setScreenDisplay();
Camera camera = new Camera(0,0,winWidth,winHeight);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(winWidth, winHeight), camera);
}
/**
* (2)
*/
@Override
protected void onCreateResources()
{
System.out.println("onCreateResources()");
//最好不同颜色字体存放在不同的纹理区域中
//创建字体
BitmapTextureAtlas mFontBitmapTextureAtlas1 = new BitmapTextureAtlas(getTextureManager(), 512, 512, TextureOptions.DEFAULT);
mFont = new Font(getFontManager(), mFontBitmapTextureAtlas1, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32, true, Color.WHITE);
//创建字体
BitmapTextureAtlas mFontBitmapTextureAtlas2 = new BitmapTextureAtlas(getTextureManager(), 512, 512, TextureOptions.DEFAULT);
mIndexFont = new Font(getFontManager(), mFontBitmapTextureAtlas2, Typeface.create(Typeface.SANS_SERIF, Typeface.ITALIC), 35, false, Color.RED);
//字体要单独加载(mFontBitmapTextureAtlas.load()好像不行)
mFont.load();
mIndexFont.load();
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("images/");
mBuildableBitmapTextureAtlas = new BuildableBitmapTextureAtlas(getTextureManager(), 512, 512, TextureOptions.DEFAULT);
mNextTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mBuildableBitmapTextureAtlas, this, "next.png");
mBadgeTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mBuildableBitmapTextureAtlas, this, "badge.png");
try
{
mBuildableBitmapTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0,1,1));
} catch (TextureAtlasBuilderException e)
{
e.printStackTrace();
}
mBuildableBitmapTextureAtlas.load();
}
/**
* (3)
*/
@Override
protected Scene onCreateScene()
{
System.out.println("onCreateScene()");
this.mEngine.registerUpdateHandler(new FPSLogger());
Scene scene = new Scene();
/*
* 平视显示器
* 摄像机的HUD相当于在你的视野上添加一个图层,这个图层用处很多,比如相机上的十字线,汽车模拟游戏里面的仪表盘。
* 在AndEngine中实际是在Camera中添加一个叫HUD的屏幕实体
*/
// HUD hud = new HUD(); //TODO 使用HUD的意义是什么?是不是与runOnUpdateThread的操作有关?
Sprite nextSprite = new Sprite(winWidth-mNextTextureRegion.getWidth()-100, 0, mNextTextureRegion, getVertexBufferObjectManager())
{
@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY)
{
if (pSceneTouchEvent.isActionDown())
{
next();
}
return true;
}
};
Sprite previousSprite = new Sprite(100, 0, mNextTextureRegion, getVertexBufferObjectManager())
{
@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY)
{
if (pSceneTouchEvent.isActionDown())
{
previous();
}
return true;
}
};
//设置previousSprite横向翻转
previousSprite.setFlippedHorizontal(true);
scene.attachChild(nextSprite);
scene.attachChild(previousSprite);
scene.registerTouchArea(nextSprite);
scene.registerTouchArea(previousSprite);
mBadgeSprite[0] = new Sprite(0, mNextTextureRegion.getHeight()+40, mBadgeTextureRegion, getVertexBufferObjectManager());
mBadgeSprite[1] = new Sprite(0, mNextTextureRegion.getHeight()+mBadgeTextureRegion.getHeight()+80, mBadgeTextureRegion, getVertexBufferObjectManager());
mBadgeSprite[2] = new Sprite(0, mNextTextureRegion.getHeight()+2*mBadgeTextureRegion.getHeight()+120, mBadgeTextureRegion, getVertexBufferObjectManager());
//创建文字(一般使用这个构造器避免ArrayIndexOutOfBoundsException异常)
mEaseFunctionNameTexts[0] = new Text(0, mNextTextureRegion.getHeight()+mBadgeTextureRegion.getHeight()+40, mFont, "",30, getVertexBufferObjectManager());
mEaseFunctionNameTexts[1] = new Text(0, mNextTextureRegion.getHeight()+2*mBadgeTextureRegion.getHeight()+80, mFont, "",30, getVertexBufferObjectManager());
mEaseFunctionNameTexts[2] = new Text(0, mNextTextureRegion.getHeight()+3*mBadgeTextureRegion.getHeight()+120, mFont, "",30, getVertexBufferObjectManager());
mIndexText = new Text(winWidth/2-100, 40, mIndexFont, "",30, getVertexBufferObjectManager());
scene.attachChild(mBadgeSprite[0]);
scene.attachChild(mBadgeSprite[1]);
scene.attachChild(mBadgeSprite[2]);
//把文字添加到场景
scene.attachChild(mIndexText);
scene.attachChild(mEaseFunctionNameTexts[0]);
scene.attachChild(mEaseFunctionNameTexts[1]);
scene.attachChild(mEaseFunctionNameTexts[2]);
//画3条直线
scene.attachChild(new Line(0, mNextTextureRegion.getHeight()+mBadgeTextureRegion.getHeight()+73,
winWidth, mNextTextureRegion.getHeight()+mBadgeTextureRegion.getHeight()+73, 2, getVertexBufferObjectManager()));
scene.attachChild(new Line(0, mNextTextureRegion.getHeight()+2*mBadgeTextureRegion.getHeight()+113,
winWidth, mNextTextureRegion.getHeight()+2*mBadgeTextureRegion.getHeight()+113, 2, getVertexBufferObjectManager()));
scene.attachChild(new Line(0, mNextTextureRegion.getHeight()+3*mBadgeTextureRegion.getHeight()+153,
winWidth, mNextTextureRegion.getHeight()+3*mBadgeTextureRegion.getHeight()+153, 2, getVertexBufferObjectManager()));
return scene;
}
private void next()
{
mEaseFunctionsIndex++;
mEaseFunctionsIndex %= mEaseFunctions.length;
reAnimate();
}
private void previous()
{
mEaseFunctionsIndex--;
if (mEaseFunctionsIndex < 0) mEaseFunctionsIndex += mEaseFunctions.length;
reAnimate();
}
/**
* (4)
*/
@Override
public synchronized void onGameCreated()
{
reAnimate();
}
/**
* 徽记坐标归位,并重新设置EaseFunction定义移动修改器。
*/
private void reAnimate()
{
//实现onUpdateSpriteBatch函数来动态更新精灵
this.runOnUpdateThread(new Runnable()
{
@Override
public void run()
{
System.out.println("mEaseFunctionsIndex:"+mEaseFunctionsIndex);
mIndexText.setText("第"+mEaseFunctionsIndex+"组");
for (int i = 0; i < 3; i++)
{
mBadgeSprite[i].setPosition(0, mBadgeSprite[i].getY());
//移除上一次的实体修改器
mBadgeSprite[i].clearEntityModifiers();
//设置文本
mEaseFunctionNameTexts[i].setText(mEaseFunctions[mEaseFunctionsIndex][i].getClass().getSimpleName());
MoveModifier moveModifier = new MoveModifier
(
3,
0,
winWidth-mBadgeSprite[i].getWidth(),
mBadgeSprite[i].getY(),
mBadgeSprite[i].getY(),
mEaseFunctions[mEaseFunctionsIndex][i]
);
mBadgeSprite[i].registerEntityModifier(moveModifier);
}
}
});
}
}
相关推荐
AndEngine是一款开源的Java游戏开发框架,主要用于Android平台。它为开发者提供了便利的2D图形渲染、物理引擎、多人游戏支持以及许多其他扩展功能,帮助开发者快速构建高质量的2D游戏。以下是对标题和描述中提及的...
AndEngine支持Box2D物理引擎的集成,可以创建可碰撞的物体,实现重力、弹性等物理效果。通过Body、Fixture和Joint等Box2D对象,你可以创建复杂的物理系统,例如平台跳跃、物体碰撞等。 此外,AndEngine还提供了丰富...
AndEngine是一款开源的2D游戏开发引擎,专为Android平台设计。它简化了在Android设备上构建高质量2D游戏的过程,提供了丰富的图形处理、物理引擎和动画功能。在这个"andengine2.0开发的小游戏"中,我们可以看到作者...
其中,Andengine的粒子系统是一个强大的工具,用于创建各种视觉效果,如火、烟、光、水波纹等。在本案例中,我们关注的是`MySimpleParticleSystem`,这是一个基础的粒子系统示例。 粒子系统是一种编程技术,用于...
Andengine的jar包是其核心库,包含了实现游戏逻辑、动画效果、碰撞检测等基本功能的类和方法。 在描述中提到的“andengine.jar”是Andengine的主要组件,它包含了游戏引擎的核心功能。这个jar文件让开发者可以直接...
通过AndEngine,开发者无需深入理解OpenGL ES的复杂细节,就能利用其强大的图形处理能力创建出高质量的视觉效果。 "JAR文件"是Java Archive的简称,是Java平台上的一个标准归档文件格式,包含了Java类和资源文件。...
AndEngine提供了丰富的动画和特效功能,如帧动画(SpriteAnimation)、粒子系统(ParticleSystem)、遮罩效果(MaskEffect)等。帧动画通过切换一系列连续的图像来创建动态效果。粒子系统可以模拟火焰、烟雾、雪花等自然...
AndEngine是一款专为Android平台设计的2D游戏开发框架,它提供了一套高效、易用的API,使得开发者能够快速构建各种2D游戏。AndEngine源码的分析和理解对于想要深入学习Android游戏开发的人来说至关重要。 1. **...
开发者可以利用AndEngine提供的基础类和工具类,如Scene(场景)、Sprite(精灵)、Camera(相机)等来构建游戏世界,通过Physics Engine(物理引擎)实现物体碰撞检测,通过Particle System(粒子系统)创建绚丽的...
,能够高效逼真的模拟火焰、雨雪、流水等效果。还拥有Motion Streak (动态模糊)、Ratial Blur (径向模糊) 等高级特效。 物理引擎 AndEngine对于物理引擎Box2D[3]的封装是让人惊讶的。 它使用JNI封装了Box2D的C++端...
- **粒子系统**:如火焰、烟雾效果的实现,以及如何自定义粒子效果。 - **用户交互**:触摸事件处理,例如角色移动、物体拖放等。 - **场景管理**:如何在不同场景间切换,以及如何组织复杂的场景结构。 - **...
,能够高效逼真的模拟火焰、雨雪、流水等效果。还拥有Motion Streak (动态模糊)、Ratial Blur (径向模糊) 等高级特效。 物理引擎 AndEngine对于物理引擎Box2D[3]的封装是让人惊讶的。 它使用JNI封装了Box2D的C++端...
在Android游戏开发中,andEngine是一个非常流行的2D游戏引擎,它提供了丰富的功能,包括粒子系统,用于创建各种视觉效果,如火花、烟雾、爆炸等。本篇将深入探讨andEngine中的粒子系统,特别是如何使用px文件来设计...
在本篇内容中,我们将深入探讨如何在andEngine中利用SVG(Scalable Vector Graphics)文件来创建图形,提升游戏的视觉效果。 SVG是一种基于XML的矢量图像格式,它可以无损地缩放而不失真,非常适合用于创建清晰、...
8. **易于上手**:AndEngine的设计目标之一就是易用性,它提供了清晰的API文档和活跃的社区支持,使开发者能更快地入门并开发出自己的游戏。 在使用AndEngine时,开发者需要注意以下几点: - **兼容性**:虽然...
AndEngine提供了Box2D物理引擎的绑定库,可以实现碰撞检测、重力模拟等物理效果。你需要创建World对象,然后定义Body(物理体)、Fixture(碰撞形状),并在Scene中应用。 六、声音与音乐 AndEngine支持Ogg和Mp3...
AndEngine是一款专为Android平台设计的游戏开发框架,它允许开发者使用Java语言进行2D游戏的开发,无需深入了解底层图形库,极大地简化了游戏制作过程。AndEngine以其高效、易用和社区活跃而受到众多独立开发者和...
AndEngine最新jar包 AndEngine最新jar包 AndEngine最新jar包
本示例源码着重展示了如何利用AndEngine将多张小图片合并成一张大图,进而创建动画精灵,实现动态效果。这个过程通常被称为精灵表(Sprite Sheet)或纹理 atlas 技术,对于优化资源加载和减少渲染时的draw调用次数...
5. **物理引擎**:AndEngine集成了Box2D物理引擎,允许开发者创建真实的物理效果,如重力、碰撞和弹性。文档会介绍如何设置物理世界、创建物理对象以及进行物理交互。 6. **动画与特效**:AndEngine提供了丰富的...