use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class NinePatchTest method newMidlessPatch.
// Make a ninepatch with no middle band, just top three and bottom three.
static NinePatch newMidlessPatch() {
final int patchSize = 8;
final int fullPatchHeight = patchSize * 2;
final int fullPatchWidth = patchSize * 3;
final int pixmapDim = MathUtils.nextPowerOfTwo(Math.max(fullPatchWidth, fullPatchHeight));
Pixmap testPatch = new Pixmap(pixmapDim, pixmapDim, Pixmap.Format.RGBA8888);
testPatch.setColor(1, 1, 1, 0);
testPatch.fill();
for (int x = 0; x < fullPatchWidth; x += patchSize) {
for (int y = 0; y < fullPatchHeight; y += patchSize) {
testPatch.setColor(x / (float) fullPatchWidth, y / (float) fullPatchHeight, 1.0f, 1.0f);
testPatch.fillRectangle(x, y, patchSize, patchSize);
}
}
return new NinePatch(new TextureRegion(new Texture(testPatch), fullPatchWidth, fullPatchHeight), patchSize, patchSize, patchSize, patchSize);
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class ComplexActionTest method create.
@Override
public void create() {
stage = new Stage();
Action complexAction = forever(sequence(parallel(rotateBy(180, 2), scaleTo(1.4f, 1.4f, 2), alpha(0.7f, 2)), parallel(rotateBy(180, 2), scaleTo(1.0f, 1.0f, 2), alpha(1.0f, 2))));
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), false);
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
final Image img1 = new Image(new TextureRegion(texture));
img1.setSize(100, 100);
img1.setOrigin(50, 50);
img1.setPosition(50, 50);
final Image img2 = new Image(new TextureRegion(texture));
img2.setSize(50, 50);
img2.setOrigin(50, 50);
img2.setPosition(150, 150);
stage.addActor(img1);
stage.addActor(img2);
img1.addAction(complexAction);
// img2.action(complexAction.copy());
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class SuperKoalio method renderKoala.
private void renderKoala(float deltaTime) {
// based on the koala state, get the animation frame
TextureRegion frame = null;
switch(koala.state) {
case Standing:
frame = stand.getKeyFrame(koala.stateTime);
break;
case Walking:
frame = walk.getKeyFrame(koala.stateTime);
break;
case Jumping:
frame = jump.getKeyFrame(koala.stateTime);
break;
}
// draw the koala, depending on the current velocity
// on the x-axis, draw the koala facing either right
// or left
Batch batch = renderer.getBatch();
batch.begin();
if (koala.facesRight) {
batch.draw(frame, koala.position.x, koala.position.y, Koala.WIDTH, Koala.HEIGHT);
} else {
batch.draw(frame, koala.position.x + Koala.WIDTH, koala.position.y, -Koala.WIDTH, Koala.HEIGHT);
}
batch.end();
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class MainShader method bindSpotShadows.
public void bindSpotShadows(final Attributes attributes) {
final SpotLightsAttribute sla = attributes.get(SpotLightsAttribute.class, SpotLightsAttribute.Type);
final Array<SpotLight> spots = sla == null ? null : sla.lights;
if (spotLightsLoc >= 0) {
for (int i = 0; i < spotLights.length; i++) {
if (spots == null || spots.size <= i) {
continue;
}
int idx = spotShadowsLoc + i * spotShadowsSize;
// Shadow
ObjectMap<SpotLight, LightProperties> spotCameras = shadowSystem.getSpotCameras();
SpotLight sl = spots.get(i);
if (shadowSystem.hasLight(sl)) {
// UVTransform
final TextureRegion tr = spotCameras.get(sl).region;
Camera cam = spotCameras.get(sl).camera;
if (cam != null) {
program.setUniformf(idx + spotShadowsUvTransformOffset, tr.getU(), tr.getV(), tr.getU2() - tr.getU(), tr.getV2() - tr.getV());
// ProjViewTrans
idx = spotShadowMapProjViewTransLoc + i * spotShadowMapProjViewTransSize;
program.setUniformMatrix(idx, spotCameras.get(sl).camera.combined);
}
}
if (spotLightsSize <= 0)
break;
}
}
}
use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.
the class BaseShadowSystem method processViewport.
/** Set viewport according to allocator.
* @param lp LightProperties to process.
* @param cameraViewport Set camera viewport if true. */
protected void processViewport(LightProperties lp, boolean cameraViewport) {
Camera camera = lp.camera;
ShadowMapRegion r = allocator.nextResult(currentLight);
if (r == null)
return;
TextureRegion region = lp.region;
region.setTexture(frameBuffers[currentPass].getColorBufferTexture());
// We don't use HdpiUtils
// gl commands related to shadow map size and not to screen size
Gdx.gl.glViewport(r.x, r.y, r.width, r.height);
Gdx.gl.glScissor(r.x + 1, r.y + 1, r.width - 2, r.height - 2);
region.setRegion(r.x, r.y, r.width, r.height);
if (cameraViewport) {
camera.viewportHeight = r.height;
camera.viewportWidth = r.width;
camera.update();
}
}
Aggregations