Advertisement
Guest User

pandus

a guest
Dec 15th, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.85 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.camera.SmoothCamera;
  8. import org.andengine.engine.options.EngineOptions;
  9. import org.andengine.engine.options.ScreenOrientation;
  10. import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
  11. import org.andengine.entity.scene.Scene;
  12. import org.andengine.entity.scene.background.AutoParallaxBackground;
  13. import org.andengine.entity.scene.background.ParallaxBackground;
  14. import org.andengine.entity.scene.background.ParallaxBackground.ParallaxEntity;
  15. import org.andengine.entity.sprite.Sprite;
  16. import org.andengine.entity.util.FPSLogger;
  17. import org.andengine.opengl.texture.ITexture;
  18. import org.andengine.opengl.texture.bitmap.BitmapTexture;
  19. import org.andengine.opengl.texture.region.ITextureRegion;
  20. import org.andengine.opengl.texture.region.TextureRegion;
  21. import org.andengine.opengl.texture.region.TextureRegionFactory;
  22. import org.andengine.ui.activity.SimpleBaseGameActivity;
  23. import org.andengine.util.adt.io.in.IInputStreamOpener;
  24. import org.andengine.util.debug.Debug;
  25.  
  26.  
  27. public class Game extends SimpleBaseGameActivity {
  28.     private static int CAMERA_WIDTH = 800;
  29.     private static int CAMERA_HEIGHT = 460;
  30.    
  31.     private SmoothCamera camera;
  32.    
  33.     private  TextureRegion mrace_theme, mrace_marks;
  34.     ParallaxLayer parallaxLayer = new ParallaxLayer(camera, true, 4000);
  35.  
  36.    
  37.     @Override
  38.     public EngineOptions onCreateEngineOptions() {
  39.         final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
  40.         return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
  41.             new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
  42.     }
  43.  
  44.     @Override
  45.     protected void onCreateResources() {
  46.         try {
  47.             // 1 - Set up bitmap textures
  48.             ITexture race_theme = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
  49.                 @Override
  50.                 public InputStream open() throws IOException {
  51.                     return getAssets().open("gfx/race_road.png");
  52.                 }
  53.             });
  54.             ITexture race_marks = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
  55.                 @Override
  56.                 public InputStream open() throws IOException {
  57.                     return getAssets().open("gfx/race_marks.png");
  58.                 }
  59.             });
  60.            
  61.          
  62.             // 2 - Load bitmap textures into VRAM
  63.             race_theme.load();
  64.             race_marks.load();
  65.             //this.mrace_theme = TextureRegionFactory.extractFromTexture(race_theme);
  66.             //this.mrace_marks = TextureRegionFactory.extractFromTexture(race_marks);
  67.            
  68.             //BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTorTexture, this, "wyscigi_tlo.png",0,0);
  69.  
  70.            
  71.             /*this.mTorTexture = new BitmapTextureAtlas(this.getTextureManager(), 1024,1024, TextureOptions.BILINEAR);
  72.         this.mTorTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTorTexture, this, "wyscigi_tlo.png",0,0);
  73.         this.mTorTexture.load();*/
  74.         } catch (IOException e) {
  75.             Debug.e(e);
  76.         }  
  77.     }
  78.  
  79.     @Override
  80.     protected Scene onCreateScene() {
  81.         Scene scene = new Scene();
  82.         ParallaxLayer parallaxLayer = new ParallaxLayer(camera, true, 4000);
  83.        
  84.         Sprite Srace_theme = new Sprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, (ITextureRegion)mrace_theme, this.getVertexBufferObjectManager());
  85.         Sprite Srace_marks = new Sprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, mrace_marks, this.getVertexBufferObjectManager());
  86.  
  87.        
  88.         parallaxLayer.setParallaxChangePerSecond(1);
  89.         parallaxLayer.setParallaxScrollFactor(0);
  90.        
  91.         parallaxLayer.attachParallaxEntity(new ParallaxEntity(0, Srace_marks));
  92.         //The method attachParallaxEntity(ParallaxLayer.ParallaxEntity) in the type ParallaxLayer is not applicable for the arguments (ParallaxBackground.ParallaxEntity)
  93.  
  94.         scene.attachChild(parallaxLayer);
  95.  
  96.  
  97.         return scene;
  98.     }
  99.  
  100.    
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement