本文整理汇总了Java中com.badlogic.gdx.graphics.g2d.SpriteBatch类的典型用法代码示例。如果您正苦于以下问题:Java SpriteBatch类的具体用法?Java SpriteBatch怎么用?Java SpriteBatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpriteBatch类属于com.badlogic.gdx.graphics.g2d包,在下文中一共展示了SpriteBatch类的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: ShareScoreScreen
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
ShareScoreScreen(final Klooni game, final Screen lastScreen,
final int score, final boolean timeMode) {
this.game = game;
this.lastScreen = lastScreen;
this.score = score;
this.timeMode = timeMode;
final Label.LabelStyle labelStyle = new Label.LabelStyle();
labelStyle.font = game.skin.getFont("font_small");
infoLabel = new Label("Generating image...", labelStyle);
infoLabel.setColor(Klooni.theme.textColor);
infoLabel.setAlignment(Align.center);
infoLabel.layout();
infoLabel.setPosition(
(Gdx.graphics.getWidth() - infoLabel.getWidth()) * 0.5f,
(Gdx.graphics.getHeight() - infoLabel.getHeight()) * 0.5f);
spriteBatch = new SpriteBatch();
}
示例3: VRContext
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
/**
* Creates a new VRContext, initializes the VR system,
* and sets up rendering surfaces.
*
* @param renderTargetMultiplier multiplier to scale the render surface dimensions as a replacement for multisampling
* @param hasStencil whether the rendering surfaces should have a stencil buffer
* @throws {@link GdxRuntimeException} if the system could not be initialized
*/
public VRContext(float renderTargetMultiplier, boolean hasStencil) {
int token = VR.VR_InitInternal(error, VR.EVRApplicationType_VRApplication_Scene);
checkInitError(error);
OpenVR.create(token);
VR.VR_GetGenericInterface(VR.IVRCompositor_Version, error);
checkInitError(error);
VR.VR_GetGenericInterface(VR.IVRRenderModels_Version, error);
checkInitError(error);
for (int i = 0; i < devicePoses.length; i++) {
devicePoses[i] = new VRDevicePose(i);
}
VRSystem.VRSystem_GetRecommendedRenderTargetSize(scratch, scratch2);
int width = (int)(scratch.get(0) * renderTargetMultiplier);
int height = (int)(scratch2.get(0) * renderTargetMultiplier);
setupEye(Eye.Left, width, height, hasStencil);
setupEye(Eye.Right, width, height, hasStencil);
batcher = new SpriteBatch();
}
示例4: create
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
@Override
public void create () {
//initialize Asset Handler
assetHandler = new AssetHandler();
assets = new HashMap<String,Class<?>>();
//load Game instance into GameUtils
GameUtils.loadGame(this);
//initialize Graphics
batch = new SpriteBatch();
//load starting assets
assets.put("Fonts/mainFont.fnt",BitmapFont.class);
assets.put("MenuScreen/CursedEchoMenuBackground.png", Texture.class);
this.setScreen(new LoadingScreen(assets,"default","menu",null));
}
示例5: show
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
/**
* Method responsible for initializing the pause menu
* Called when the screen becomes the current screen of the game
*/
@Override
public void show() {
// Inits:
cam = new OrthographicCamera();
viewport = new FitViewport(1920, 1080);
viewport.setCamera(cam);
stage = new Stage(viewport);
stage.setViewport(viewport);
skin = menuAssets.styles_json;
skin.getFont("bocklin").getData().setScale(0.8f, 0.8f);
int x = 1920;
int y = 1080;
spriteBatch = new SpriteBatch();
mainbackground = menuAssets.testmainscreen;
createComponents();
AL.input.setInputProcessor(new InputMultiplexer(stage, this));
}
示例6: create
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
@Override
public void create() {
this.batch = new SpriteBatch();
this.backgroundImage = new Texture("coffee.jpg");
GUIConstructor guiConstructor = new GUIConstructor();
this.guiManager = guiConstructor.instantiate("1", () -> {
Gdx.app.exit();
});
this.drawingManager = new GDXDrawingAdapter(this.batch);
this.drawVisitor = new DefaultDrawVisitor(this.drawingManager);
this.inputManager = new GDXMouse();
this.updateVisitor = new DefaultUpdateVisitor(this.inputManager);
}
示例7: create
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
@Override
public void create() {
batch = new SpriteBatch();
cam = new Camera(screenX, screenY);
batch.setProjectionMatrix(cam.camera.combined);
batch.enableBlending();
try {
save = new Save();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.setScreen(new MainMenu(this));
}
示例8: renderGuiFpsCounter
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
private void renderGuiFpsCounter(SpriteBatch batch) {
float x = cameraGUI.viewportWidth - 55;
float y = cameraGUI.viewportHeight - 15;
int fps = Gdx.graphics.getFramesPerSecond();
BitmapFont fpsFont = Assets.instance.fonts.defaultNormal;
if (fps >= 45) {
// 45 or more FPS show up in green
fpsFont.setColor(0, 1, 0, 1);
} else if (fps >= 30) {
// 30 or more FPS show up in yellow
fpsFont.setColor(1, 1, 0, 1);
} else {
// less than 30 FPS show up in red
fpsFont.setColor(1, 0, 0, 1);
}
fpsFont.draw(batch, "FPS: " + fps, x, y);
fpsFont.setColor(1, 1, 1, 1);
}
示例9: drawLines
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
public static void drawLines(SpriteBatch batch) {
if (!Settings.getBooleanSettingValue(Settings.DEBUG_FRAMETIME_GRAPH))
return;
float width = width();
int size = frametimeGraph.frametimes.size();
while (size < width) {
frametimeGraph.frametimes.addFirst(0f);
size = frametimeGraph.frametimes.size();
}
for (int i = 0; i <= 16; i++) {
batch.draw(textureLine, 0, yOffset + (scale * i), width, 1);
}
batch.draw(textureLine60, 0, yOffset + (scale * 16.666666f), width, 1);
}
示例10: GameScreen
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
public GameScreen(){
spriteBatch = new SpriteBatch(); // buffer ok
texture = new Texture(Gdx.files.internal("bg/gameBG.jpg"));
viewMatrix = new Matrix4(); // matriz de visualização
tranMatrix = new Matrix4(); // matriz de escala
// camera
camera = new PerspectiveCamera(67.0f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.near = 0.1f;
camera.far = 1000f;
camera.position.set(0, 5, 10);
camera.lookAt(0, 5, 0);
camera.update();
// ambiente
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 1,1,1,1));
// renderizador
modelBatch = new ModelBatch();
p1 = new Player(1);
p2 = new Player(2);
}
示例11: create
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
@Override
public void create() {
if (androidInterface != null)
androidInterface.tryToStopMusicApp();
batch = new SpriteBatch();
sr = new ShapeRenderer();
camera = new OrthographicCamera();
viewport = new FitViewport(Configuration.WINDOW_WIDTH, Configuration.WINDOW_HEIGHT, camera);
camera.position.set(viewport.getWorldWidth() / 2 - (viewport.getWorldWidth() - 500) / 2, viewport.getWorldHeight() / 2 - (viewport.getWorldHeight() - 220) / 2, 0);
camera.update();
fade = new Sprite(new Texture("sprites/fade.png"));
fade.setBounds(0, -100, viewport.getWorldWidth(), viewport.getWorldHeight() - 40);
font = new BitmapFont(Gdx.files.internal("fonts/amiga4everpro2.fnt"));
showModernTimesCutscene(); // start the game
}
示例12: draw
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
@Override
public void draw(GameTime time, SpriteBatch batch) {
// set camera projection matrix
batch.setProjectionMatrix(game.getUICamera().combined);
// draw background
batch.draw(this.bgImage, 0, 0, game.getViewportWidth(), game.getViewportHeight());
// draw first (SpriteBatch) layer of HUD
this.hud.drawLayer0(time, batch);
batch.flush();
batch.end();
// draw second layer (ShapeRenderer) of HUD
this.shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
this.shapeRenderer.setProjectionMatrix(game.getUICamera().combined);
this.hud.drawLayer1(time, this.shapeRenderer);
this.shapeRenderer.end();
// draw last (SpriteBatch) layer of HUD
batch.begin();
batch.setProjectionMatrix(game.getUICamera().combined);
this.hud.drawLayer2(time, batch);
}
示例13: draw
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
@Override
public void draw(GameTime time, CameraWrapper camera, SpriteBatch batch) {
// if no texture is set, we don't have to draw anything
if (this.texture == null) {
return;
}
// only draw texture, if entity is visible
if (this.visible) {
// draw texture
batch.draw(this.texture,
this.positionComponent.getX() + this.getPaddingLeft()/* - originX */,
this.positionComponent.getY() + this.getPaddingBottom()/* - originY */, originX, originY, getWidth(), getHeight(), scaleX,
scaleY, angle, 0, // srcX
0, // srcY
this.texture.getWidth(), this.texture.getHeight(), false, false);
}
}
示例14: draw
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
public void draw(GameTime time, SpriteBatch batch) {
// draw background texture
if (hovered) {
batch.draw(this.hoverTexture, x, y);
} else {
batch.draw(this.bgTexture, x, y);
}
float paddingBottom = (this.height / 2) - 32;
// draw icon
if (iconTexture != null) {
batch.draw(iconTexture, x + 10, y + paddingBottom);
}
// draw button text
this.font.draw(batch, text, x + 80, y + 60);
}
示例15: ScreenExtensions
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //导入依赖的package包/类
public ScreenExtensions(GameManager gameManager) {
this.gameManager = gameManager;
manager = ManagerAssets.getInstance();
addExtensions = this;
camera = new PerspectiveCamera(40, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(0, 0, Gdx.graphics.getHeight() * 0.183f);//initial 180
camera.lookAt(0, 0, 0);
camera.far = 2500;
camera.near = 1;
camera.update();
controller = new CameraInputController(camera);
cam = new OrthographicCamera();
batchsprite = new SpriteBatch();
renderer = new ImmediateModeRenderer20(false, true, 1);
gd = new GestureDetector(this);
}