當前位置: 首頁>>代碼示例>>Java>>正文


Java SpriteBatch.draw方法代碼示例

本文整理匯總了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);
}
 
開發者ID:cdetamble,項目名稱:nomoore,代碼行數:22,代碼來源:ScreenGame.java

示例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);
}
 
開發者ID:opensourcegamedev,項目名稱:SpaceChaos,代碼行數:19,代碼來源:SkyBox.java

示例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();
}
 
開發者ID:MrGussio,項目名稱:EarthInvadersGDX,代碼行數:19,代碼來源:SplashScreen.java

示例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();

}
 
開發者ID:kirdmiv,項目名稱:Flappy-Baranus,代碼行數:10,代碼來源:MenuState.java

示例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();
}
 
開發者ID:heyzqt,項目名稱:libGdx-xiyou,代碼行數:9,代碼來源:Tao.java

示例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);
}
 
開發者ID:MMORPG-Prototype,項目名稱:MMORPG_Prototype,代碼行數:9,代碼來源:GameObjectHighlightGraphic.java

示例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);
    }
}
 
開發者ID:davyjoneswang,項目名稱:libgdx-learnlib,代碼行數:11,代碼來源:WorldRenderer.java

示例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);
	}
	
}
 
開發者ID:ja-brouil,項目名稱:StarshipFighters,代碼行數:9,代碼來源:Background.java

示例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);
}
 
開發者ID:davyjoneswang,項目名稱:libgdx-learnlib,代碼行數:32,代碼來源:Mountains.java

示例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);
}
 
開發者ID:heyzqt,項目名稱:libGdx-xiyou,代碼行數:8,代碼來源:Monkey.java

示例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();

}
 
開發者ID:MissionBit,項目名稱:summer17-android,代碼行數:12,代碼來源:CharacterState.java

示例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);

}
 
開發者ID:davyjoneswang,項目名稱:libgdx-learnlib,代碼行數:14,代碼來源:Feather.java

示例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();
}
 
開發者ID:EtherWorks,項目名稱:arcadelegends-gg,代碼行數:27,代碼來源:CharacterRenderer.java

示例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());
    }
}
 
開發者ID:opensourcegamedev,項目名稱:SpaceChaos,代碼行數:10,代碼來源:ImageButton.java

示例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);
	}
}
 
開發者ID:heyzqt,項目名稱:libGdx-xiyou,代碼行數:14,代碼來源:JumpBall.java


注:本文中的com.badlogic.gdx.graphics.g2d.SpriteBatch.draw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。