[changed] ParticleEmitter, removed method calls.
[added] BitmapFont#setFixedWidthGlyphs.
[fixed] SpriteBatch.maxSpritesInBatch.
[added] various javadocs.
[changed] TextureAtlas: addRegion for manually adding regions, better methods for getting regions/sprites, public fields on AtlasRegion.
[fixed] TextureRegion#getRegionWidth.
[fixed] Test compile errors.
[fixed] ParticleEmitterTest particle counts were too high by 1000.
formatToAbbrev.put(Format.Alpha, "a");\r
}\r
\r
- static class Settings {\r
+ static public class Settings {\r
public Format defaultFormat = Format.RGBA8888;\r
public TextureFilter defaultFilterMin = TextureFilter.Linear;\r
public TextureFilter defaultFilterMag = TextureFilter.Linear;\r
return color;\r
}\r
\r
- public TextureRegion getTextureRegion () {\r
+ public TextureRegion getRegion () {\r
return region;\r
}\r
\r
region.getTexture().dispose();\r
}\r
\r
+ /**\r
+ * Makes the specified glyphs fixed width. This can be useful to make the numbers in a font fixed width. Eg, when horizontally\r
+ * centering a score or loading percentage text, it will not jump around as different numbers are shown.\r
+ */\r
+ public void setFixedWidthGlyphs (CharSequence glyphs) {\r
+ int maxAdvance = 0;\r
+ for (int index = 0, end = glyphs.length(); index < end; index++) {\r
+ Glyph g = getGlyph(glyphs.charAt(index));\r
+ if (g != null && g.xadvance > maxAdvance) maxAdvance = g.xadvance;\r
+ }\r
+ for (int index = 0, end = glyphs.length(); index < end; index++) {\r
+ Glyph g = getGlyph(glyphs.charAt(index));\r
+ if (g == null) continue;\r
+ g.xoffset += (maxAdvance - g.xadvance) / 2;\r
+ g.xadvance = maxAdvance;\r
+ g.kerning = null;\r
+ }\r
+ }\r
+\r
static class Glyph {\r
int width, height;\r
float u, v, u2, v2;\r
}\r
\r
public void draw (SpriteBatch spriteBatch) {\r
- spriteBatch.draw(font.getTextureRegion().getTexture(), vertices, 0, idx);\r
+ spriteBatch.draw(font.getRegion().getTexture(), vertices, 0, idx);\r
}\r
\r
private void reset (int glyphCount) {\r
* Draws a rectangle with the top left corner at x,y having the given width\r
* and height in pixels. The rectangle is offset by originX, originY\r
* relative to the origin. Scale specifies the scaling factor by which the\r
- * rectangle should be scaled around originX,originY. Rotation specifies the\r
+ * rectangle should be scaled around originX, originY. Rotation specifies the\r
* angle of counter clockwise rotation of the rectangle around originX,\r
* originY. The portion of the {@link Texture} given by srcX, srcY and\r
* srcWidth, srcHeight is used. These coordinates and sizes are given in\r
- * texels. The rectangle will have the given tint {@link Color}. FlipX and\r
+ * texels. FlipX and\r
* flipY specify whether the texture portion should be fliped horizontally\r
* or vertically.\r
* \r
vertices[idx++] = 1;\r
}\r
\r
+ /**\r
+ * Draws a rectangle using the given vertices. There must be 4 vertices, each made up of 5 elements in this order: x, y, color,\r
+ * u, v.\r
+ */\r
public void draw(Texture texture, float[] spriteVertices, int offset,\r
int length) {\r
if (!drawing)\r
idx += length;\r
}\r
\r
+ /**\r
+ * Draws a rectangle with the top left corner at x,y having the width and height of the region.\r
+ */\r
public void draw (TextureRegion region, float x, float y) {\r
draw(region, x, y, region.getRegionWidth(), region.getRegionHeight());\r
}\r
\r
+ /**\r
+ * Draws a rectangle with the top left corner at x,y and stretching the region to cover the given width and height.\r
+ */\r
public void draw (TextureRegion region, float x, float y, float width, float height) {\r
if (!drawing) throw new IllegalStateException("SpriteBatch.begin must be called before draw.");\r
\r
vertices[idx++] = v;\r
}\r
\r
+ /**\r
+ * Draws a rectangle with the top left corner at x,y and stretching the region to cover the given width and height. The\r
+ * rectangle is offset by originX, originY relative to the origin. Scale specifies the scaling factor by which the rectangle\r
+ * should be scaled around originX, originY. Rotation specifies the angle of counter clockwise rotation of the rectangle around\r
+ * originX, originY.\r
+ */\r
public void draw (TextureRegion region, float x, float y, float originX, float originY, float width, float height,\r
float scaleX, float scaleY, float rotation) {\r
if (!drawing) throw new IllegalStateException("SpriteBatch.begin must be called before draw.");\r
return;\r
\r
renderCalls++;\r
+ int spritesInBatch = idx / 20;\r
+ if (spritesInBatch > maxSpritesInBatch) maxSpritesInBatch = spritesInBatch;\r
\r
lastTexture.bind();\r
mesh.setVertices(vertices, 0, idx);\r
gl20.glBlendFunc(blendSrcFunc, blendDstFunc);\r
}\r
\r
- mesh.render(shader, GL10.GL_TRIANGLES, 0, idx / 20 * 6);\r
+ mesh.render(shader, GL10.GL_TRIANGLES, 0, spritesInBatch * 6);\r
} else {\r
if (blendingDisabled) {\r
Gdx.gl10.glDisable(GL10.GL_BLEND);\r
gl10.glEnable(GL10.GL_BLEND);\r
gl10.glBlendFunc(blendSrcFunc, blendDstFunc);\r
}\r
- mesh.render(GL10.GL_TRIANGLES, 0, idx / 20 * 6);\r
+ mesh.render(GL10.GL_TRIANGLES, 0, spritesInBatch * 6);\r
}\r
- int spritesInBatch = idx / 20 / 6;\r
- if (spritesInBatch > maxSpritesInBatch) spritesInBatch = maxSpritesInBatch;\r
+ \r
idx = 0;\r
currBufferIdx++;\r
- if(currBufferIdx == buffers.length) {\r
- currBufferIdx = 0;\r
- }\r
+ if (currBufferIdx == buffers.length) currBufferIdx = 0;\r
mesh = buffers[currBufferIdx];\r
}\r
\r
}\r
\r
/**\r
- * Sets the color used to tint images when they are added to the SpriteBatch. Default is {@link Color#WHITE}.\r
+ * Sets the color used to tint images when they are added to the SpriteCache. Default is {@link Color#WHITE}.\r
*/\r
public void setColor (Color tint) {\r
color = tint.toFloatBits();\r
}\r
\r
/**\r
- * Adds the specified image to the cache.\r
+ * Adds the specified texture to the cache.\r
*/\r
public void add (Texture texture, float x, float y) {\r
final float fx2 = x + texture.getWidth();\r
}\r
\r
/**\r
- * Adds the specified image to the cache.\r
+ * Adds the specified texture to the cache.\r
*/\r
public void add (Texture texture, float x, float y, int srcWidth, int srcHeight, float u, float v, float u2, float v2,\r
float color) {\r
}\r
\r
/**\r
- * Adds the specified image to the cache.\r
+ * Adds the specified texture to the cache.\r
*/\r
public void add (Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight) {\r
float invTexWidth = 1.0f / texture.getWidth();\r
}\r
\r
/**\r
- * Adds the specified image to the cache.\r
+ * Adds the specified texture to the cache.\r
*/\r
public void add (Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth,\r
int srcHeight, boolean flipX, boolean flipY) {\r
}\r
\r
/**\r
- * Adds the specified image to the cache.\r
+ * Adds the specified texture to the cache.\r
*/\r
public void add (Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX,\r
float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) {\r
}\r
}\r
\r
+ /**\r
+ * Adds the specified region to the cache.\r
+ */\r
public void add (TextureRegion region, float x, float y) {\r
add(region, x, y, region.getRegionWidth(), region.getRegionHeight());\r
}\r
\r
+ /**\r
+ * Adds the specified region to the cache.\r
+ */\r
public void add (TextureRegion region, float x, float y, float width, float height) {\r
final float fx2 = x + width;\r
final float fy2 = y + height;\r
}\r
}\r
\r
+ /**\r
+ * Adds the specified region to the cache.\r
+ */\r
public void add (TextureRegion region, float x, float y, float originX, float originY, float width, float height,\r
float scaleX, float scaleY, float rotation) {\r
\r
import java.io.InputStreamReader;\r
import java.util.ArrayList;\r
import java.util.Comparator;\r
+import java.util.HashSet;\r
import java.util.List;\r
import java.util.PriorityQueue;\r
\r
public class TextureAtlas {\r
static private final String[] tuple = new String[2];\r
\r
- private final ArrayList<Texture> textures = new ArrayList(4);\r
- private final AtlasRegion[] regions;\r
+ private final HashSet<Texture> textures = new HashSet(4);\r
+ private final ArrayList<AtlasRegion> regions;\r
\r
+ /**\r
+ * Creates an empty atlas to which regions can be added.\r
+ */\r
+ public TextureAtlas () {\r
+ regions = new ArrayList();\r
+ }\r
+\r
+ /**\r
+ * Loads a pack file named "pack" in the specified directory and also looks there for page images named in the pack file.\r
+ */\r
public TextureAtlas (FileHandle imagesDir) {\r
this(imagesDir.child("pack"), imagesDir);\r
}\r
\r
+ /**\r
+ * @param flip If true, all regions loaded will be flipped for use with a perspective where 0,0 is the upper left corner.\r
+ * @see #TextureAtlas(FileHandle)\r
+ */\r
public TextureAtlas (FileHandle imagesDir, boolean flip) {\r
this(imagesDir.child("pack"), imagesDir, flip);\r
}\r
this(packFile, imagesDir, false);\r
}\r
\r
+ /**\r
+ * @param flip If true, all regions loaded will be flipped for use with a perspective where 0,0 is the upper left corner.\r
+ */\r
public TextureAtlas (FileHandle packFile, FileHandle imagesDir, boolean flip) {\r
PriorityQueue<AtlasRegion> sortedRegions = new PriorityQueue(16, indexComparator);\r
\r
}\r
\r
int n = sortedRegions.size();\r
- regions = new AtlasRegion[n];\r
+ regions = new ArrayList(n);\r
for (int i = 0; i < n; i++)\r
- regions[i] = sortedRegions.poll();\r
+ regions.add(sortedRegions.poll());\r
+ }\r
+\r
+ /**\r
+ * Adds a region to the atlas. The specified texture will be disposed when the atlas is disposed.\r
+ */\r
+ public AtlasRegion addRegion (String name, Texture texture, int x, int y, int width, int height) {\r
+ textures.add(texture);\r
+ AtlasRegion region = new AtlasRegion(texture, x, y, width, height);\r
+ region.name = name;\r
+ region.originalWidth = width;\r
+ region.originalHeight = height;\r
+ region.index = Integer.MAX_VALUE;\r
+ regions.add(region);\r
+ return region;\r
}\r
\r
/**\r
- * Returns the first sprite found with the specified name.<br>\r
- * <br>\r
- * This method uses string comparison to find the sprite, so the result should be cached rather than calling this method every\r
- * frame.\r
+ * Adds a region to the atlas. The texture for the specified region will be disposed when the atlas is disposed.\r
+ */\r
+ public AtlasRegion addRegion (String name, TextureRegion textureRegion) {\r
+ return addRegion(name, textureRegion.texture, textureRegion.getRegionX(), textureRegion.getRegionY(),\r
+ textureRegion.getRegionWidth(), textureRegion.getRegionHeight());\r
+ }\r
+\r
+ /**\r
+ * Returns all regions in the atlas.\r
+ */\r
+ public List<AtlasRegion> getRegions () {\r
+ return regions;\r
+ }\r
+\r
+ /**\r
+ * Returns the first region found with the specified name. This method uses string comparison to find the region, so the result\r
+ * should be cached rather than calling this method multiple times.\r
+ * @return The region, or null.\r
*/\r
public AtlasRegion getRegion (String name) {\r
- for (int i = 0, n = regions.length; i < n; i++)\r
- if (regions[i].name.equals(name)) return regions[i];\r
+ for (int i = 0, n = regions.size(); i < n; i++)\r
+ if (regions.get(i).name.equals(name)) return regions.get(i);\r
return null;\r
}\r
\r
/**\r
- * Returns all sprites found with the specified name, ordered by smallest to largest {@link AtlasRegion#getIndex() index}.<br>\r
- * <br>\r
- * This method uses string comparison to find the sprite, so the result should be cached rather than calling this method every\r
- * frame.\r
+ * Returns all regions with the specified name, ordered by smallest to largest {@link AtlasRegion#index index}. This method\r
+ * uses string comparison to find the regions, so the result should be cached rather than calling this method multiple times.\r
*/\r
public List<AtlasRegion> getRegions (String name) {\r
ArrayList<AtlasRegion> matched = new ArrayList();\r
- for (int i = 0, n = regions.length; i < n; i++)\r
- if (regions[i].name.equals(name)) matched.add(new AtlasRegion(regions[i]));\r
+ for (int i = 0, n = regions.size(); i < n; i++) {\r
+ AtlasRegion region = regions.get(i);\r
+ if (region.name.equals(name)) matched.add(new AtlasRegion(region));\r
+ }\r
return matched;\r
}\r
\r
+ /**\r
+ * Returns all regions in the atlas as sprites. This method creates a new sprite for each region, so the result should be\r
+ * stored rather than calling this method multiple times.\r
+ * @see #getSprite(String)\r
+ */\r
+ public List<Sprite> getSprites () {\r
+ ArrayList sprites = new ArrayList(regions.size());\r
+ for (int i = 0, n = regions.size(); i < n; i++)\r
+ sprites.add(newSprite(regions.get(i)));\r
+ return sprites;\r
+ }\r
+\r
+ /**\r
+ * Returns the first region found with the specified name as a sprite. If whitespace was stripped from the region when it was\r
+ * packed, the sprite is automatically positioned as if whitespace had not been stripped. This method uses string comparison to\r
+ * find the region and constructs a new sprite, so the result should be cached rather than calling this method multiple times.\r
+ * @return The sprite, or null.\r
+ */\r
public Sprite getSprite (String name) {\r
- for (int i = 0, n = regions.length; i < n; i++)\r
- if (regions[i].name.equals(name)) return newSprite(regions[i]);\r
+ for (int i = 0, n = regions.size(); i < n; i++)\r
+ if (regions.get(i).name.equals(name)) return newSprite(regions.get(i));\r
return null;\r
}\r
\r
+ /**\r
+ * Returns all regions with the specified name as sprites, ordered by smallest to largest {@link AtlasRegion#index index}. This\r
+ * method uses string comparison to find the regions and constructs new sprites, so the result should be cached rather than\r
+ * calling this method multiple times.\r
+ * @see #getSprite(String)\r
+ */\r
public List<Sprite> getSprites (String name) {\r
ArrayList<Sprite> matched = new ArrayList();\r
- for (int i = 0, n = regions.length; i < n; i++)\r
- if (regions[i].name.equals(name)) matched.add(newSprite(regions[i]));\r
+ for (int i = 0, n = regions.size(); i < n; i++) {\r
+ AtlasRegion region = regions.get(i);\r
+ if (region.name.equals(name)) matched.add(newSprite(region));\r
+ }\r
return matched;\r
}\r
\r
* and Sprites, which should no longer be used after calling dispose.\r
*/\r
public void dispose () {\r
- for (int i = 0, n = textures.size(); i < n; i++)\r
- textures.get(i).dispose();\r
+ for (Texture texture : textures)\r
+ texture.dispose();\r
textures.clear();\r
}\r
\r
tuple[1] = line.substring(comma + 1).trim();\r
}\r
\r
+ /**\r
+ * Describes the region of a packed image and provides extra information, such as the original image size before any whitespace\r
+ * was stripped.\r
+ */\r
static public class AtlasRegion extends TextureRegion {\r
- int index;\r
- String name;\r
- float offsetX, offsetY;\r
- int packedWidth, packedHeight;\r
- int originalWidth, originalHeight;\r
- boolean rotate;\r
-\r
- AtlasRegion (Texture texture, int x, int y, int width, int height) {\r
- super(texture, x, y, width, height);\r
- packedWidth = width;\r
- packedHeight = height;\r
- }\r
-\r
- AtlasRegion (AtlasRegion region) {\r
- setRegion(region);\r
- packedWidth = region.packedWidth;\r
- packedHeight = region.packedHeight;\r
- }\r
-\r
- public void flip (boolean x, boolean y) {\r
- super.flip(x, y);\r
- if (x) offsetX = originalWidth - offsetX - packedWidth;\r
- if (y) offsetY = originalHeight - offsetY - packedHeight;\r
- }\r
-\r
- /**\r
- * The name of the original image file, with any trailing numbers or special flags removed.\r
- */\r
- public String getName () {\r
- return name;\r
- }\r
-\r
/**\r
* The number at the end of the original image file name, or Integer.MAX_VALUE if none.<br>\r
* <br>\r
* part of the sprite's name. This is useful for keeping animation frames in order.\r
* @see TextureAtlas#getRegions(String)\r
*/\r
- public int getIndex () {\r
- return index;\r
- }\r
+ public int index;\r
+\r
+ /**\r
+ * The name of the original image file, with any trailing numbers or special flags removed.\r
+ */\r
+ public String name;\r
+\r
+ /**\r
+ * The offset from the left of the original image to the left of the packed image, after whitespace was removed for packing.\r
+ */\r
+ public float offsetX;\r
+\r
+ /**\r
+ * The offset from the bottom of the original image to the bottom of the packed image, after whitespace was removed for\r
+ * packing.\r
+ */\r
+ public float offsetY;\r
\r
/**\r
* The width of the image, after whitespace was removed for packing.\r
*/\r
- public int getPackedWidth () {\r
- return packedWidth;\r
- }\r
+ public int packedWidth;\r
\r
/**\r
* The height of the image, after whitespace was removed for packing.\r
*/\r
- public int getPackedHeight () {\r
- return packedHeight;\r
- }\r
+ public int packedHeight;\r
\r
/**\r
* The width of the image, before whitespace was removed for packing.\r
*/\r
- public int getOriginalWidth () {\r
- return originalWidth;\r
- }\r
+ public int originalWidth;\r
\r
/**\r
* The height of the image, before whitespace was removed for packing.\r
*/\r
- public int getOriginalHeight () {\r
- return originalHeight;\r
- }\r
+ public int originalHeight;\r
\r
/**\r
- * The offset from the left of the original image to the left of the packed image, after whitespace was removed for packing.\r
+ * If true, the region has been rotated 90 degrees counter clockwise.\r
*/\r
- public float getOffsetX () {\r
- return offsetX;\r
+ public boolean rotate;\r
+\r
+ AtlasRegion (Texture texture, int x, int y, int width, int height) {\r
+ super(texture, x, y, width, height);\r
+ packedWidth = width;\r
+ packedHeight = height;\r
}\r
\r
- /**\r
- * The offset from the bottom of the original image to the bottom of the packed image, after whitespace was removed for\r
- * packing.\r
- */\r
- public float getOffsetY () {\r
- return offsetY;\r
+ AtlasRegion (AtlasRegion region) {\r
+ setRegion(region);\r
+ packedWidth = region.packedWidth;\r
+ packedHeight = region.packedHeight;\r
+ }\r
+\r
+ public void flip (boolean x, boolean y) {\r
+ super.flip(x, y);\r
+ if (x) offsetX = originalWidth - offsetX - packedWidth;\r
+ if (y) offsetY = originalHeight - offsetY - packedHeight;\r
}\r
}\r
\r
- /**\r
- * A sprite that provides additional information about the packed image it represents. An AtlasSprite's position is relative to\r
- * the bottom left of the original image, before whitespace was removed for packing.\r
- */\r
- static class AtlasSprite extends Sprite {\r
+ static private class AtlasSprite extends Sprite {\r
final AtlasRegion region;\r
\r
- AtlasSprite (AtlasRegion region) {\r
+ public AtlasSprite (AtlasRegion region) {\r
this.region = region;\r
setRegion(region);\r
if (region.rotate) rotate90(true);\r
public void flip (boolean x, boolean y) {\r
// Flip texture.\r
super.flip(x, y);\r
- // Update x and y offsets.\r
+\r
float oldOffsetX = region.offsetX;\r
float oldOffsetY = region.offsetY;\r
+ // Update x and y offsets.\r
region.flip(x, y);\r
+\r
// Update position with new offsets.\r
translate(region.offsetX - oldOffsetX, region.offsetY - oldOffsetY);\r
}\r
package com.badlogic.gdx.graphics;\r
\r
/**\r
- * A TextureRegion defines a rectangular area in a texture given in pixels. The coordinate system used has its origin in the upper\r
- * left corner with the x-axis pointing to the left and the y axis pointing downwards.\r
+ * Defines a rectangular area of a texture. The coordinate system used has its origin in the upper left corner with the x-axis\r
+ * pointing to the left and the y axis pointing downwards.\r
* @author mzechner\r
* @author Nathan Sweet <misc@n4te.com>\r
*/\r
float u, v;\r
float u2, v2;\r
\r
+ /**\r
+ * Constructs a region with no texture and no coordinates defined.\r
+ */\r
public TextureRegion () {\r
}\r
\r
+ /**\r
+ * Constructs a region the size of the specified texture.\r
+ */\r
public TextureRegion (Texture texture) {\r
this.texture = texture;\r
setRegion(0, 0, texture.getWidth(), texture.getHeight());\r
}\r
\r
+ /**\r
+ * @param width The width of the texture region. May be negative to flip the sprite when drawn.\r
+ * @param height The height of the texture region. May be negative to flip the sprite when drawn.\r
+ */\r
public TextureRegion (Texture texture, int x, int y, int width, int height) {\r
this.texture = texture;\r
setRegion(x, y, width, height);\r
setRegion(u, v, u2, v2);\r
}\r
\r
+ /**\r
+ * Constructs a region with the same texture and coordinates of the specified region.\r
+ */\r
public TextureRegion (TextureRegion region) {\r
setRegion(region);\r
}\r
\r
+ /**\r
+ * Constructs a region with the same texture as the specified region and sets the coordinates relative to the specified region.\r
+ * @param width The width of the texture region. May be negative to flip the sprite when drawn.\r
+ * @param height The height of the texture region. May be negative to flip the sprite when drawn.\r
+ */\r
public TextureRegion (TextureRegion region, int x, int y, int width, int height) {\r
setRegion(region, x, y, width, height);\r
}\r
\r
+ /**\r
+ * Sets the texture and sets the coordinates to the size of the specified texture.\r
+ */\r
public void setRegion (Texture texture) {\r
this.texture = texture;\r
setRegion(0, 0, texture.getWidth(), texture.getHeight());\r
}\r
\r
/**\r
- * Sets the texture coordinates in pixels to apply to the sprite. This resets calling {@link #flip(boolean, boolean)}.\r
- * \r
- * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn.\r
- * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn.\r
+ * @param width The width of the texture region. May be negative to flip the sprite when drawn.\r
+ * @param height The height of the texture region. May be negative to flip the sprite when drawn.\r
*/\r
public void setRegion (int x, int y, int width, int height) {\r
float invTexWidth = 1f / texture.getWidth();\r
this.v2 = v2;\r
}\r
\r
+ /**\r
+ * Sets the texture and coordinates to the specified region.\r
+ */\r
public void setRegion (TextureRegion region) {\r
texture = region.texture;\r
setRegion(region.u, region.v, region.u2, region.v2);\r
}\r
\r
+ /**\r
+ * Sets the texture to that of the specified region and sets the coordinates relative to the specified region.\r
+ */\r
public void setRegion (TextureRegion region, int x, int y, int width, int height) {\r
texture = region.texture;\r
setRegion(region.getRegionX() + x, region.getRegionY() + y, width, height);\r
}\r
\r
public int getRegionY () {\r
- return (int)(getV() * texture.getHeight());\r
+ return (int)(v * texture.getHeight());\r
}\r
\r
public void setRegionY (int y) {\r
}\r
\r
/**\r
- * Returns the region's width in pixels. May be negative if the texture region is flipped horizontally.\r
+ * Returns the region's width. May be negative if the texture region is flipped horizontally.\r
*/\r
public int getRegionWidth () {\r
- return (int)((v - u) * texture.getWidth());\r
+ return (int)((u2 - u) * texture.getWidth());\r
}\r
\r
public void setRegionWidth (int width) {\r
}\r
\r
/**\r
- * Returns the region's height in pixels. May be negative if the texture region is flipped horizontally.\r
+ * Returns the region's height. May be negative if the texture region is flipped horizontally.\r
*/\r
public int getRegionHeight () {\r
- return (int)((getV2() - getV()) * texture.getHeight());\r
+ return (int)((v2 - v) * texture.getHeight());\r
}\r
\r
public void setRegionHeight (int height) {\r
- setV2(getV() + height / (float)texture.getHeight());\r
+ setV2(v + height / (float)texture.getHeight());\r
}\r
\r
public void flip (boolean x, boolean y) {\r
}\r
\r
/**\r
- * Offsets the texture region relative to the current texture region.\r
- * \r
+ * Offsets the region relative to the current region. Generally the region's size should be the entire size of the texture in\r
+ * the direction(s) it is scrolled.\r
* @param xAmount The percentage to offset horizontally.\r
* @param yAmount The percentage to offset vertically.\r
*/\r
particle.angleSin = MathUtils.sinDeg(angle);\r
}\r
\r
- particle.scale = scaleValue.newLowValue() / sprite.getWidth();\r
- particle.scaleDiff = scaleValue.newHighValue() / sprite.getWidth();\r
+ float spriteWidth = sprite.getWidth();\r
+ particle.scale = scaleValue.newLowValue() / spriteWidth;\r
+ particle.scaleDiff = scaleValue.newHighValue() / spriteWidth;\r
if (!scaleValue.isRelative()) particle.scaleDiff -= particle.scale;\r
if ((updateFlags & UPDATE_SCALE) == 0) particle.setScale(particle.scale + particle.scaleDiff * scaleValue.getScale(0));\r
\r
}\r
}\r
\r
- float spriteWidth = sprite.getWidth();\r
float spriteHeight = sprite.getHeight();\r
particle.setBounds(x - spriteWidth / 2, y - spriteHeight / 2, spriteWidth, spriteHeight);\r
}\r
private SpriteBatch spriteBatch;\r
private BitmapFont font;\r
private Sprite logoSprite;\r
- private Color red = new Color(1, 0, 0, 0.5f);\r
+ private Color red = new Color(1, 0, 0, 0);\r
private BitmapFontCache cache1, cache2, cache3, cache4, cache5;\r
int renderMode;\r
\r
\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.InputAdapter;\r
-import com.badlogic.gdx.InputProcessor;\r
-import com.badlogic.gdx.Files.FileType;\r
import com.badlogic.gdx.graphics.BitmapFont;\r
+import com.badlogic.gdx.graphics.BitmapFont.HAlignment;\r
import com.badlogic.gdx.graphics.BitmapFontCache;\r
import com.badlogic.gdx.graphics.Color;\r
import com.badlogic.gdx.graphics.GL10;\r
import com.badlogic.gdx.graphics.Sprite;\r
import com.badlogic.gdx.graphics.SpriteBatch;\r
-import com.badlogic.gdx.graphics.BitmapFont.HAlignment;\r
-import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
-import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
-import com.badlogic.gdx.math.Matrix4;\r
import com.badlogic.gdx.tests.utils.GdxTest;\r
\r
+import static com.badlogic.gdx.graphics.Texture.TextureFilter.*;\r
+import static com.badlogic.gdx.graphics.Texture.TextureWrap.*;\r
+\r
public class BitmapFontTest extends GdxTest {\r
private SpriteBatch spriteBatch;\r
private BitmapFont font;\r
private Sprite logoSprite;\r
- private Color red = new Color(1, 0, 0, 1);\r
+ private Color red = new Color(1, 0, 0, 0);\r
private BitmapFontCache cache1, cache2, cache3, cache4, cache5;\r
int renderMode;\r
\r
\r
spriteBatch = new SpriteBatch();\r
\r
- logoSprite = new Sprite(Gdx.graphics.newTexture(Gdx.files.getFileHandle("data/badlogic.jpg", FileType.Internal),\r
- TextureFilter.Linear, TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge));\r
+ logoSprite = new Sprite(Gdx.graphics.newTexture(Gdx.files.internal("data/badlogic.jpg"), Linear, Linear, ClampToEdge,\r
+ ClampToEdge));\r
logoSprite.setColor(1, 1, 1, 0.5f);\r
\r
- font = new BitmapFont(Gdx.files.getFileHandle("data/verdana39.fnt", FileType.Internal), Gdx.files.getFileHandle(\r
- "data/verdana39.png", FileType.Internal), false);\r
+ font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), Gdx.files.internal("data/verdana39.png"), false);\r
\r
cache1 = new BitmapFontCache(font);\r
cache2 = new BitmapFontCache(font);\r
\r
text = "How quickly\ndaft jumping zebras vex.";\r
cache3.setColor(Color.BLUE);\r
- cache3.setMultiLineText(text, 5, 200, 470, BitmapFont.HAlignment.CENTER);\r
+ cache3.setMultiLineText(text, 5, 200, 470, HAlignment.CENTER);\r
\r
text = "Kerning: LYA moo";\r
cache4.setText(text, 210, 66, 0, text.length() - 3);\r
\r
text = "How quickly\ndaft jumping zebras vex.";\r
font.setColor(Color.BLUE);\r
- font.drawMultiLine(spriteBatch, text, 5, 200, 470, BitmapFont.HAlignment.RIGHT);\r
+ font.drawMultiLine(spriteBatch, text, 5, 200, 470, HAlignment.RIGHT);\r
\r
text = "Kerning: LYA moo";\r
font.setColor(Color.WHITE);\r
for(int y=0; y < HEIGHT; y++) { \r
int tileX = colX - y * TILE_WIDTH / 2;\r
int tileY = colY - y * TILE_HEIGHT_DIAMOND / 2;\r
- cache.add(texture, tileX, tileY, rand.nextInt(2) * 54, 0,TILE_WIDTH, TILE_HEIGHT, Color.WHITE); \r
+ cache.add(texture, tileX, tileY, rand.nextInt(2) * 54, 0,TILE_WIDTH, TILE_HEIGHT); \r
}\r
colX += TILE_WIDTH / 2;\r
colY -= TILE_HEIGHT_DIAMOND / 2;\r
else if (keycode == Input.Keys.KEYCODE_SPACE) {\r
emitterIndex = (emitterIndex + 1) % emitters.size();\r
emitter = emitters.get(emitterIndex);\r
- particleCount = (int)(emitter.getEmission().getHighMax() * emitter.getLife().getHighMax());\r
+ particleCount = (int)(emitter.getEmission().getHighMax() * emitter.getLife().getHighMax() / 1000f);\r
} else\r
return false;\r
particleCount = Math.max(0, particleCount);\r
\r
spriteCache.beginCache();\r
for (int i = 0; i < sprites2.length; i += 6)\r
- spriteCache.add(texture2, sprites2[i], sprites2[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32, Color.WHITE,\r
+ spriteCache.add(texture2, sprites2[i], sprites2[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32,\r
false, false);\r
for (int i = 0; i < sprites.length; i += 6)\r
- spriteCache.add(texture, sprites[i], sprites[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32, Color.WHITE,\r
+ spriteCache.add(texture, sprites[i], sprites[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32,\r
false, false);\r
normalCacheID = spriteCache.endCache();\r
\r
float angle = MathUtils.random(1, 360);\r
spriteCache.beginCache(normalCacheID);\r
for (int i = 0; i < sprites2.length; i += 6)\r
- spriteCache.add(texture2, sprites2[i], sprites2[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32, Color.WHITE,\r
+ spriteCache.add(texture2, sprites2[i], sprites2[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32,\r
false, false);\r
for (int i = 0; i < sprites.length; i += 6)\r
- spriteCache.add(texture, sprites[i], sprites[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32, Color.WHITE,\r
+ spriteCache.add(texture, sprites[i], sprites[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32,\r
false, false);\r
spriteCache.endCache();\r
return false;\r
badlogicSmall.flip(true, true);\r
\r
AtlasRegion region = atlas.getRegion("badlogicsmall");\r
- System.out.println("badlogicSmall original size: " + region.getOriginalWidth() + ", " + region.getOriginalHeight());\r
- System.out.println("badlogicSmall packed size: " + region.getPackedWidth() + ", " + region.getPackedHeight());\r
+ System.out.println("badlogicSmall original size: " + region.originalWidth + ", " + region.originalHeight);\r
+ System.out.println("badlogicSmall packed size: " + region.packedWidth + ", " + region.packedHeight);\r
\r
star = atlas.getSprite("particle-star");\r
star.setPosition(10, 70);\r
for(int x = 0; x < WIDTH; x++) {\r
int tileX = rand.nextInt(5);\r
int tileY = rand.nextInt(5);\r
- cache.add(texture, x << 5, y << 5, 1 + tileX * 33, 1 + tileY * 33, 32, 32, Color.WHITE);\r
+ cache.add(texture, x << 5, y << 5, 1 + tileX * 33, 1 + tileY * 33, 32, 32);\r
}\r
} \r
layers[i] = cache.endCache();\r