[AndEngine学习教程] ParticleSystem 粒子系统(二)

2014-11-24 09:21:00 · 作者: · 浏览: 1
======

// ===========================================================
// Constructors
// ===========================================================

public CircleParticleEmitter(final float pCenterX, final float pCenterY, final float pRadius) {
super(pCenterX, pCenterY, pRadius);
}

public CircleParticleEmitter(final float pCenterX, final float pCenterY, final float pRadiusX, final float pRadiusY) {
super(pCenterX, pCenterY, pRadiusX, pRadiusY);
}

// ===========================================================
// Getter & Setter
// ===========================================================

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

@Override
public void getPositionOffset(final float[] pOffset) {
final float random = MathUtils.RANDOM.nextFloat() * MathConstants.PI * 2;
pOffset[VERTEX_INDEX_X] = this.mCenterX + FloatMath.cos(random) * this.mRadiusX * MathUtils.RANDOM.nextFloat();
pOffset[VERTEX_INDEX_Y] = this.mCenterY + FloatMath.sin(random) * this.mRadiusY * MathUtils.RANDOM.nextFloat();
}

// ===========================================================
// Methods
// ===========================================================

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
3.内容初始化
这里要实现的东西很简单,只有一张图片,用作粒子系统用的

[java]
private static final int CAMERA_WIDTH = 800;
private static final int CAMERA_HEIGHT = 480;

private Camera mCamera;
private TiledTextureRegion mParticleRegion;



@Override
public EngineOptions onCreateEngineOptions() {
// TODO Auto-generated method stub
mCamera = new Camera(0,0,CAMERA_WIDTH, CAMERA_HEIGHT);
EngineOptions mEngineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);


return mEngineOptions;
}

@Override
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws Exception {
// TODO Auto-generated method stub
BitmapTextureAtlas mTexture = new BitmapTextureAtlas(getTextureManager(), 32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
mParticleRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mTexture, this, "particle_point.png", 0, 0,1,1);
mTexture.load();

pOnCreateResourcesCallback.onCreateResourcesFinished();
}

4.构建场景
[java]
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
throws Exception {
// TODO Auto-generated method stub
Scene mScene = new Scene();

CircleOutlineParticleEmitter mEmitter = new CircleOutlineParticleEmitter(CAMERA_WIDTH/2,CAMERA_HEIGHT/2,80);
SpriteParticleSystem mParticleSystem = new SpriteParticleSystem(CAMERA_WIDTH/2, CAMERA_HEIGHT/2,
mEmitt