Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.pandus;
- import java.io.IOException;
- import java.io.InputStream;
- 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.scene.Scene;
- import org.andengine.entity.sprite.Sprite;
- import org.andengine.input.touch.TouchEvent;
- import org.andengine.opengl.texture.ITexture;
- import org.andengine.opengl.texture.bitmap.BitmapTexture;
- import org.andengine.opengl.texture.region.ITextureRegion;
- import org.andengine.opengl.texture.region.TextureRegionFactory;
- import org.andengine.ui.activity.SimpleBaseGameActivity;
- import org.andengine.util.adt.io.in.IInputStreamOpener;
- import org.andengine.util.debug.Debug;
- import android.content.Intent;
- import android.view.Menu;
- public class Pandus extends SimpleBaseGameActivity {
- private static int CAMERA_WIDTH = 800;
- private static int CAMERA_HEIGHT = 460;
- Intent intent_play;
- private ITextureRegion mbackground_theme, mplay_button;
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.pandus, menu);
- return true;
- }
- @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() {
- try {
- // 1 - Set up bitmap textures
- ITexture background_theme = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
- @Override
- public InputStream open() throws IOException {
- return getAssets().open("gfx/main_menu.png");
- }
- });
- ITexture play_button = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
- @Override
- public InputStream open() throws IOException {
- return getAssets().open("gfx/main_play.png");
- }
- });
- // 2 - Load bitmap textures into VRAM
- background_theme.load();
- play_button.load();
- this.mbackground_theme = TextureRegionFactory.extractFromTexture(background_theme);
- this.mplay_button = TextureRegionFactory.extractFromTexture(play_button);
- } catch (IOException e) {
- Debug.e(e);
- }
- }
- @Override
- protected Scene onCreateScene() {
- intent_play = new Intent(this, Game.class);
- final Scene scene = new Scene();
- Sprite backgroundSprite = new Sprite(0, 0, this.mbackground_theme, getVertexBufferObjectManager());
- Sprite playSprite = new Sprite(300, 140, this.mplay_button, getVertexBufferObjectManager()){
- @Override
- public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
- System.out.println("DOTKNIETY");
- startActivity(intent_play);
- return true;
- }
- };
- scene.registerTouchArea(playSprite);
- scene.attachChild(backgroundSprite);
- scene.attachChild(playSprite);
- return scene;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement