Package com.badlogic.gdx.utils

Examples of com.badlogic.gdx.utils.Array


  public Skeleton (SkeletonData data) {
    if (data == null) throw new IllegalArgumentException("data cannot be null.");
    this.data = data;

    bones = new Array(data.bones.size);
    for (BoneData boneData : data.bones) {
      Bone parent = boneData.parent == null ? null : bones.get(data.bones.indexOf(boneData.parent, true));
      bones.add(new Bone(boneData, parent));
    }

    slots = new Array(data.slots.size);
    drawOrder = new Array(data.slots.size);
    for (SlotData slotData : data.slots) {
      Bone bone = bones.get(data.bones.indexOf(slotData.boneData, true));
      Slot slot = new Slot(slotData, this, bone);
      slots.add(slot);
      drawOrder.add(slot);
View Full Code Here


  /** Copy constructor. */
  public Skeleton (Skeleton skeleton) {
    if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
    data = skeleton.data;

    bones = new Array(skeleton.bones.size);
    for (Bone bone : skeleton.bones) {
      Bone parent = bone.parent == null ? null : bones.get(skeleton.bones.indexOf(bone.parent, true));
      bones.add(new Bone(bone, parent));
    }

    slots = new Array(skeleton.slots.size);
    for (Slot slot : skeleton.slots) {
      Bone bone = bones.get(skeleton.bones.indexOf(slot.bone, true));
      Slot newSlot = new Slot(slot, this, bone);
      slots.add(newSlot);
    }

    drawOrder = new Array(slots.size);
    for (Slot slot : skeleton.drawOrder)
      drawOrder.add(slots.get(skeleton.slots.indexOf(slot, true)));

    skin = skeleton.skin;
    color = new Color(skeleton.color);
View Full Code Here

    return attachment;
  }

  private void readAnimation (String name, DataInput input, SkeletonData skeletonData) {
    Array<Timeline> timelines = new Array();
    float duration = 0;

    try {
      int boneCount = input.readInt(true);
      for (int i = 0; i < boneCount; i++) {
        String boneName = input.readString();
        int boneIndex = skeletonData.findBoneIndex(boneName);
        if (boneIndex == -1) throw new SerializationException("Bone not found: " + boneName);
        int itemCount = input.readInt(true);
        for (int ii = 0; ii < itemCount; ii++) {
          int timelineType = input.readByte();
          int keyCount = input.readInt(true);
          switch (timelineType) {
          case TIMELINE_ROTATE: {
            RotateTimeline timeline = new RotateTimeline(keyCount);
            timeline.setBoneIndex(boneIndex);
            for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
              timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat());
              if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
            }
            timelines.add(timeline);
            duration = Math.max(duration, timeline.getFrames()[keyCount * 2 - 2]);
            break;
          }
          case TIMELINE_TRANSLATE:
          case TIMELINE_SCALE:
            TranslateTimeline timeline;
            float timelineScale = 1;
            if (timelineType == TIMELINE_SCALE)
              timeline = new ScaleTimeline(keyCount);
            else {
              timeline = new TranslateTimeline(keyCount);
              timelineScale = scale;
            }
            timeline.setBoneIndex(boneIndex);
            for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
              timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat()
                * timelineScale);
              if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
            }
            timelines.add(timeline);
            duration = Math.max(duration, timeline.getFrames()[keyCount * 3 - 3]);
            break;
          default:
            throw new RuntimeException("Invalid timeline type for a bone: " + timelineType + " (" + boneName + ")");
          }
        }
      }

      int slotCount = input.readInt(true);
      for (int i = 0; i < slotCount; i++) {
        String slotName = input.readString();
        int slotIndex = skeletonData.findSlotIndex(slotName);
        int itemCount = input.readInt(true);
        for (int ii = 0; ii < itemCount; ii++) {
          int timelineType = input.readByte();
          int keyCount = input.readInt(true);
          switch (timelineType) {
          case TIMELINE_COLOR: {
            ColorTimeline timeline = new ColorTimeline(keyCount);
            timeline.setSlotIndex(slotIndex);
            for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
              float time = input.readFloat();
              Color.rgba8888ToColor(tempColor, input.readInt());
              timeline.setFrame(keyframeIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a);
              if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
            }
            timelines.add(timeline);
            duration = Math.max(duration, timeline.getFrames()[keyCount * 5 - 5]);
            break;
          }
          case TIMELINE_ATTACHMENT:
            AttachmentTimeline timeline = new AttachmentTimeline(keyCount);
            timeline.setSlotIndex(slotIndex);
            for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++)
              timeline.setFrame(keyframeIndex, input.readFloat(), input.readString());
            timelines.add(timeline);
            duration = Math.max(duration, timeline.getFrames()[keyCount - 1]);
            break;
          default:
            throw new RuntimeException("Invalid timeline type for a slot: " + timelineType + " (" + slotName + ")");
          }
        }
      }
    } catch (IOException ex) {
      throw new SerializationException("Error reading skeleton file.", ex);
    }

    timelines.shrink();
    skeletonData.addAnimation(new Animation(name, timelines, duration));
  }
View Full Code Here

    return attachment;
  }

  private void readAnimation (String name, JsonValue map, SkeletonData skeletonData) {
    Array<Timeline> timelines = new Array();
    float duration = 0;

    for (JsonValue boneMap = map.getChild("bones"); boneMap != null; boneMap = boneMap.next()) {
      int boneIndex = skeletonData.findBoneIndex(boneMap.name());
      if (boneIndex == -1) throw new SerializationException("Bone not found: " + boneMap.name());

      for (JsonValue timelineMap = boneMap.child(); timelineMap != null; timelineMap = timelineMap.next()) {
        String timelineName = timelineMap.name();
        if (timelineName.equals(TIMELINE_ROTATE)) {
          RotateTimeline timeline = new RotateTimeline(timelineMap.size());
          timeline.setBoneIndex(boneIndex);

          int frameIndex = 0;
          for (JsonValue valueMap = timelineMap.child(); valueMap != null; valueMap = valueMap.next()) {
            float time = valueMap.getFloat("time");
            timeline.setFrame(frameIndex, time, valueMap.getFloat("angle"));
            readCurve(timeline, frameIndex, valueMap);
            frameIndex++;
          }
          timelines.add(timeline);
          duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 2 - 2]);

        } else if (timelineName.equals(TIMELINE_TRANSLATE) || timelineName.equals(TIMELINE_SCALE)) {
          TranslateTimeline timeline;
          float timelineScale = 1;
          if (timelineName.equals(TIMELINE_SCALE))
            timeline = new ScaleTimeline(timelineMap.size());
          else {
            timeline = new TranslateTimeline(timelineMap.size());
            timelineScale = scale;
          }
          timeline.setBoneIndex(boneIndex);

          int frameIndex = 0;
          for (JsonValue valueMap = timelineMap.child(); valueMap != null; valueMap = valueMap.next()) {
            float time = valueMap.getFloat("time");
            float x = valueMap.getFloat("x", 0), y = valueMap.getFloat("y", 0);
            timeline.setFrame(frameIndex, time, x * timelineScale, y * timelineScale);
            readCurve(timeline, frameIndex, valueMap);
            frameIndex++;
          }
          timelines.add(timeline);
          duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 3 - 3]);

        } else
          throw new RuntimeException("Invalid timeline type for a bone: " + timelineName + " (" + boneMap.name() + ")");
      }
    }

    for (JsonValue slotMap = map.getChild("slots"); slotMap != null; slotMap = slotMap.next()) {
      int slotIndex = skeletonData.findSlotIndex(slotMap.name());

      for (JsonValue timelineMap = slotMap.child(); timelineMap != null; timelineMap = timelineMap.next()) {
        String timelineName = timelineMap.name();
        if (timelineName.equals(TIMELINE_COLOR)) {
          ColorTimeline timeline = new ColorTimeline(timelineMap.size());
          timeline.setSlotIndex(slotIndex);

          int frameIndex = 0;
          for (JsonValue valueMap = timelineMap.child(); valueMap != null; valueMap = valueMap.next()) {
            float time = valueMap.getFloat("time");
            Color color = Color.valueOf(valueMap.getString("color"));
            timeline.setFrame(frameIndex, time, color.r, color.g, color.b, color.a);
            readCurve(timeline, frameIndex, valueMap);
            frameIndex++;
          }
          timelines.add(timeline);
          duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() * 5 - 5]);

        } else if (timelineName.equals(TIMELINE_ATTACHMENT)) {
          AttachmentTimeline timeline = new AttachmentTimeline(timelineMap.size());
          timeline.setSlotIndex(slotIndex);

          int frameIndex = 0;
          for (JsonValue valueMap = timelineMap.child(); valueMap != null; valueMap = valueMap.next()) {
            float time = valueMap.getFloat("time");
            timeline.setFrame(frameIndex++, time, valueMap.getString("name"));
          }
          timelines.add(timeline);
          duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);

        } else
          throw new RuntimeException("Invalid timeline type for a slot: " + timelineName + " (" + slotMap.name() + ")");
      }
    }

    timelines.shrink();
    skeletonData.addAnimation(new Animation(name, timelines, duration));
  }
View Full Code Here

  }

  /** Returns all regions with the specified name, ordered by smallest to largest {@link AtlasRegion#index index}. This method
   * uses string comparison to find the regions, so the result should be cached rather than calling this method multiple times. */
  public Array<AtlasRegion> findRegions (String name) {
    Array<AtlasRegion> matched = new Array();
    for (int i = 0, n = regions.size; i < n; i++) {
      AtlasRegion region = regions.get(i);
      if (region.name.equals(name)) matched.add(new AtlasRegion(region));
    }
    return matched;
  }
View Full Code Here

  /** Returns all regions in the atlas as sprites. This method creates a new sprite for each region, so the result should be
   * stored rather than calling this method multiple times.
   * @see #createSprite(String) */
  public Array<Sprite> createSprites () {
    Array sprites = new Array(regions.size);
    for (int i = 0, n = regions.size; i < n; i++)
      sprites.add(newSprite(regions.get(i)));
    return sprites;
  }
View Full Code Here

  /** Returns all regions with the specified name as sprites, ordered by smallest to largest {@link AtlasRegion#index index}. This
   * method uses string comparison to find the regions and constructs new sprites, so the result should be cached rather than
   * calling this method multiple times.
   * @see #createSprite(String) */
  public Array<Sprite> createSprites (String name) {
    Array<Sprite> matched = new Array();
    for (int i = 0, n = regions.size; i < n; i++) {
      AtlasRegion region = regions.get(i);
      if (region.name.equals(name)) matched.add(newSprite(region));
    }
    return matched;
  }
View Full Code Here

  private final Array<ParticleEmitter> emitters;
  private BoundingBox bounds;
  private boolean ownsTexture;

  public ParticleEffect () {
    emitters = new Array(8);
  }
View Full Code Here

  public ParticleEffect () {
    emitters = new Array(8);
  }

  public ParticleEffect (ParticleEffect effect) {
    emitters = new Array(true, effect.emitters.size);
    for (int i = 0, n = effect.emitters.size; i < n; i++)
      emitters.add(new ParticleEmitter(effect.emitters.get(i)));
  }
View Full Code Here

    super(resolver);
  }

  @Override
  public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, SkinParameter parameter) {
    Array<AssetDescriptor> deps = new Array();
    if (parameter == null)
      deps.add(new AssetDescriptor(file.pathWithoutExtension() + ".atlas", TextureAtlas.class));
    else if (parameter.textureAtlasPath != null)
      deps.add(new AssetDescriptor(parameter.textureAtlasPath, TextureAtlas.class));
    return deps;
  }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.utils.Array

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.