/**
   * Add an Actor to the world (at the object's specified location).
   *
   * @param object The new object to add.
   * @throws IndexOutOfBoundsException If the coordinates are outside the bounds of the world.
   */
  public synchronized void addObject(Actor object, int x, int y) throws IndexOutOfBoundsException {
    // TODO bad performance when using a List for the objects. But if we
    // want to have paint order, a List is necessary.
    if (objects.contains(object)) {
      return;
    }

    object.addToWorld(x, y, this);

    collisionChecker.addObject(object);
    objects.add(object);

    object.addedToWorld(this);
  }
示例#2
0
  /**
   * Add an Actor to the world.
   *
   * @param object The new object to add.
   * @param x The x coordinate of the location where the object is added.
   * @param y The y coordinate of the location where the object is added.
   */
  public void addObject(Actor object, int x, int y) {
    if (object.world != null) {
      if (object.world == this) {
        return; // Actor is already in the world
      }
      object.world.removeObject(object);
    }

    objectsDisordered.add(object);
    addInPaintOrder(object);
    addInActOrder(object);

    // Note we must call this before adding the object to the collision checker,
    // so that the cached bounds are cleared:
    object.addToWorld(x, y, this);

    collisionChecker.addObject(object);
    object.addedToWorld(this);

    WorldHandler whInstance = WorldHandler.getInstance();
    if (whInstance != null) {
      WorldHandler.getInstance().objectAddedToWorld(object);
    }
  }