@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
  @Override
  public void onLoadScene() {
    // Load the menu resources
    ResourceManager.loadMenuResources();

    // Create the background
    BackgroundSprite =
        new Sprite(
            ResourceManager.getInstance().cameraWidth / 2f,
            ResourceManager.getInstance().cameraHeight / 2f,
            ResourceManager.menuBackgroundTextureRegion,
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    BackgroundSprite.setScaleX(ResourceManager.getInstance().cameraWidth);
    BackgroundSprite.setScaleY(ResourceManager.getInstance().cameraHeight / 480f);
    BackgroundSprite.setZIndex(-5000);
    this.attachChild(BackgroundSprite);

    // Create clouds that move from one side of the screen to the other, and repeat.
    CloudSprites = new Sprite[20];
    for (Sprite curCloudSprite : CloudSprites) {
      curCloudSprite =
          new Sprite(
              MathUtils.random(
                  -(this.getWidth() * this.getScaleX()) / 2,
                  ResourceManager.getInstance().cameraWidth
                      + (this.getWidth() * this.getScaleX()) / 2),
              MathUtils.random(
                  -(this.getHeight() * this.getScaleY()) / 2,
                  ResourceManager.getInstance().cameraHeight
                      + (this.getHeight() * this.getScaleY()) / 2),
              ResourceManager.cloudTextureRegion,
              ResourceManager.getInstance().engine.getVertexBufferObjectManager()) {
            private float XSpeed = MathUtils.random(0.2f, 2f);
            private boolean initialized = false;

            @Override
            protected void onManagedUpdate(final float pSecondsElapsed) {
              super.onManagedUpdate(pSecondsElapsed);
              if (!initialized) {
                initialized = true;
                this.setScale(XSpeed / 2);
                this.setZIndex(-4000 + Math.round(XSpeed * 1000f));
                MainMenu.getInstance().sortChildren();
              }
              if (this.getX() < -(this.getWidth() * this.getScaleX()) / 2) {
                XSpeed = MathUtils.random(0.2f, 2f);
                this.setScale(XSpeed / 2);
                this.setPosition(
                    ResourceManager.getInstance().cameraWidth
                        + (this.getWidth() * this.getScaleX()) / 2,
                    MathUtils.random(
                        -(this.getHeight() * this.getScaleY()) / 2,
                        ResourceManager.getInstance().cameraHeight
                            + (this.getHeight() * this.getScaleY()) / 2));

                this.setZIndex(-4000 + Math.round(XSpeed * 1000f));
                MainMenu.getInstance().sortChildren();
              }
              this.setPosition(this.getX() - (XSpeed * (pSecondsElapsed / 0.016666f)), this.getY());
            }
          };
      this.attachChild(curCloudSprite);
    }

    // Create a Play button. Notice that the Game scenes, unlike menus, are not referred to in a
    // static way.
    PlayButton =
        new ButtonSprite(
            (ResourceManager.getInstance().cameraWidth
                    - ResourceManager.buttonTiledTextureRegion.getTextureRegion(0).getWidth())
                / 2f,
            (ResourceManager.getInstance().cameraHeight
                    - ResourceManager.buttonTiledTextureRegion.getTextureRegion(0).getHeight())
                * (1f / 3f),
            ResourceManager.buttonTiledTextureRegion.getTextureRegion(0),
            ResourceManager.buttonTiledTextureRegion.getTextureRegion(1),
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    PlayButtonText =
        new Text(
            0,
            0,
            ResourceManager.fontDefault32Bold,
            "PLAY",
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    PlayButtonText.setPosition((PlayButton.getWidth()) / 2, (PlayButton.getHeight()) / 2);
    PlayButton.attachChild(PlayButtonText);
    this.attachChild(PlayButton);
    PlayButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            // Create a new GameLevel and show it using the SceneManager. And play a click.
            SceneManager.getInstance().showScene(new GameLevel());
            ResourceManager.clickSound.play();
          }
        });
    this.registerTouchArea(PlayButton);

    // Create an Option button. Notice that the SceneManager is being told to not pause the scene
    // while the OptionsLayer is open.
    OptionsButton =
        new ButtonSprite(
            PlayButton.getX() + PlayButton.getWidth(),
            PlayButton.getY(),
            ResourceManager.buttonTiledTextureRegion.getTextureRegion(0),
            ResourceManager.buttonTiledTextureRegion.getTextureRegion(1),
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    OptionsButtonText =
        new Text(
            0,
            0,
            ResourceManager.fontDefault32Bold,
            "OPTIONS",
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    OptionsButtonText.setPosition((OptionsButton.getWidth()) / 2, (OptionsButton.getHeight()) / 2);
    OptionsButton.attachChild(OptionsButtonText);
    this.attachChild(OptionsButton);
    OptionsButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(
              ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
            // Show the OptionsLayer and play a click.
            SceneManager.getInstance().showOptionsLayer(false);
            ResourceManager.clickSound.play();
          }
        });
    this.registerTouchArea(OptionsButton);

    // Create a title
    TitleText =
        new Text(
            0,
            0,
            ResourceManager.fontDefault72Bold,
            "HAPPY BIRDS",
            ResourceManager.getInstance().engine.getVertexBufferObjectManager());
    TitleText.setPosition(
        (ResourceManager.getInstance().cameraWidth) / 2,
        (ResourceManager.getInstance().cameraHeight * 2) / 3f);
    TitleText.setColor(0.153f, 0.290f, 0.455f);
    this.attachChild(TitleText);
  }