Package com.badlogic.gdx.graphics.g2d

Examples of com.badlogic.gdx.graphics.g2d.TextureRegion


        count++;
        final boolean flipX = cell.getFlipHorizontally();
        final boolean flipY = cell.getFlipVertically();
        final int rotations = cell.getRotation();

        final TextureRegion region = tile.getTextureRegion();
        final Texture texture = region.getTexture();

        final float x1 = col * layerTileWidth + tile.getOffsetX() * unitScale;
        final float y1 = row * layerTileHeight + tile.getOffsetY() * unitScale;
        final float x2 = x1 + region.getRegionWidth() * unitScale;
        final float y2 = y1 + region.getRegionHeight() * unitScale;

        final float adjustX = 0.5f / texture.getWidth();
        final float adjustY = 0.5f / texture.getHeight();
        final float u1 = region.getU() + adjustX;
        final float v1 = region.getV2() - adjustY;
        final float u2 = region.getU2() - adjustX;
        final float v2 = region.getV() + adjustY;

        vertices[X1] = x1;
        vertices[Y1] = y1;
        vertices[C1] = color;
        vertices[U1] = u1;
View Full Code Here


          final boolean flipX = cell.getFlipHorizontally();
          final boolean flipY = cell.getFlipVertically();
          final int rotations = cell.getRotation();

          TextureRegion region = tile.getTextureRegion();

          float x1 = x + tile.getOffsetX() * unitScale;
          float y1 = y + tile.getOffsetY() * unitScale;
          float x2 = x1 + region.getRegionWidth() * unitScale;
          float y2 = y1 + region.getRegionHeight() * unitScale;

          float u1 = region.getU();
          float v1 = region.getV2();
          float u2 = region.getU2();
          float v2 = region.getV();

          vertices[X1] = x1;
          vertices[Y1] = y1;
          vertices[C1] = color;
          vertices[U1] = u1;
          vertices[V1] = v1;

          vertices[X2] = x1;
          vertices[Y2] = y2;
          vertices[C2] = color;
          vertices[U2] = u1;
          vertices[V2] = v2;

          vertices[X3] = x2;
          vertices[Y3] = y2;
          vertices[C3] = color;
          vertices[U3] = u2;
          vertices[V3] = v2;

          vertices[X4] = x2;
          vertices[Y4] = y1;
          vertices[C4] = color;
          vertices[U4] = u2;
          vertices[V4] = v1;

          if (flipX) {
            float temp = vertices[U1];
            vertices[U1] = vertices[U3];
            vertices[U3] = temp;
            temp = vertices[U2];
            vertices[U2] = vertices[U4];
            vertices[U4] = temp;
          }
          if (flipY) {
            float temp = vertices[V1];
            vertices[V1] = vertices[V3];
            vertices[V3] = temp;
            temp = vertices[V2];
            vertices[V2] = vertices[V4];
            vertices[V4] = temp;
          }
          if (rotations == 2) {
            float tempU = vertices[U1];
            vertices[U1] = vertices[U3];
            vertices[U3] = tempU;
            tempU = vertices[U2];
            vertices[U2] = vertices[U4];
            vertices[U4] = tempU;
            float tempV = vertices[V1];
            vertices[V1] = vertices[V3];
            vertices[V3] = tempV;
            tempV = vertices[V2];
            vertices[V2] = vertices[V4];
            vertices[V4] = tempV;
            break;
          }
          spriteBatch.draw(region.getTexture(), vertices, 0, 20);
        }
      }
    }

  }
View Full Code Here

        if (tile != null) {
          final boolean flipX = cell.getFlipHorizontally();
          final boolean flipY = cell.getFlipVertically();
          final int rotations = cell.getRotation();
          TextureRegion region = tile.getTextureRegion();

          float x1 = x * layerTileWidth - offsetX + tile.getOffsetX() * unitScale;
          float y1 = y * layerTileHeight50 + tile.getOffsetY() * unitScale;
          float x2 = x1 + region.getRegionWidth() * unitScale;
          float y2 = y1 + region.getRegionHeight() * unitScale;

          float u1 = region.getU();
          float v1 = region.getV2();
          float u2 = region.getU2();
          float v2 = region.getV();

          vertices[X1] = x1;
          vertices[Y1] = y1;
          vertices[C1] = color;
          vertices[U1] = u1;
          vertices[V1] = v1;

          vertices[X2] = x1;
          vertices[Y2] = y2;
          vertices[C2] = color;
          vertices[U2] = u1;
          vertices[V2] = v2;

          vertices[X3] = x2;
          vertices[Y3] = y2;
          vertices[C3] = color;
          vertices[U3] = u2;
          vertices[V3] = v2;

          vertices[X4] = x2;
          vertices[Y4] = y1;
          vertices[C4] = color;
          vertices[U4] = u2;
          vertices[V4] = v1;

          if (flipX) {
            float temp = vertices[U1];
            vertices[U1] = vertices[U3];
            vertices[U3] = temp;
            temp = vertices[U2];
            vertices[U2] = vertices[U4];
            vertices[U4] = temp;
          }

          if (flipY) {
            float temp = vertices[V1];
            vertices[V1] = vertices[V3];
            vertices[V3] = temp;
            temp = vertices[V2];
            vertices[V2] = vertices[V4];
            vertices[V4] = temp;
          }

          if (rotations != 0) {
            switch (rotations) {
            case Cell.ROTATE_90: {
              float tempV = vertices[V1];
              vertices[V1] = vertices[V2];
              vertices[V2] = vertices[V3];
              vertices[V3] = vertices[V4];
              vertices[V4] = tempV;

              float tempU = vertices[U1];
              vertices[U1] = vertices[U2];
              vertices[U2] = vertices[U3];
              vertices[U3] = vertices[U4];
              vertices[U4] = tempU;
              break;
            }
            case Cell.ROTATE_180: {
              float tempU = vertices[U1];
              vertices[U1] = vertices[U3];
              vertices[U3] = tempU;
              tempU = vertices[U2];
              vertices[U2] = vertices[U4];
              vertices[U4] = tempU;
              float tempV = vertices[V1];
              vertices[V1] = vertices[V3];
              vertices[V3] = tempV;
              tempV = vertices[V2];
              vertices[V2] = vertices[V4];
              vertices[V4] = tempV;
              break;
            }
            case Cell.ROTATE_270: {
              float tempV = vertices[V1];
              vertices[V1] = vertices[V4];
              vertices[V4] = vertices[V3];
              vertices[V3] = vertices[V2];
              vertices[V2] = tempV;

              float tempU = vertices[U1];
              vertices[U1] = vertices[U4];
              vertices[U4] = vertices[U3];
              vertices[U3] = vertices[U2];
              vertices[U2] = tempU;
              break;
            }
            }
          }
          spriteBatch.draw(region.getTexture(), vertices, 0, 20);
        }
      }
    }
  }
View Full Code Here

        texture.setFilter(minFilter, magFilter);
       
        Keys<String> names = page.rects.keys();
        for(String name: names) {
          Rectangle rect = page.rects.get(name);
          TextureRegion region = new TextureRegion(texture, (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
          atlas.addRegion(name, region);
        }
      }
    }
    return atlas;
View Full Code Here

          };
          page.texture.setFilter(minFilter, magFilter);
         
          for(String name: page.addedRects) {
            Rectangle rect = page.rects.get(name);
            TextureRegion region = new TextureRegion(page.texture, (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
            atlas.addRegion(name, region);
          }
          page.addedRects.clear();
        }
      } else {
        if(page.addedRects.size > 0) {
          page.texture.load(page.texture.getTextureData());
          for(String name: page.addedRects) {
            Rectangle rect = page.rects.get(name);
            TextureRegion region = new TextureRegion(page.texture, (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
            atlas.addRegion(name, region);
          }
          page.addedRects.clear();
          return;
        }
View Full Code Here

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    final BitmapFont font = style.font;
    final Color fontColor = style.fontColor;
    final TextureRegion selection = style.selection;
    final NinePatch cursorPatch = style.cursor;

    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    float bgLeftWidth = 0;
    if (style.background != null) {
View Full Code Here

        if (skin.hasResource(className, TextureRegion.class))
          return new Image(skin.getRegion(className));
        if (skin.hasResource(className, NinePatch.class)) return new Image(skin.getPatch(className));
      }
      if (layout.assetManager != null && layout.assetManager.isLoaded(className, Texture.class))
        return new Image(new TextureRegion(layout.assetManager.get(className, Texture.class)));
      throw ex;
    }
  }
View Full Code Here

    }
    // Find Texture, TextureRegion and NinePatch in asset manager.
    if (layout.assetManager != null) {
      if (memberType == NinePatch.class) {
        if (layout.assetManager.isLoaded(value, Texture.class))
          return new NinePatch(new TextureRegion(layout.assetManager.get(value, Texture.class)));
      } else if (memberType == Texture.class) {
        if (layout.assetManager.isLoaded(value, Texture.class)) return layout.assetManager.get(value, Texture.class);
      } else if (memberType == TextureRegion.class) {
        if (layout.assetManager.isLoaded(value, Texture.class))
          return new TextureRegion(layout.assetManager.get(value, Texture.class));
      }
    }
    return super.convertType(layout, parentObject, memberType, memberName, value);
  }
View Full Code Here

    return style;
  }

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    final TextureRegion knob = style.knob;
    final NinePatch slider = style.slider;

    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    sliderPos = (value - min) / (max - min) * (width - knob.getRegionWidth());
    sliderPos = Math.max(0, sliderPos);
    sliderPos = Math.min(width - knob.getRegionWidth(), sliderPos);

    slider.draw(batch, x, y + (int)((height - slider.getTotalHeight()) * 0.5f), width, slider.getTotalHeight());
    batch.draw(knob, x + sliderPos, y + (int)((height - knob.getRegionHeight()) * 0.5f));
  }
 
View Full Code Here

  public void touchDragged (float x, float y, int pointer) {
    calculatePositionAndValue(x);
  }

  private void calculatePositionAndValue (float x) {
    final TextureRegion knob = style.knob;

    sliderPos = x - knob.getRegionWidth() / 2;
    sliderPos = Math.max(0, sliderPos);
    sliderPos = Math.min(width - knob.getRegionWidth(), sliderPos);
    value = min + (max - min) * (sliderPos / (width - knob.getRegionWidth()));
    if (listener != null) listener.changed(this, getValue());
  }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.graphics.g2d.TextureRegion

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.