本文整理匯總了Java中com.badlogic.gdx.graphics.g2d.SpriteBatch.draw方法的典型用法代碼示例。如果您正苦於以下問題:Java SpriteBatch.draw方法的具體用法?Java SpriteBatch.draw怎麽用?Java SpriteBatch.draw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.graphics.g2d.SpriteBatch
的用法示例。
在下文中一共展示了SpriteBatch.draw方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawSprite
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
private void drawSprite(SpriteBatch batch, Sprite sprite, int scene, Interactable interactable) {
if (interactable.isConsumed()) {
sprite.draw(batch);
return;
}
Rectangle handle = null;
if (dragsLeftHandle)
handle = rectangleLeftHandle;
if (dragsRightHandle)
handle = rectangleRightHandle;
if (handle == null)
return;
float percentage = (Math.min(sprite.getWidth(), Math.max(0, handle.x - sprite.getX())) / sprite.getWidth());
boolean reverseDirection = (scene == 1 && dragsLeftHandle || scene == 2 && dragsRightHandle);
if (reverseDirection) {
percentage = 1 - percentage;
}
int visibleWidth = (int) (sprite.getWidth() * percentage);
batch.draw(sprite.getTexture(), (reverseDirection ? sprite.getWidth() - visibleWidth : 0) + sprite.getX(), sprite.getY(), sprite.getWidth() / 2, sprite.getHeight() / 2, visibleWidth, sprite.getHeight(), sprite.getScaleX() * (interactable.isConsumable() ? scaleFactor : 1),
sprite.getScaleY() * (interactable.isConsumable() ? scaleFactor : 1), 0, sprite.getRegionX(), sprite.getRegionY(), (int) (sprite.getRegionWidth() * percentage), sprite.getRegionHeight(), reverseDirection, false);
}
示例2: drawView
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
private void drawView(int x, int y, SpriteBatch batch) {
// set temporary values to vectors
minVector.set(x, y, 0);
maxVector.set(x + width, y + height, 0);
// update bounding box
this.rectangle.set(minVector, maxVector);
int index = getIndex(x, y);
if (index < 0) {
int abs = Math.abs(index);
abs += skyboxTextures.length;
index = abs % skyboxTextures.length;
}
batch.draw(skyboxTextures[index], x * width, y * height, width, height);
}
示例3: render
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
@Override
public void render(SpriteBatch sb, ShapeRenderer sr) {
sb.setProjectionMatrix(camera.combined);
sr.setAutoShapeType(true);
sr.setProjectionMatrix(camera.combined);
//BACKGROUND
sr.begin();
sr.set(ShapeRenderer.ShapeType.Filled);
sr.setColor(Color.WHITE);
sr.rect(0, 0, Game.WIDTH, Game.HEIGHT);
sr.end();
//LOGO
sb.begin();
sb.draw(logo, Game.WIDTH / 2 - logo.getWidth() * 20 / 2, Game.HEIGHT / 2 - logo.getHeight() * 20 / 2, logo.getWidth() * 20, logo.getHeight() * 20);
sb.end();
}
示例4: render
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
@Override
public void render(SpriteBatch sb) {
sb.setProjectionMatrix(camera.combined);
sb.begin();
sb.draw(background, 0, 0);
sb.draw(playBtn, camera.position.x - playBtn.getWidth() / 2, camera.position.y);
sb.end();
}
示例5: render
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
public void render(SpriteBatch batch, float delta) {
update(delta);
batch.begin();
batch.draw(mRegion, x * Constant.RATE - mRegion.getRegionWidth() / 2
, y * Constant.RATE - mRegion.getRegionHeight() / 2);
batch.end();
}
示例6: render
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
@Override
public void render(SpriteBatch batch)
{
batch.setColor(1.0f, 1.0f, 1.0f, 0.5f);
batch.draw(highlightingGraphic, gameObject.getX(), gameObject.getY(), gameObject.getWidth(),
gameObject.getHeight());
batch.setColor(1.0f, 1.0f, 1.0f, 1.0f);
}
示例7: renderGuiExtraLives
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
private void renderGuiExtraLives(SpriteBatch batch) {
float x = cameraGUI.viewportWidth - 50 - Constants.LIVES_START * 50;
float y = -15;
for (int i = 0; i < Constants.LIVES_START; ++i) {
if (worldController.lives <= i)
batch.setColor(0.5f, 0.5f, 0.5f, 0.5f);
batch.draw(Assets.instance.bunny.head, x + i * 50, y, 50, 50, 120, 100, 0.35f, -0.35f, 0);
batch.setColor(1, 1, 1, 1);
}
}
示例8: draw
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
public void draw(SpriteBatch spriteBatch) {
// Draw if needed to be drawn
if (isBeingShown) {
spriteBatch.draw(texture, x, y, width, height);
}
}
示例9: drawMountain
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
private void drawMountain(SpriteBatch batch, float offsetX, float offsetY, float tintColor) {
TextureRegion reg = null;
batch.setColor(tintColor, tintColor, tintColor, 1);
float xRel = dimension.x * offsetX;
float yRel = dimension.y * offsetY;
//山區跨越整個關卡
int mountainLength = 0;
mountainLength += MathUtils.ceil(length / (2 * dimension.x));
mountainLength += MathUtils.ceil(0.5f + offsetX);
for (int i = 0; i < mountainLength; i++) {
// mountain left
reg = regMountainLeft;
batch.draw(reg.getTexture(), origin.x + xRel, position.y + origin.y
+ yRel, origin.x, origin.y, dimension.x, dimension.y,
scale.x, scale.y, rotation, reg.getRegionX(),
reg.getRegionY(), reg.getRegionWidth(),
reg.getRegionHeight(), false, false);
xRel += dimension.x;
// mountain right
reg = regMountainRight;
batch.draw(reg.getTexture(), origin.x + xRel, position.y + origin.y
+ yRel, origin.x, origin.y, dimension.x, dimension.y,
scale.x, scale.y, rotation, reg.getRegionX(),
reg.getRegionY(), reg.getRegionWidth(),
reg.getRegionHeight(), false, false);
xRel += dimension.x;
}
// reset color to white
batch.setColor(1, 1, 1, 1);
}
示例10: setFrame
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
private void setFrame(SpriteBatch batch, Animation animation, TextureRegion[] regions, float delta) {
mWidth = regions[0].getRegionWidth();
mHeight = regions[0].getRegionHeight();
batch.draw(animation.getKeyFrame(delta, true),
mBody.getPosition().x * Constant.RATE - mWidth / 2,
mBody.getPosition().y * Constant.RATE - mHeight / 2);
}
示例11: render
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
@Override
public void render(SpriteBatch sb) {
sb.setProjectionMatrix(cam.combined);
sb.begin();
sb.draw(bg, 0, 0, GameTutorial.WIDTH, GameTutorial.HEIGHT);
sb.end();
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
示例12: render
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
@Override
public void render(SpriteBatch spriteBatch) {
if (collected) {
return;
}
TextureRegion reg = null;
reg = regGoldCoin;
spriteBatch.draw(reg.getTexture(), position.x, position.y, origin.x, origin.y,
dimension.x, dimension.y, scale.x, scale.y, rotation,
reg.getRegionX(), reg.getRegionY(), reg.getRegionWidth(), reg.getRegionHeight(), false, false);
}
示例13: drawToBuffer
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
/**
* Draws the given gradient {@link Texture} to the given {@link FrameBuffer}, using the given {@link Color} with the given percent.
* <p>
* This is achieved via a gradient shader.
*
* @param buffer the {@link FrameBuffer} to be drawn to
* @param color the {@link Color} which should be drawn
* @param gradient the gradient texture which should be drawn
* @param perc the percent the gradient texture should be drawn
* @param shaderBatch the {@link SpriteBatch} to use
* @param shader the {@link ShaderProgram} to use
* @param projection projection matrix for pixel perfect rendering
*/
private static void drawToBuffer(FrameBuffer buffer, Color color, Texture gradient, float perc, SpriteBatch shaderBatch, ShaderProgram shader, Matrix4 projection) {
buffer.begin();
AL.graphics.getGL20().glClearColor(0, 0, 0, 0);
AL.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);
shaderBatch.setProjectionMatrix(projection);
shaderBatch.begin();
shaderBatch.setColor(color);
shader.setUniformf("u_gradient", perc);
shaderBatch.draw(gradient, -buffer.getWidth() / 2, -buffer.getHeight() / 2);
shaderBatch.end();
buffer.end();
}
示例14: drawLayer0
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
@Override
public void drawLayer0(GameTime time, SpriteBatch batch) {
// draw background texture
if (hovered) {
batch.draw(this.hoverTexture, getX(), getY(), getWidth(), getHeight());
} else {
batch.draw(this.texture, getX(), getY(), getWidth(), getHeight());
}
}
示例15: setFrame
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
private void setFrame(SpriteBatch batch, Animation animation, TextureRegion[] regions, float delta) {
mWidth = regions[0].getRegionWidth();
mHeight = regions[0].getRegionHeight();
if (STATE == State.STATE_RIGHT) {
batch.draw(animation.getKeyFrame(delta, true),
mMonkey.getBody().getPosition().x * Constant.RATE,
mMonkey.getBody().getPosition().y * Constant.RATE - mHeight / 2);
} else {
batch.draw(animation.getKeyFrame(delta, true),
mMonkey.getBody().getPosition().x * Constant.RATE - mWidth,
mMonkey.getBody().getPosition().y * Constant.RATE - mHeight / 2);
}
}