Bom dia Rodrigo!
Segue o código: (ele está meio gambs ainda)
import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.AutoParallaxBackground;
import org.andengine.entity.scene.background.ParallaxBackground.ParallaxEntity;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.util.FPSLogger;
import org.andengine.input.touch.TouchEvent;
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.region.ITextureRegion;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.ui.activity.SimpleBaseGameActivity;
public class MainActivity extends SimpleBaseGameActivity {
private static final int CAMERA_WIDTH = 960; //LARGURA DA TELA
private static final int CAMERA_HEIGHT = 720; //ALTURA DA TELA
private BitmapTextureAtlas BTAbackground;
private ITextureRegion ITEback;
private BitmapTextureAtlas mBitmapTextureAtlas;
private ITiledTextureRegion mLekTextureRegion;
private AnimatedSprite player;
@Override
public EngineOptions onCreateEngineOptions() {
final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
}
@Override
protected void onCreateResources() {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); //DIRETÓRIO BASE PARA OS RECURSOS DO GAME
this.BTAbackground = new BitmapTextureAtlas(this.getTextureManager(), 960, 720);
this.ITEback = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.BTAbackground, this, "game_back.png", 0, 0);
this.BTAbackground.load();
this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1536, 135, TextureOptions.DEFAULT);
this.mLekTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "spr_lek.png", 0, 0, 15, 1);
this.mBitmapTextureAtlas.load();
}
@Override
protected Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);
final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, CAMERA_HEIGHT - this.ITEback.getHeight(), this.ITEback, vertexBufferObjectManager)));
scene.setBackground(autoParallaxBackground);
/* Calculate the coordinates for the face, so its centered on the camera. */
final float playerX = (CAMERA_WIDTH - this.mLekTextureRegion.getWidth()) / 2;
final float playerY = CAMERA_HEIGHT - this.mLekTextureRegion.getHeight() - 5;
final TimerHandler mDelayTimeHandler = new TimerHandler(200, new DelayTimerCallback());
/* Create two sprits and add it to the scene. */
player = new AnimatedSprite(250, 250, this.mLekTextureRegion, vertexBufferObjectManager) {
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
//this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
this.setVisible(false);
mDelayTimeHandler.reset(); //ative o timer
return true;
}
};
final AnimatedSprite player1 = new AnimatedSprite(450, 350, this.mLekTextureRegion, vertexBufferObjectManager) {
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
//this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
this.setVisible(false);
return true;
}
};
player.setScaleCenterY(this.mLekTextureRegion.getHeight());
player.setScale(1.5f);
player.animate(new long[]{150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150}, 0, 14, true);
player1.setScaleCenterY(this.mLekTextureRegion.getHeight());
player1.setScale(1.5f);
player1.animate(new long[]{150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150}, 0, 14, true);
scene.attachChild(player);
scene.registerTouchArea(player);
scene.attachChild(player1);
scene.registerTouchArea(player1);
scene.registerUpdateHandler(mDelayTimeHandler);
mDelayTimeHandler.setTimerCallbackTriggered(true);
scene.setTouchAreaBindingOnActionDownEnabled(true);
return scene;
}
private class DelayTimerCallback implements ITimerCallback{
@Override
public void onTimePassed(TimerHandler pTimerHandler) {
player.setVisible(true);
}
}
}
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.






0 comentários:
Postar um comentário