Advertisement
Guest User

Untitled

a guest
Dec 15th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.24 KB | None | 0 0
  1. package com.example.pandus;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5.  
  6. import org.andengine.engine.camera.Camera;
  7. import org.andengine.engine.options.EngineOptions;
  8. import org.andengine.engine.options.ScreenOrientation;
  9. import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
  10. import org.andengine.entity.scene.Scene;
  11. import org.andengine.entity.sprite.Sprite;
  12. import org.andengine.input.touch.TouchEvent;
  13. import org.andengine.opengl.texture.ITexture;
  14. import org.andengine.opengl.texture.bitmap.BitmapTexture;
  15. import org.andengine.opengl.texture.region.ITextureRegion;
  16. import org.andengine.opengl.texture.region.TextureRegionFactory;
  17. import org.andengine.ui.activity.SimpleBaseGameActivity;
  18. import org.andengine.util.adt.io.in.IInputStreamOpener;
  19. import org.andengine.util.debug.Debug;
  20.  
  21.  
  22.  
  23. import android.content.Intent;
  24. import android.view.Menu;
  25.  
  26. public class Pandus extends SimpleBaseGameActivity {
  27.     private static int CAMERA_WIDTH = 800;
  28.     private static int CAMERA_HEIGHT = 460;
  29.     Intent intent_play;
  30.  
  31.     private  ITextureRegion mbackground_theme, mplay_button;
  32.    
  33.     @Override
  34.     public boolean onCreateOptionsMenu(Menu menu) {
  35.         // Inflate the menu; this adds items to the action bar if it is present.
  36.         getMenuInflater().inflate(R.menu.pandus, menu);
  37.         return true;
  38.     }
  39.  
  40.     @Override
  41.     public EngineOptions onCreateEngineOptions() {
  42.         final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
  43.         return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
  44.             new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
  45.     }
  46.  
  47.     @Override
  48.     protected void onCreateResources() {
  49.         try {
  50.             // 1 - Set up bitmap textures
  51.             ITexture background_theme = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
  52.                 @Override
  53.                 public InputStream open() throws IOException {
  54.                     return getAssets().open("gfx/main_menu.png");
  55.                 }
  56.             });
  57.             ITexture play_button = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
  58.                 @Override
  59.                 public InputStream open() throws IOException {
  60.                     return getAssets().open("gfx/main_play.png");
  61.                 }
  62.             });
  63.          
  64.             // 2 - Load bitmap textures into VRAM
  65.             background_theme.load();
  66.             play_button.load();
  67.  
  68.             this.mbackground_theme = TextureRegionFactory.extractFromTexture(background_theme);
  69.             this.mplay_button = TextureRegionFactory.extractFromTexture(play_button);
  70.            
  71.            
  72.            
  73.         } catch (IOException e) {
  74.             Debug.e(e);
  75.         }      
  76.     }
  77.  
  78.     @Override
  79.     protected Scene onCreateScene() {
  80.         intent_play = new Intent(this, Game.class);
  81.  
  82.         final Scene scene = new Scene();
  83.         Sprite backgroundSprite = new Sprite(0, 0, this.mbackground_theme, getVertexBufferObjectManager());
  84.         Sprite playSprite = new Sprite(300, 140, this.mplay_button, getVertexBufferObjectManager()){
  85.             @Override
  86.             public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
  87.  
  88.                     System.out.println("DOTKNIETY");
  89.                     startActivity(intent_play);
  90.                     return true;
  91.             }
  92.         };
  93.        
  94.         scene.registerTouchArea(playSprite);
  95.         scene.attachChild(backgroundSprite);
  96.         scene.attachChild(playSprite);
  97.         return scene;
  98.     }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement