コード例 #1
0
  @Override
  public void onLoadScene() {
    // mCurrentBoss = 1;
    // SFXManager.getInstance().loadSound("t_ko", ResourceManager.getActivity().getSoundManager(),
    // ResourceManager.getActivity());
    System.out.println("mCurrentBoss --> " + mCurrentBoss);
    Sprite themeBGSprite = new Sprite(0f, 0f, ResourceManager.themeBG, mVertexBufferObjectManager);
    // themeBGSprite.setScale(ResourceManager.getInstance().cameraHeight /
    // ResourceManager.themeBG.getHeight());
    themeBGSprite.setSize(mCameraWidth, mCameraHeight);
    themeBGSprite.setPosition(mCameraWidth / 2f, mCameraHeight / 2f);
    themeBGSprite.setZIndex(-90);
    attachChild(themeBGSprite);

    if (mScrollDetector == null) {
      mScrollDetector = new SurfaceScrollDetector(this);
    }
    mScrollDetector.setTriggerScrollMinimumDistance(10f);
    mBossSlider = getScensSlider();
    attachChild(mBossSlider);
    if (isKO) {
      themeRInitX = themeRInitX - mCameraWidth * (mCurrentBoss - 1);
      // mBossSlider.registerEntityModifier(new MoveXModifier(0.3F, mBossSlider.getX(),
      // themeRInitX));
      mBossSlider.setX(themeRInitX);
    }

    // 后退按钮
    ButtonSprite backBS =
        new ButtonSprite(0f, 0f, ResourceManager.backTR, mVertexBufferObjectManager);
    EntityUtil.setSize("height", 1f / 8f, backBS);
    backBS.setPosition(10f + backBS.getWidth() / 2f, mCameraHeight - 10f - backBS.getHeight() / 2f);
    attachChild(backBS);
    backBS.setOnClickListener(
        new org.andengine.entity.sprite.ButtonSprite.OnClickListener() {

          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            SceneManager.getInstance().showScene(ThemeScene.getInstance());
          }
        });
    registerTouchArea(backBS);

    // 主页按钮
    ButtonSprite homeBS =
        new ButtonSprite(0f, 0f, ResourceManager.homeTR, mVertexBufferObjectManager);
    homeBS.setSize(backBS.getWidth(), backBS.getHeight());
    homeBS.setPosition(mCameraWidth - 10f - homeBS.getWidth() / 2f, backBS.getY());
    attachChild(homeBS);
    homeBS.setOnClickListener(
        new org.andengine.entity.sprite.ButtonSprite.OnClickListener() {

          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            SceneManager.getInstance().showScene(MainMenuScene.getInstance());
          }
        });
    registerTouchArea(homeBS);

    // 向左箭头
    ButtonSprite arrowLeftSprite =
        new ButtonSprite(
            0f, 0f, ResourceManager.arrowLRTTR.getTextureRegion(0), mVertexBufferObjectManager);
    EntityUtil.setSize("height", 1f / 8f, arrowLeftSprite);
    arrowLeftSprite.setPosition(backBS.getX(), mCameraHeight / 2f);
    attachChild(arrowLeftSprite);
    arrowLeftSprite.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            mBossSlider.clearEntityModifiers();
            if (mCurrentBoss == 1) {
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(0.3F, mBossSlider.getX(), mBossSlider.getWidth() / 2f));
            } else {
              mCurrentBoss--;
              themeRInitX = themeRInitX + mCameraWidth;
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(0.3F, mBossSlider.getX(), themeRInitX));
            }
            System.out.println("mCurrentBoss --> " + mCurrentBoss);
          }
        });
    registerTouchArea(arrowLeftSprite);
    // 向右箭头
    ButtonSprite arrowRightSprite =
        new ButtonSprite(
            0f, 0f, ResourceManager.arrowLRTTR.getTextureRegion(1), mVertexBufferObjectManager);
    arrowRightSprite.setSize(arrowLeftSprite.getWidth(), arrowLeftSprite.getHeight());
    arrowRightSprite.setPosition(homeBS.getX(), mCameraHeight / 2f);
    attachChild(arrowRightSprite);
    arrowRightSprite.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            SFXManager.getInstance().playSound("a_click");
            mBossSlider.clearEntityModifiers();
            if (mCurrentBoss == bossPics.length) {
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(
                      0.3F,
                      mBossSlider.getX(),
                      mBossSlider.getWidth() / 2f - mCameraWidth * (bossPics.length - 1)));
            } else {
              mCurrentBoss++;
              themeRInitX = themeRInitX - mCameraWidth;
              mBossSlider.registerEntityModifier(
                  new MoveXModifier(0.3F, mBossSlider.getX(), themeRInitX));
            }
            System.out.println("mCurrentBoss --> " + mCurrentBoss);
          }
        });
    registerTouchArea(arrowRightSprite);
  }
コード例 #2
0
  /**
   * BOSS滑块
   *
   * @author zuowhat 2013-11-25
   * @since 1.0
   */
  private Rectangle getScensSlider() {
    bossPics = new AnimatedButtonSprite[ResourceManager.mxdBoss_TTRArray.length];
    Sprite[] bossBlackBG = new Sprite[bossPics.length];
    // Sprite[] bossInfo = new Sprite[bossPics.length];
    float themeRWidth = mCameraWidth * bossPics.length;
    themeRInitX = themeRWidth / 2f;
    Rectangle themeR =
        new Rectangle(
            themeRWidth / 2f,
            mCameraHeight / 2f,
            themeRWidth,
            mCameraHeight * (2f / 3f),
            mVertexBufferObjectManager);
    themeR.setAlpha(0f);
    int themeSceneOneBossTotal =
        BangYouScreenActivity.getIntFromSharedPreferences(DataConstant.SHARED_PREFS_THEME_MXD);
    for (int i = 0; i < ResourceManager.mxdBoss_TTRArray.length; i++) {
      if (i < themeSceneOneBossTotal) {
        if (isKO) {
          if (i != (mCurrentBoss - 1)) {
            // KO标志
            Sprite s = new Sprite(0f, 0f, ResourceManager.ko, mVertexBufferObjectManager);
            EntityUtil.setSize("width", 1f / 4f, s);
            s.setPosition((i + 1f / 2f) * mCameraWidth, themeR.getHeight() / 2f);
            themeR.attachChild(s);
          } else {
            // KO动画
            Sprite s = new Sprite(0f, 0f, ResourceManager.ko, mVertexBufferObjectManager);
            EntityUtil.setSize("width", 1f / 4f, s);
            s.setPosition((i + 1f / 2f) * mCameraWidth, themeR.getHeight() / 2f);
            themeR.attachChild(s);
            ScaleAtModifier highestPicScale =
                new ScaleAtModifier(0.5f, 25f, 1f, 0.5f, 0.5f); // 实体缩放
            FadeInModifier highestPicFadeIn = new FadeInModifier(0.5f); // 在0.5秒内改变透明度由0f变为1f
            ParallelEntityModifier highestPicParalle =
                new ParallelEntityModifier(
                    new IEntityModifierListener() {

                      @Override
                      public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
                        SFXManager.getInstance().playSound("t_ko");
                      }

                      @Override
                      public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
                        // TODO Auto-generated method stub

                      }
                    },
                    highestPicScale,
                    highestPicFadeIn); // 同时执行修饰符
            s.registerEntityModifier(highestPicParalle);
          }
        } else {
          // KO标志
          Sprite s = new Sprite(0f, 0f, ResourceManager.ko, mVertexBufferObjectManager);
          EntityUtil.setSize("width", 1f / 4f, s);
          s.setPosition((i + 1f / 2f) * mCameraWidth, themeR.getHeight() / 2f);
          themeR.attachChild(s);
        }
      }
      if (ResourceManager.mxdBoss_TTRArray[i] != null) {

        // BOSS动画
        bossPics[i] =
            new AnimatedButtonSprite(
                0f, 0f, ResourceManager.mxdBoss_TTRArray[i], mVertexBufferObjectManager);
        EntityUtil.setSize("height", 1f / 2f, bossPics[i]);
        // BOSS简介
        // bossInfo[i] = new Sprite(0f, 0f,ResourceManager.mxdBoss_InfoTRArray[i],
        // mVertexBufferObjectManager);
        // EntityUtil.setSize("height", 1f/2f, bossInfo[i]);
        if (i == 0) {
          bossPics[i].setPosition(mCameraWidth / 4f, themeR.getHeight() / 2f);
          // bossInfo[i].setPosition(3f*mCameraWidth/4f, themeR.getHeight()/2f);
        }
        if (i == 7) {
          long[] frameDur = new long[2];
          Arrays.fill(frameDur, 300);
          bossPics[i].animate(frameDur, 0, 1, true);
        } else {
          bossPics[i].animate(100, true);
        }

        bossPics[i].setOnClickListenerABS(
            new OnClickListenerABS() {
              @Override
              public void onClick(
                  AnimatedButtonSprite pButtonSprite,
                  float pTouchAreaLocalX,
                  float pTouchAreaLocalY) {
                SFXManager.getInstance().playSound("a_click");
                SFXManager.getInstance().stopMusic();
                SceneManager.getInstance()
                    .showScene(
                        new GameLevel(
                            DataConstant.getMXDBoss(mCurrentBoss), DataConstant.getPlayerModel()));
              }
            });
        // BOSS图片和简介的位置
        if (i > 0) {
          bossPics[i].setPosition(mCameraWidth + bossPics[i - 1].getX(), themeR.getHeight() / 2f);
          // bossInfo[i].setPosition(mCameraWidth+bossInfo[i-1].getX(), themeR.getHeight()/2f);
        }
        themeR.attachChild(bossPics[i]);
        registerTouchArea(bossPics[i]);
        // themeR.attachChild(bossInfo[i]);
      } else {
        bossBlackBG[i] =
            new Sprite(
                0f,
                0f,
                ResourceManager.bossBlackBG.getTextureRegion(i),
                mVertexBufferObjectManager);
        EntityUtil.setSize("height", 1f / 2f, bossBlackBG[i]);
        bossBlackBG[i].setPosition(mCameraWidth * (i + 1f / 4f), themeR.getHeight() / 2f);

        switch (i) {
          case 0:
            break;

          case 1:
            break;
        }
        themeR.attachChild(bossBlackBG[i]);
      }
    }

    return themeR;
  }