コード例 #1
0
  private void drawSun(Canvas canvas) {
    float pixelScale = getPixelScale();

    int imageSize = (int) (300.0f * pixelScale);
    Sprite sprite = StarImageManager.getInstance().getSprite(mStar, imageSize, false);

    mMatrix.reset();
    mMatrix.postTranslate(-(sprite.getWidth() / 2.0f), -(sprite.getHeight() / 2.0f));
    mMatrix.postScale(
        300.0f * pixelScale / sprite.getWidth(), 300.0f * pixelScale / sprite.getHeight());
    canvas.save();
    canvas.concat(mMatrix);
    sprite.draw(canvas);
    canvas.restore();
  }
コード例 #2
0
  private void drawPlanets(Canvas canvas) {
    for (int i = 0; i < mPlanetInfos.length; i++) {
      canvas.drawCircle(0, 0, mPlanetInfos[i].distanceFromSun, mPlanetPaint);
    }

    PlanetImageManager pim = PlanetImageManager.getInstance();

    for (int i = 0; i < mPlanetInfos.length; i++) {
      final PlanetInfo planetInfo = mPlanetInfos[i];

      Sprite sprite = pim.getSprite(planetInfo.planet);
      mMatrix.reset();
      mMatrix.postTranslate(-(sprite.getWidth() / 2.0f), -(sprite.getHeight() / 2.0f));
      mMatrix.postScale(
          100.0f * getPixelScale() / sprite.getWidth(),
          100.0f * getPixelScale() / sprite.getHeight());
      mMatrix.postTranslate((float) planetInfo.centre.x, (float) planetInfo.centre.y);
      canvas.save();
      canvas.concat(mMatrix);
      sprite.draw(canvas);
      canvas.restore();

      if (planetInfo.buildings != null) {
        int j = 0;
        float angleOffset = (float) (Math.PI / 4.0) * (planetInfo.buildings.size() - 1) / 2.0f;
        for (Building building : planetInfo.buildings) {
          BuildingDesign design = building.getDesign();
          Sprite buildingSprite = SpriteManager.i.getSprite(design.getSpriteName());

          Vector2 pt = Vector2.pool.borrow().reset(0, -30.0f);
          pt.rotate(angleOffset - (float) (Math.PI / 4.0) * j);

          mMatrix.reset();
          mMatrix.postTranslate(
              -(buildingSprite.getWidth() / 2.0f), -(buildingSprite.getHeight() / 2.0f));
          mMatrix.postScale(
              20.0f * getPixelScale() / buildingSprite.getWidth(),
              20.0f * getPixelScale() / buildingSprite.getHeight());
          mMatrix.postTranslate(
              (float) (planetInfo.centre.x + (pt.x * getPixelScale())),
              (float) (planetInfo.centre.y + (pt.y * getPixelScale())));

          canvas.save();
          canvas.concat(mMatrix);
          buildingSprite.draw(canvas);
          canvas.restore();

          j++;
        }
      }

      if (planetInfo.colony != null) {
        Empire empire = EmpireManager.i.getEmpire(planetInfo.colony.getEmpireID());
        if (empire != null) {
          Bitmap shield = EmpireShieldManager.i.getShield(mContext, empire);
          if (shield != null) {
            mMatrix.reset();
            mMatrix.postTranslate(-shield.getWidth() / 2.0f, -shield.getHeight() / 2.0f);
            mMatrix.postScale(
                20.0f * getPixelScale() / shield.getWidth(),
                20.0f * getPixelScale() / shield.getHeight());
            mMatrix.postTranslate(
                (float) planetInfo.centre.x,
                (float) planetInfo.centre.y + (30.0f * getPixelScale()));
            canvas.drawBitmap(shield, mMatrix, mPlanetPaint);
          }
        }
      }
    }
  }