コード例 #1
0
  @Override
  public void onDestroy() {
    if (BuildConfig.DEBUG) {
      Debug.d(
          this.getClass().getSimpleName()
              + ".onDestroy"
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')");
    }

    super.onDestroy();

    this.mEngine.onDestroy();

    try {
      this.onDestroyResources();
    } catch (final Throwable pThrowable) {
      Debug.e(
          this.getClass().getSimpleName()
              + ".onDestroyResources failed."
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')",
          pThrowable);
    }

    this.onGameDestroyed();

    this.mEngine = null;
  }
コード例 #2
0
  private void applyEngineOptions() {
    final EngineOptions engineOptions = this.mEngine.getEngineOptions();

    if (engineOptions.isFullscreen()) {
      // ActivityUtils.requestFullscreen(getActivity());
    }

    if (engineOptions.getAudioOptions().needsMusic()
        || engineOptions.getAudioOptions().needsSound()) {
      getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }

    switch (engineOptions.getScreenOrientation()) {
      case LANDSCAPE_FIXED:
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        break;
      case LANDSCAPE_SENSOR:
        if (SystemUtils.SDK_VERSION_GINGERBREAD_OR_LATER) {
          getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
          Debug.w(
              ScreenOrientation.class.getSimpleName()
                  + "."
                  + ScreenOrientation.LANDSCAPE_SENSOR
                  + " is not supported on this device. Falling back to "
                  + ScreenOrientation.class.getSimpleName()
                  + "."
                  + ScreenOrientation.LANDSCAPE_FIXED);
          getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
        break;
      case PORTRAIT_FIXED:
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        break;
      case PORTRAIT_SENSOR:
        if (SystemUtils.SDK_VERSION_GINGERBREAD_OR_LATER) {
          getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {
          Debug.w(
              ScreenOrientation.class.getSimpleName()
                  + "."
                  + ScreenOrientation.PORTRAIT_SENSOR
                  + " is not supported on this device. Falling back to "
                  + ScreenOrientation.class.getSimpleName()
                  + "."
                  + ScreenOrientation.PORTRAIT_FIXED);
          getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        break;
    }
  }
コード例 #3
0
ファイル: MenuScene.java プロジェクト: rattipal/Dhadi
  @Override
  public void loadScene() {

    menuTextureAtlas =
        new BuildableBitmapTextureAtlas(
            activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    menu_background_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            menuTextureAtlas, activity, "menu_background.png");
    play_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            menuTextureAtlas, activity, "play.png");
    options_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            menuTextureAtlas, activity, "options.png");

    try {
      this.menuTextureAtlas.build(
          new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));

    } catch (TextureAtlasBuilderException e) {
      Debug.e(e);
    }
    this.menuTextureAtlas.load();
  }
コード例 #4
0
  public EngineOptions onCreateEngineOptions() {

    android.os.Debug.waitForDebugger();

    // Debug.setDebugLevel(DebugLevel.NONE);
    // Toast.makeText(this, "You move my sprite right round, right round...",
    // Toast.LENGTH_LONG).show();
    Debug.d("toast", "onCreateEngineOptions");

    final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    EngineOptions options =
        new EngineOptions(
            true,
            ScreenOrientation.LANDSCAPE_FIXED,
            new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
            camera);
    // EngineOptions options = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new
    // FillResolutionPolicy(), camera);
    options.getAudioOptions().setNeedsSound(true);
    options.getAudioOptions().setNeedsMusic(true);

    // getApplication().getWallpaperDesiredMinimumHeight()
    // DisplayMetrics metrics = getWindowManager().getDefaultDisplay().getMetrics(new
    // DisplayMetrics());

    return options;
  }
コード例 #5
0
ファイル: Button.java プロジェクト: nazgee/AndEngineLimbo
  // ===========================================================
  // Methods
  // ===========================================================
  public void changeState(final State pState) {
    if (pState == this.mState) {
      return;
    }

    final IEntity pNewFace = this.mEntities[pState.getEntityIndex()];
    final IEntity pOldFace = this.mEntities[this.mState.getEntityIndex()];
    this.mState = pState;

    detachChild(pOldFace);
    detachChild(pNewFace);
    if (pNewFace == null) {
      attachDefaultFace();
      Debug.w(
          this.getClass().getSimpleName()
              + " changed its "
              + State.class.getSimpleName()
              + " to "
              + pState.toString()
              + ", which doesn't have an "
              + IEntity.class.getSimpleName()
              + " supplied. Applying default "
              + IEntity.class.getSimpleName()
              + ".");
    } else {
      attachChild(pNewFace);
    }
    sortChildren(false);
  }
コード例 #6
0
  private void loadGameGraphics() {

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/game/");
    gameTextureAtlas =
        new BuildableBitmapTextureAtlas(
            activity.getTextureManager(),
            1024,
            1024,
            TextureOptions.REPEATING_NEAREST_PREMULTIPLYALPHA);
    rockTop_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            gameTextureAtlas, activity, "Red_Rock_Top.png");
    rockMid_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            gameTextureAtlas, activity, "Red_Rock_Middle.png");
    rockOre_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            gameTextureAtlas, activity, "Ore_Rock.png");
    player_region =
        BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(
            gameTextureAtlas, activity, "player.png", 1, 1);
    dpad_region =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            gameTextureAtlas, activity, "Dpad_Notpressed.png");
    try {
      this.gameTextureAtlas.build(
          new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 0));
      this.gameTextureAtlas.load();
    } catch (final TextureAtlasBuilderException e) {
      Debug.e(e);
    }
  }
コード例 #7
0
    public ParallaxEntity(final float pParallaxFactor, final IEntity pEntity) {
      this.mParallaxFactor = pParallaxFactor;
      this.mEntity = pEntity;

      // TODO Adjust onDraw calculations, so that these assumptions aren't necessary.
      if (this.mEntity.getX() != 0) {
        Debug.w("The X position of a " + this.getClass().getSimpleName() + " is expected to be 0.");
      }

      if (this.mEntity.getOffsetCenterX() != 0) {
        Debug.w(
            "The OffsetCenterXposition of a "
                + this.getClass().getSimpleName()
                + " is expected to be 0.");
      }
    }
コード例 #8
0
  @Override
  public synchronized void onSurfaceCreated(final GLState pGLState) {
    if (BuildConfig.DEBUG) {
      Debug.d(
          this.getClass().getSimpleName()
              + ".onSurfaceCreated"
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')");
    }

    if (this.mGameCreated) {
      this.onReloadResources();

      if (this.mGamePaused && this.mGameCreated) {
        this.onResumeGame();
      }
    } else {
      if (this.mCreateGameCalled) {
        this.mOnReloadResourcesScheduled = true;
      } else {
        this.mCreateGameCalled = true;
        this.onCreateGame();
      }
    }
  }
コード例 #9
0
  public void onCreateResources() {
    Debug.d("toast", "onCreateResources");
    this.game = new StarWarsGame(this.getEngine(), this);
    this.game.onCreateResources();

    soundLibrary = new SoundLibrary(mEngine.getSoundManager(), this);
    this.mEngine.registerUpdateHandler(soundLibrary);
  }
コード例 #10
0
  public void onTapFromGame(TouchEvent event) {
    Debug.d("tap on " + event.getX() + "x" + event.getY());

    //		SoundLibrary.playSample(Sample.LASER); //AG: lo he movido a TouchProcess

    //		SoundLibrary.playSample(Sample.CHEWAKA);
    //		SoundLibrary.stopSample(Sample.CHEWAKA, true, 2);
  }
コード例 #11
0
 public Sound createSound(String soundFileName) {
   Sound sound = null;
   try {
     sound = SoundFactory.createSoundFromAsset(engine.getSoundManager(), context, soundFileName);
   } catch (final IOException e) {
     Debug.e(e);
   }
   return sound;
 }
コード例 #12
0
 @Override
 protected void onReadTransmissionData(final DataInputStream pDataInputStream) throws IOException {
   ObjectInputStream reader = new ObjectInputStream(pDataInputStream);
   try {
     this.mServerList = (HashMap<String, GameServer>) reader.readObject();
   } catch (ClassNotFoundException e) {
     Debug.e(e);
   }
 }
 @Override
 public void onTerminated(final ServerConnector<BluetoothSocketConnection> pServerConnector) {
   Debug.d(
       "Closed Server-Connection from: '"
           + pServerConnector
               .getConnection()
               .getBluetoothSocket()
               .getRemoteDevice()
               .getAddress());
 }
コード例 #14
0
  public Scene onCreateScene() {
    Debug.d("toast", "onCreateScene");

    this.mEngine.registerUpdateHandler(new FPSLogger());
    Scene initialScene = this.game.onCreateScene();

    this.starWarsScene = this.game.starWarsScene;

    return initialScene;
  }
コード例 #15
0
  @Override
  protected Scene onCreateScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());
    // TODO Auto-generated method stub
    scene = new Scene();
    try {
      final TMXLoader tmxLoader =
          new TMXLoader(
              this.getAssets(),
              this.mEngine.getTextureManager(),
              TextureOptions.BILINEAR_PREMULTIPLYALPHA,
              this.getVertexBufferObjectManager(),
              new ITMXTilePropertiesListener() {
                @Override
                public void onTMXTileWithPropertiesCreated(
                    final TMXTiledMap pTMXTiledMap,
                    final TMXLayer pTMXLayer,
                    final TMXTile pTMXTile,
                    final TMXProperties<TMXTileProperty> pTMXTileProperties) {}
              });
      this.mTMXTiledMap = tmxLoader.loadFromAsset("tmx/map_pro.tmx");

    } catch (final TMXLoadException e) {
      Debug.e(e);
    }
    final TMXLayer tmxLayer = this.mTMXTiledMap.getTMXLayers().get(0);

    scene.attachChild(tmxLayer);

    /* Make the camera not exceed the bounds of the TMXEntity. */
    this.mBoundChaseCamera.setBounds(0, 0, tmxLayer.getHeight(), tmxLayer.getWidth());
    this.mBoundChaseCamera.setBoundsEnabled(true);

    final float centerX = (MyCamera.CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
    final float centerY = (MyCamera.CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
    face =
        new Sprite(centerX, centerY, this.mFaceTextureRegion, this.getVertexBufferObjectManager());

    scene.attachChild(face);

    // Add playerSprite to screen
    initplayerSprite(scene, this.mPlayerTextureRegion);

    // Scene UpdateHandler

    scene.setTouchAreaBindingOnActionDownEnabled(true);
    scene.setOnAreaTouchListener(pOnAreaTouchListener);
    scene.registerUpdateHandler(pUpdateHandler);
    scene.registerTouchArea(tmxLayer);
    scene.setOnSceneTouchListener(pOnSceneTouchListener);
    return scene;
  }
コード例 #16
0
  @Override
  public synchronized void onGameDestroyed() {
    if (BuildConfig.DEBUG) {
      Debug.d(
          this.getClass().getSimpleName()
              + ".onGameDestroyed"
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')");
    }

    this.mGameCreated = false;
  }
コード例 #17
0
  @Override
  public void onReloadResources() {
    if (BuildConfig.DEBUG) {
      Debug.d(
          this.getClass().getSimpleName()
              + ".onReloadResources"
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')");
    }

    this.mEngine.onReloadResources();
  }
コード例 #18
0
ファイル: Scores.java プロジェクト: anod/SeaMerchantAndroid
 public void writeScore(Context ctx) {
   DataOutputStream out;
   try {
     out = new DataOutputStream(ctx.openFileOutput(FILENAME, Context.MODE_APPEND));
     out.writeInt(getScore());
     out.writeChar(' ');
     out.writeUTF(mName);
     out.flush();
     out.close();
   } catch (IOException e) {
     Debug.e(e);
   }
 }
コード例 #19
0
  @Override
  public synchronized void onResumeGame() { // esto viene despues de reload resources
    // Toast.makeText(this, "onResumeGame", Toast.LENGTH_LONG).show();
    Debug.d("toast", "onResumeGame");

    game.onResumeGame();

    super.onResumeGame();
    //		TimerHelper.startTimer(mEngine.getScene(), 2f,  new ITimerCallback() {
    //			public void onTimePassed(final TimerHandler pTimerHandler){
    //				restartEngine();
    //			}
    //		});
  }
コード例 #20
0
  @Override
  public Bitmap onLoadBitmap(final Config pBitmapConfig) {
    final Bitmap bitmap =
        this.ensureLoadedBitmapIsMutable(
            this.mBitmapTextureAtlasSource.onLoadBitmap(pBitmapConfig));

    final Canvas canvas = new Canvas(bitmap);
    try {
      this.onDecorateBitmap(canvas);
    } catch (final Exception e) {
      Debug.e(e);
    }
    return bitmap;
  }
コード例 #21
0
ファイル: ThreadUtils.java プロジェクト: ESal0/AndroidGame
 private static void dumpCurrentThreadInfo(
     final DebugLevel pDebugLevel, final StackTraceElement pCaller) {
   Debug.log(
       pDebugLevel,
       pCaller.getClassName()
           + "."
           + pCaller.getMethodName()
           + "("
           + pCaller.getFileName()
           + ".java:"
           + pCaller.getLineNumber()
           + ") @(Thread: '"
           + Thread.currentThread().getName()
           + "')");
 }
コード例 #22
0
  @Override
  public synchronized void onPauseGame() {
    if (BuildConfig.DEBUG) {
      Debug.d(
          this.getClass().getSimpleName()
              + ".onPauseGame"
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')");
    }

    this.mGamePaused = true;

    this.mEngine.stop();
  }
コード例 #23
0
 @Override
 public synchronized void onSurfaceChanged(
     final GLState pGLState, final int pWidth, final int pHeight) {
   if (BuildConfig.DEBUG) {
     Debug.d(
         this.getClass().getSimpleName()
             + ".onSurfaceChanged(Width="
             + pWidth
             + ",  Height="
             + pHeight
             + ")"
             + " @(Thread: '"
             + Thread.currentThread().getName()
             + "')");
   }
 }
コード例 #24
0
ファイル: TestActivity2.java プロジェクト: begerter/aeon
  @Override
  protected void onCreateResources() {
    try {
      final TMXLoader tmxLoader =
          new TMXLoader(
              getAssets(),
              getTextureManager(),
              TextureOptions.NEAREST,
              getVertexBufferObjectManager());
      this.tiledMap = tmxLoader.loadFromAsset("TileMap_new.tmx");

      // this.tiledMap.setIsometricDrawMethod(TMXConstants.DRAW_METHOD_ISOMETRIC_CULLING_PADDING);
    } catch (final TMXLoadException e) {
      Debug.e(e);
    }
  }
コード例 #25
0
 private void acquireWakeLock(final WakeLockOptions pWakeLockOptions) {
   if (pWakeLockOptions == WakeLockOptions.SCREEN_ON) {
     ActivityUtils.keepScreenOn(getActivity());
   } else {
     final PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
     this.mWakeLock =
         pm.newWakeLock(
             pWakeLockOptions.getFlag() | PowerManager.ON_AFTER_RELEASE, Constants.DEBUGTAG);
     try {
       this.mWakeLock.acquire();
     } catch (final SecurityException pSecurityException) {
       Debug.e(
           "You have to add\n\t<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>\nto your AndroidManifest.xml !",
           pSecurityException);
     }
   }
 }
コード例 #26
0
  private void onHandleAverageDurationElapsed() {
    if (BuildConfig.DEBUG) {
      final int texturesLoadedCount = this.mTextureManager.getTexturesLoadedCount();
      final int textureMemoryUsed = this.mTextureManager.getTextureMemoryUsed();

      this.mTexturesLoadedCountMax = Math.max(texturesLoadedCount, this.mTexturesLoadedCountMax);
      this.mTextureMemoryUsedMax = Math.max(textureMemoryUsed, this.mTextureMemoryUsedMax);

      Debug.log(
          this.mDebugLevel,
          String.format(
              "MEM: %d kB in %d textures (MAX: %d kB in %d textures)",
              textureMemoryUsed,
              texturesLoadedCount,
              this.mTextureMemoryUsedMax,
              this.mTexturesLoadedCountMax));
    }
  }
コード例 #27
0
  @Override
  public synchronized void onResume() {
    if (BuildConfig.DEBUG) {
      Debug.d(
          this.getClass().getSimpleName()
              + ".onResume"
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')");
    }

    super.onResume();

    this.acquireWakeLock();
    this.mRenderSurfaceView.onResume();
    if ((this.mGamePaused) && (this.mGameCreated)) {
      onResumeGame();
    }
  }
コード例 #28
0
  @Override
  public void onDestroyResources() throws Exception {
    if (BuildConfig.DEBUG) {
      Debug.d(
          this.getClass().getSimpleName()
              + ".onDestroyResources"
              + " @(Thread: '"
              + Thread.currentThread().getName()
              + "')");
    }

    if (this.mEngine.getEngineOptions().getAudioOptions().needsMusic()) {
      this.getMusicManager().releaseAll();
    }

    if (this.mEngine.getEngineOptions().getAudioOptions().needsSound()) {
      this.getSoundManager().releaseAll();
    }
  }
コード例 #29
0
 @Override
 public synchronized void onGameCreated() {
   this.mGameCreated = true;
   if (this.mOnReloadResourcesScheduled) {
     this.mOnReloadResourcesScheduled = false;
     try {
       this.onReloadResources();
     } catch (final Throwable pThrowable) {
       Debug.e(
           this.getClass().getSimpleName()
               + ".onReloadResources failed."
               + " @(Thread: '"
               + Thread.currentThread().getName()
               + "')",
           pThrowable);
     }
   }
   loadKaraokeComplete();
 }
コード例 #30
0
  @Override
  public void load(Context context, Engine engine) {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/main-menu/");

    BuildableBitmapTextureAtlas bitmapTextureAtlas =
        new BuildableBitmapTextureAtlas(
            engine.getTextureManager(),
            1024,
            1024,
            BitmapTextureFormat.RGBA_8888,
            TextureOptions.BILINEAR);

    backgroundTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "background.png");
    titleTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "title.png");
    easyUnlockTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "easy_unlock.png");
    normalUnlockTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "normal_unlock.png");
    hardUnlockTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "hard_unlock.png");
    normalLockTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "normal_lock.png");
    hardLockTextureRegion =
        BitmapTextureAtlasTextureRegionFactory.createFromAsset(
            bitmapTextureAtlas, context, "hard_lock.png");

    try {
      bitmapTextureAtlas.build(
          new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 0));
      bitmapTextureAtlas.load();
    } catch (TextureAtlasBuilderException e) {
      Debug.e(e);
    }
  }