示例#1
0
  /**
   * 绘制,实现自sceneInterface
   *
   * @param canvas 画布
   */
  public void onDraw(Canvas canvas, Paint paint) {
    if (paint == null) {
      paint = DEFAULT_PAINT;
    }
    final Iterator<AbstractSprite> it = dynLevel.getSpriteList().iterator();
    while (it.hasNext()) {
      final AbstractSprite obj = it.next();
      if (obj instanceof Moveable) {
        ((Moveable) obj).autoMove();
      }
      if (obj instanceof StaCollidable) {
        ((StaCollidable) obj).handleStaCollision();
      }
    }
    checkCollision();
    if (mel != null) {
      MapEvent met = map.checkEvent((Rect) hero.getRect());
      if (met != null) {
        mel.mapEventOccured(met);
      }
    }
    if (hero != null) {

      offsetX = hero.getX() - SystemData.getActivityWidth() / 2;
      offsetY = hero.getY() - SystemData.getActivityHeight() / 2;
    }

    if (offsetX < 0) offsetX = 0;
    if (offsetY < 0) offsetY = 0;

    if (offsetX + SystemData.getActivityWidth() > map.getWidth()) {
      offsetX = map.getWidth() - SystemData.getActivityWidth();
    }
    if (offsetY + SystemData.getActivityHeight() > map.getHeight()) {
      offsetY = map.getHeight() - SystemData.getActivityHeight();
    }

    Matrix m = new Matrix();
    m.setTranslate(-offsetX, -offsetY);
    canvas.setMatrix(m);

    // map.setOffsetXY(offsetX, offsetY);
    // dynLevel.setOffsetXY(offsetX, offsetY);

    if (map != null) {
      map.drawDown(canvas, paint);
    }
    if (dynLevel != null) {
      dynLevel.onDraw(canvas, paint);
    }
    if (map != null) {
      map.drawUp(canvas, paint);
    }

    canvas.setMatrix(new Matrix());
  }