Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. package com.example.testnew;
  2.  
  3. import org.andengine.opengl.texture.ITexture;
  4. import org.andengine.opengl.texture.bitmap.BitmapTexture;
  5. import org.andengine.opengl.texture.region.ITextureRegion;
  6. import org.andengine.opengl.texture.region.TextureRegionFactory;
  7. import org.andengine.util.adt.io.in.IInputStreamOpener;
  8. import org.andengine.util.debug.Debug;
  9.  
  10. import java.io.IOException;
  11. import java.io.InputStream;
  12.  
  13. import org.andengine.engine.camera.Camera;
  14. import org.andengine.engine.options.EngineOptions;
  15. import org.andengine.engine.options.ScreenOrientation;
  16. import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
  17. import org.andengine.entity.scene.Scene;
  18. import org.andengine.entity.sprite.Sprite;
  19. import org.andengine.ui.activity.SimpleBaseGameActivity;
  20.  
  21.  
  22. import android.os.Bundle;
  23. import android.view.Menu;
  24. import android.view.MenuItem;
  25.  
  26. public class MainActivity extends SimpleBaseGameActivity {
  27.  
  28. private static int CAMERA_WIDTH = 800;
  29. private static int CAMERA_HEIGHT = 480;
  30.  
  31. private ITextureRegion mBackgroundTextureRegion, mTowerTextureRegion, mRing1, mRing2, mRing3;
  32.  
  33. ITexture backgroundTexture,ring1,ring2,ring3,towerTexture;
  34.  
  35.  
  36.  
  37. @Override
  38. public EngineOptions onCreateEngineOptions() {
  39.  
  40. final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
  41.  
  42. return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
  43. new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
  44.  
  45. }
  46.  
  47.  
  48. @Override
  49. protected void onCreateResources() throws IOException {
  50.  
  51. try{
  52.  
  53. ITexture backgroundTexture = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener()
  54. {
  55.  
  56. @Override
  57. public InputStream open() throws IOException
  58. {
  59. //AssetManager Class:-getAsset();
  60. //Provides access to an application's raw asset files
  61. // for the way most applications will want to retrieve their resource data.
  62. return getAssets().open("gfx/background.png");
  63. }
  64. });
  65. ITexture towerTexture = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener()
  66. {
  67. @Override
  68. public InputStream open() throws IOException {
  69. return getAssets().open("gfx/tower.png");
  70. }
  71. });
  72.  
  73. ITexture ring1 = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener()
  74. {
  75. @Override
  76. public InputStream open() throws IOException {
  77. return getAssets().open("gfx/ring1.png");
  78. }
  79. });
  80.  
  81. ITexture ring2 = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener()
  82. {
  83. @Override
  84. public InputStream open() throws IOException {
  85. return getAssets().open("gfx/ring2.png");
  86. }
  87. });
  88.  
  89. ITexture ring3 = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener()
  90. {
  91. @Override
  92. public InputStream open() throws IOException {
  93. return getAssets().open("gfx/ring3.png");
  94. }
  95. });
  96.  
  97. backgroundTexture.load();
  98. towerTexture.load();
  99. ring1.load();
  100. ring2.load();
  101. ring3.load();
  102. } catch (IOException e) {
  103. Debug.e(e);
  104. }
  105.  
  106. this.mBackgroundTextureRegion = TextureRegionFactory.extractFromTexture(backgroundTexture);
  107. this.mTowerTextureRegion = TextureRegionFactory.extractFromTexture(towerTexture);
  108. this.mRing1 = TextureRegionFactory.extractFromTexture(ring1);
  109. this.mRing2 = TextureRegionFactory.extractFromTexture(ring2);
  110.  
  111. mBackgroundTextureRegion.setTextureSize(1600, 1000);
  112. }
  113.  
  114. @Override
  115. protected Scene onCreateScene() {
  116.  
  117. final Scene scene = new Scene();
  118.  
  119. Sprite backgroundSprite = new Sprite(0, 0, this.mBackgroundTextureRegion, getVertexBufferObjectManager());
  120. scene.attachChild(backgroundSprite);
  121.  
  122. return scene;
  123.  
  124. }
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement