Esempio n. 1
0
  /**
   * 触屏事件处理
   *
   * @param event 触屏事件
   */
  public void onTouchEvent(MotionEvent event) {
    Log.i("touch", "touch!!!!!!!!!!");
    if (event.getAction() == MotionEvent.ACTION_UP) {
      if (map instanceof AutoSearchable) {
        final int x = (int) event.getX();
        final int y = (int) event.getY();

        final Point des = map.mapToArray(new Point(x, y));
        final Point start = map.mapToArray(new Point(hero.getX(), hero.getY()));
        final Route route = ((AutoSearchable) map).findRoute(start, des);
        if (route != null) {
          createStep(route);
        }
      }
    }
  }
Esempio n. 2
0
 /**
  * 加载,实现自sceneInterface
  *
  * @param context context
  */
 public void load(Resources resource) {
   if (map != null) {
     map.load(resource);
   }
   if (dynLevel != null) {
     dynLevel.load(resource);
   }
 }
Esempio n. 3
0
 /** 释放,实现自sceneInterface */
 public void unLoad() {
   if (map != null) {
     map.unload();
   }
   if (dynLevel != null) {
     dynLevel.unload();
   }
 }
Esempio n. 4
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());
  }