当前位置: 首页>>代码示例>>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;未经允许,请勿转载。