Exemple #1
0
 /** @param visible the visible to set */
 public void setVisible(boolean visible) {
   this.visible = visible;
   if (sprite != null) {
     for (Sprite element : sprite) {
       if (element != null) {
         element.setVisible(visible);
       }
     }
   }
 }
Exemple #2
0
  /*
   * (non-Javadoc)
   * @see net.puppygames.applet.Tickable#update()
   */
  @Override
  public final void update() {
    calculateScreenPosition();

    if (sprite != null) {

      // Firstly, if we're significantly offscreen, hide all the sprites.
      if (getScreenX() < -48.0f
          || getScreenX() >= Game.getWidth() + 48
          || getScreenY() < -48.0f - getZ()
          || getScreenY() >= Game.getHeight() + 48 + getZ()) {
        for (Sprite element : sprite) {
          element.setVisible(false);
        }
        doUpdate();
        return;
      } else {
        for (Sprite element : sprite) {
          element.setVisible(visible);
        }
      }

      boolean searchForChildOffsets = false;

      for (Sprite element : sprite) {

        element.setLocation(screenX, screenY, 0);
        if (element.getLayer() > Layers.SHADOW) {
          element.setFlash(flash);
        }

        // shall we bother checking anims for childOffset stuff?
        if (element.isDoChildOffset()) {
          searchForChildOffsets = true;
        }
      }

      if (searchForChildOffsets) {

        float xOffset = 0;
        float yOffset = 0;
        yOffsetTotal = 0;
        xOffsetTotal = 0;

        for (int i = 0; i < sprite.length; i++) {

          boolean doOffset = false;

          // check for offset
          if (sprite[i].getChildXOffset() != 0) {

            xOffset = sprite[i].getChildXOffset();
            xOffset *= FPMath.floatValue(sprite[0].getXScale());
            if (isMirrored() && xOffset != 0) {

              // chaz hack! - if we've got any <offset anim commands they'd need to be mirrored too
              // so for now will disable mirroring of childOffset if <offset x=""/> present
              if (sprite[i].getOffset(null).x == 0) {
                xOffset = -xOffset;
              }
            }

            xOffsetTotal += xOffset;
            doOffset = true;
          }
          if (sprite[i].getChildYOffset() != 0) {

            yOffset = sprite[i].getChildYOffset();
            yOffset *= FPMath.floatValue(sprite[0].getYScale());
            yOffsetTotal += yOffset;
            doOffset = true;
          }

          // if we've found an offset apply this to any sprites after where we found the offset

          if (doOffset) {
            for (int j = i + 1; j < sprite.length; j++) {
              if (sprite[j].isDoChildOffset()) {
                sprite[j].setLocation(screenX + xOffsetTotal, screenY + yOffsetTotal, 0);
                sprite[j].setYSortOffset(
                    -yOffsetTotal
                        - j); // the '-j' is chaz hack! budge layers YSortOffset a tad to force
                // render ok
              }
            }
          }
        }
      }

      LayersFeature currentAppearance = getCurrentAppearance();
      float cx = getMapX() + getCollisionX();
      float cy = getMapY() + getCollisionY();
      if (currentAppearance != null
          && (GameScreen.isDiddlerOpen()
              || hackyTick > 0
              || cx != oldX
              || cy != oldY
              || currentAppearance != oldAppearance)) {
        currentAppearance.updateColors(sprite, cx, cy);
        if (hackyTick > 0) {
          hackyTick--;
        }
      }
      oldX = cx;
      oldY = cy;
      oldAppearance = currentAppearance;
    }

    doUpdate();
  }
 /* (non-Javadoc)
  * @see com.shavenpuppy.jglib.sprites.Animation.Animated#hide()
  */
 public void hide() {
   setVisible(false);
 }