use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class SuperKoalio method create.
@Override
public void create() {
// load the koala frames, split them, and assign them to Animations
koalaTexture = new Texture("data/maps/tiled/super-koalio/koalio.png");
TextureRegion[] regions = TextureRegion.split(koalaTexture, 18, 26)[0];
stand = new Animation(0, regions[0]);
jump = new Animation(0, regions[1]);
walk = new Animation(0.15f, regions[2], regions[3], regions[4]);
walk.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);
// figure out the width and height of the koala for collision
// detection and rendering by converting a koala frames pixel
// size into world units (1 unit == 16 pixels)
Koala.WIDTH = 1 / 16f * regions[0].getRegionWidth();
Koala.HEIGHT = 1 / 16f * regions[0].getRegionHeight();
// load the map, set the unit scale to 1/16 (1 unit == 16 pixels)
map = new TmxMapLoader().load("data/maps/tiled/super-koalio/level1.tmx");
renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f);
// create an orthographic camera, shows us 30x20 units of the world
camera = new OrthographicCamera();
camera.setToOrtho(false, 30, 20);
camera.update();
// create the Koala we want to move around the world
koala = new Koala();
koala.position.set(20, 20);
debugRenderer = new ShapeRenderer();
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class MainShader method bindDirectionalShadows.
public void bindDirectionalShadows(final Attributes attributes) {
final DirectionalLightsAttribute dla = attributes.get(DirectionalLightsAttribute.class, DirectionalLightsAttribute.Type);
final Array<DirectionalLight> dirs = dla == null ? null : dla.lights;
if (dirLightsLoc >= 0) {
for (int i = 0; i < directionalLights.length; i++) {
if (dirs == null || dirs.size <= i) {
continue;
}
int idx = dirShadowsLoc + i * dirShadowsSize;
// Shadow
ObjectMap<DirectionalLight, LightProperties> dirCameras = shadowSystem.getDirectionalCameras();
DirectionalLight dl = dirs.get(i);
if (shadowSystem.hasLight(dl)) {
// UVTransform
final TextureRegion tr = dirCameras.get(dl).region;
Camera cam = dirCameras.get(dl).camera;
if (cam != null) {
program.setUniformf(idx + dirShadowsUvTransformOffset, tr.getU(), tr.getV(), tr.getU2() - tr.getU(), tr.getV2() - tr.getV());
// ProjViewTrans
idx = dirShadowMapProjViewTransLoc + i * dirShadowMapProjViewTransSize;
program.setUniformMatrix(idx, dirCameras.get(dl).camera.combined);
}
}
if (dirLightsSize <= 0)
break;
}
}
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class Decal method updateUVs.
/** Re-applies the uv coordinates from the material's texture region to the uv components of the vertices array */
protected void updateUVs() {
TextureRegion tr = material.textureRegion;
// left top
vertices[U1] = tr.getU();
vertices[V1] = tr.getV();
// right top
vertices[U2] = tr.getU2();
vertices[V2] = tr.getV();
// left bot
vertices[U3] = tr.getU();
vertices[V3] = tr.getV2();
// right bot
vertices[U4] = tr.getU2();
vertices[V4] = tr.getV2();
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class APKExpansionTest method create.
@Override
public void create() {
if ((((AndroidFiles) Gdx.files)).setAPKExpansion(1, 0)) {
resolver = new ZipFileHandleResolver();
} else {
Gdx.app.error("libgdx", "No Expansion can be opened");
}
assetManager = new AssetManager();
FileHandleResolver resolver = new InternalFileHandleResolver();
assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
assetManager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
loadFont(assetManager, "data/DroidSerif-Regular.ttf", 12);
loadFont(assetManager, "data/" + extensionPrefix + "DroidSerif-Regular.ttf", 12);
assetManager.load("data/" + extensionPrefix + "testpackobb", TextureAtlas.class);
assetManager.finishLoading();
sound = Gdx.audio.newSound(Gdx.files.internal("data/" + extensionPrefix + "chirp.ogg"));
sound.play();
texture = new Texture(resolver.resolve("data/" + extensionPrefix + "badlogic.jpg"));
batch = new SpriteBatch();
TextureAtlas atlas = assetManager.get("data/" + extensionPrefix + "testpackobb");
atlasTextureRegion = new TextureRegion(atlas.findRegion("water"));
sound = Gdx.audio.newSound(Gdx.files.internal("data/shotgun.ogg"));
sound.play();
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class TiledDrawable method draw.
public void draw(Batch batch, float x, float y, float width, float height) {
float batchColor = batch.getPackedColor();
batch.setColor(batch.getColor().mul(color));
TextureRegion region = getRegion();
float regionWidth = region.getRegionWidth(), regionHeight = region.getRegionHeight();
int fullX = (int) (width / regionWidth), fullY = (int) (height / regionHeight);
float remainingX = width - regionWidth * fullX, remainingY = height - regionHeight * fullY;
float startX = x, startY = y;
float endX = x + width - remainingX, endY = y + height - remainingY;
for (int i = 0; i < fullX; i++) {
y = startY;
for (int ii = 0; ii < fullY; ii++) {
batch.draw(region, x, y, regionWidth, regionHeight);
y += regionHeight;
}
x += regionWidth;
}
Texture texture = region.getTexture();
float u = region.getU();
float v2 = region.getV2();
if (remainingX > 0) {
// Right edge.
float u2 = u + remainingX / texture.getWidth();
float v = region.getV();
y = startY;
for (int ii = 0; ii < fullY; ii++) {
batch.draw(texture, x, y, remainingX, regionHeight, u, v2, u2, v);
y += regionHeight;
}
// Upper right corner.
if (remainingY > 0) {
v = v2 - remainingY / texture.getHeight();
batch.draw(texture, x, y, remainingX, remainingY, u, v2, u2, v);
}
}
if (remainingY > 0) {
// Top edge.
float u2 = region.getU2();
float v = v2 - remainingY / texture.getHeight();
x = startX;
for (int i = 0; i < fullX; i++) {
batch.draw(texture, x, y, regionWidth, remainingY, u, v2, u2, v);
x += regionWidth;
}
}
batch.setColor(batchColor);
}
Aggregations