1. activity하나 만듬.
2. nullpointerexception 방지를 위해 manifest에 추가.
android:configChanges="orientation|screenSize"
3.
public class Intro extends Activity {
Intent intent = null;
@Override
onCreate {
System.gc();
....
Handler x = new Handler();
x.postDelayed(new splashHandler(), 1000);
}
public class splashHandler implements Runnable {
public void run() {
Intent intent = new Intent(getApplicationContext(),
Jump.class);
startActivity(intent);
finish();
}
}
private void clearApplicationCache(java.io.File dir) {
if (dir == null)
dir = getCacheDir();
else
;
if (dir == null)
return;
java.io.File[] children = dir.listFiles();
try {
for (int i=0; i < children.length; i++)
if (children[i].isDirectory())
clearApplicationCache(children[i]);
else
children[i].delete();
} catch (Exception e) {
}
}
@Override
public void onDestory() {
super.onDestory();
clearApplicationCache(null);
}
}
2014년 8월 15일 금요일
[AndEngine] 10. Font 폰트
1. set font.
private Font mFont1;
private Font mFont2;
onCreateResources() {
....
this.mFont1 = FontFactory.create(this.getFontManager(),
this.getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT, Typeface.BOLD, 32);
this.mFont1.load();
FontFactory.setAssetBasePath("font/");
this.mFont2 = FontFactory.create(this.getFontManager(),
this.getTextureManager(), 512, 512, Typeface.create(Typeface.BILINEAR, this.getAssets(), "Droid.ttf", 28, true, Color.WHITE);
this.mFont2.load();
....
}
onCreateScene() {
...
text = new Text(80, y, this.mFont1, content, content.length(), vertexBufferObjectManager);
}
2. display point.
//
leftText = new Text(80, 35, this.mFont, "0 Meter", "XXXX Meter".length(), vertexBufferObjectManager);
leftText.registerEntityModifier(new ScaleModifier(2, 0.0f, 1.0f));
scene.attachChild(leftText);
private Font mFont1;
private Font mFont2;
onCreateResources() {
....
this.mFont1 = FontFactory.create(this.getFontManager(),
this.getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT, Typeface.BOLD, 32);
this.mFont1.load();
FontFactory.setAssetBasePath("font/");
this.mFont2 = FontFactory.create(this.getFontManager(),
this.getTextureManager(), 512, 512, Typeface.create(Typeface.BILINEAR, this.getAssets(), "Droid.ttf", 28, true, Color.WHITE);
this.mFont2.load();
....
}
onCreateScene() {
...
text = new Text(80, y, this.mFont1, content, content.length(), vertexBufferObjectManager);
}
2. display point.
//
leftText = new Text(80, 35, this.mFont, "0 Meter", "XXXX Meter".length(), vertexBufferObjectManager);
leftText.registerEntityModifier(new ScaleModifier(2, 0.0f, 1.0f));
scene.attachChild(leftText);
[AndEngine] 9. Collision 충돌
if (obj1.collidesWith(obj2) {
}
scene.registerUpdateHandler(new IUpdateHandler() {
@Override
public void reset() {
}
@Override
public void onUpdate(final float pSecondsElapsed) {
if (stone.collidesWith(jump) {
//TODO
}
}
}
[AndEngine] 8. Animation
1. move
onCreateResources() {
....
this.mBitmapTextureAtlasJump = new BitmapTextureAtlas(
this.getTextureManger(), 200, 100, TextureOptions.BILINEAR); //image 200x100
this.mFaceTextureRegionJump = BitmapTextureAtlasTextureRegionFactory.createTitledFromAsset(this.mBitmapTextureAtlasJump, this, "jump.gif", 0, 0, 2, 1); //2 images
this.mBitmapTextureAtlasJump.load();
}
onCreateScene() {
....
//animate(long[] pFrameDurations, int pFirstTileIndex, int pLastTileIndex, boolean pLoop)
jump.animate(new long[] {400, 400}, 0, 1, true);
scene.attachChild(jump);
return scene;
}
2. rotate
//(float pDuration, float pFromRotation, float pToRotation)
this.registerEntityModifier(new RotationModifier(1, 0, -360));
onCreateResources() {
....
this.mBitmapTextureAtlasJump = new BitmapTextureAtlas(
this.getTextureManger(), 200, 100, TextureOptions.BILINEAR); //image 200x100
this.mFaceTextureRegionJump = BitmapTextureAtlasTextureRegionFactory.createTitledFromAsset(this.mBitmapTextureAtlasJump, this, "jump.gif", 0, 0, 2, 1); //2 images
this.mBitmapTextureAtlasJump.load();
}
onCreateScene() {
....
//animate(long[] pFrameDurations, int pFirstTileIndex, int pLastTileIndex, boolean pLoop)
jump.animate(new long[] {400, 400}, 0, 1, true);
scene.attachChild(jump);
return scene;
}
2. rotate
//(float pDuration, float pFromRotation, float pToRotation)
this.registerEntityModifier(new RotationModifier(1, 0, -360));
[AndEngine] 7. Jump
onCreateScene() {
....
final Jump jump = new Jump(center_X, center_Y, this.mFaceTextureRegionJump, this.getVertexBufferObjectManager());
scene.attachChild(jump);
return scene;
}
private static class Jump extends AnimatedSprite {
private final PhysicsHandler mPhysicsHandler;
public Jump(final float pX, final float pY, final TiledTextureRegion pTextureRegion, final VertexBufferObjectManger pVertexBufferObjectManager) {
super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
this.mPhysicsHandler = new PhysicsHandler(this);
this.mPhysicsHandler.setVelocityY(JumpSample.DEMO_VELOCITY);
}
@Override
protected void onManagedUpdate(final float pSecondsElapsed) {
....
this.mPhysicsHandler.setVelocityY(JumpSample.DEMO_VELOCITY);//+
this.mPhysicsHandler.setVelocityY(-JumpSample.DEMO_VELOCITY);//-
}
}
....
final Jump jump = new Jump(center_X, center_Y, this.mFaceTextureRegionJump, this.getVertexBufferObjectManager());
scene.attachChild(jump);
return scene;
}
private static class Jump extends AnimatedSprite {
private final PhysicsHandler mPhysicsHandler;
public Jump(final float pX, final float pY, final TiledTextureRegion pTextureRegion, final VertexBufferObjectManger pVertexBufferObjectManager) {
super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
this.mPhysicsHandler = new PhysicsHandler(this);
this.mPhysicsHandler.setVelocityY(JumpSample.DEMO_VELOCITY);
}
@Override
protected void onManagedUpdate(final float pSecondsElapsed) {
....
this.mPhysicsHandler.setVelocityY(JumpSample.DEMO_VELOCITY);//+
this.mPhysicsHandler.setVelocityY(-JumpSample.DEMO_VELOCITY);//-
}
}
피드 구독하기:
글 (Atom)