Java Code Examples for com.badlogic.gdx.graphics.g2d.SpriteBatch

The following are top voted examples for showing how to use com.badlogic.gdx.graphics.g2d.SpriteBatch. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: nomoore   File: ScreenGame.java   Source Code and License 7 votes vote down vote up
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);
}
 
Example 2
Project: Klooni1010   File: ShareScoreScreen.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 3
Project: Tower-Defense-Galaxy   File: VRContext.java   Source Code and License 6 votes vote down vote up
/**
 * 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();
}
 
Example 4
Project: CursedEcho   File: Main.java   Source Code and License 6 votes vote down vote up
@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));
}
 
Example 5
Project: arcadelegends-gg   File: PauseMenuScreen.java   Source Code and License 6 votes vote down vote up
/**
 * 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));
}
 
Example 6
Project: INFSEN01-2   File: Program.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 7
Project: JGame   File: JGame.java   Source Code and License 6 votes vote down vote up
@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));

}
 
Example 8
Project: libgdx-learnlib   File: WorldRenderer.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 9
Project: Cubes_2   File: FrametimeGraph.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 10
Project: StreetCampusFighter   File: GameScreen.java   Source Code and License 6 votes vote down vote up
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);
	
	
	
}
 
Example 11
Project: nomoore   File: MyGdxGame.java   Source Code and License 6 votes vote down vote up
@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
}
 
Example 12
Project: SpaceChaos   File: MainMenuScreen.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 13
Project: SpaceChaos   File: DrawTextureComponent.java   Source Code and License 6 votes vote down vote up
@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);
    }
}
 
Example 14
Project: SpaceChaos   File: ImageButton.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 15
Project: enklave   File: ScreenExtensions.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 16
Project: SpaceChaos   File: Entity.java   Source Code and License 5 votes vote down vote up
public void drawUILayer(GameTime time, CameraWrapper camera, SpriteBatch batch) {
    // draw all components
    for (IDrawUILayerComponent component : this.drawUILayerComponentList) {
        component.drawUILayer(time, camera, batch);
    }

    /*
     * this.drawUILayerComponentList.stream().forEach(component -> {
     * component.drawUILayer(time, camera, batch); });
     */
}
 
Example 17
Project: GDX-Engine   File: BaseGameScene3D.java   Source Code and License 5 votes vote down vote up
@Override 
public void renderGL2(float gameTime)
{
	GLCommon gl = Gdx.gl;
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
	
	SpriteBatch batch = getSpriteBatch();
	viewMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	batch.setProjectionMatrix(viewMatrix);
	batch.begin();
	batch.disableBlending();
	batch.setColor(Color.WHITE);
	//begin render background
	renderBackground(gameTime);
	batch.enableBlending();
	batch.end();
	gl.glEnable(GL10.GL_DEPTH_TEST);
	gl.glEnable(GL10.GL_CULL_FACE);
	camera.update();
	
	for(IDrawable3D obj : collection)
		if(obj.isVisible())
		{
			obj.renderGL2(gameTime);
		}
	gl.glDisable(GL10.GL_CULL_FACE);
	gl.glDisable(GL10.GL_DEPTH_TEST);

	batch.setProjectionMatrix(viewMatrix);
	batch.begin();
	
	//begin render foreground
	renderForeground(gameTime);
	
	//batch.enableBlending();
	//batch.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
	batch.end();
}
 
Example 18
Project: arcadelegends-gg   File: LevelScreen.java   Source Code and License 5 votes vote down vote up
@Override
public void show() {
    if (arcadeWorld == null || reInit) {
        AL.getAudioManager().registerSound("sword_1", levelAssets.sword_1);
        AL.getAudioManager().registerSound("sword_2", levelAssets.sword_2);
        AL.getAudioManager().registerSound("sword_3", levelAssets.sword_3);
        AL.getAudioManager().registerSound("sword_4", levelAssets.sword_4);
        AL.getAudioManager().registerSound("rocketlauncher", levelAssets.rocketLauncher);
        AL.getAudioManager().registerSound("boom", levelAssets.boom);
        spriteBatch = new SpriteBatch();
        font = new BitmapFont();

        camera = new PerspectiveCamera();
        camera.far = 1000;
        camera.position.set(new Vector3(-.5f, -.5f, 35));
        camera.rotateAround(new Vector3(-.5f, -.5f, 0), Vector3.X, rot);
        camera.fieldOfView = 15;
        camera.update();
        viewport = new ExtendViewport(1920, 1080, camera);
        viewport.apply();
        uiCamera = new OrthographicCamera();
        uiViewport = new FitViewport(1920, 1080, uiCamera);
        uiStage = new Stage(uiViewport);

        map = levelAssets.get(mapName);

        arcadeWorld = new ArcadeWorld(map, rot, camera, levelAssets);

        initUI();

        reInit = false;
        playerEnt = -1;

        spawnPlayer();
        enemies = arcadeWorld.spawnEnemies(playerEnt);
        arcadeWorld.setDebug(AL.getMiscellaneousConfig().debug());
    }

    Gdx.input.setInputProcessor(this);
}
 
Example 19
Project: ggvm   File: HorizontalMirroringRenderManager.java   Source Code and License 5 votes vote down vote up
private void drawNametable(GGVm ggvm, SpriteBatch spriteBatch, int scrollX, int scrollY, float splitYStart, float splitYEnd) {
    int patternTable = ggvm.getBackgroundPatternTableAddress() == 0 ? 0 : 1;

    boolean toggleNametableEarly = false;
    if (scrollY > 239 && scrollY <= 255) {
        scrollY -= 16;
        toggleNametableEarly = true;
    }

    int coarseScrollX = scrollX >> 3;
    int coarseScrollY = scrollY >> 3;
    int fineScrollX = scrollX & 7;
    int fineScrollY = scrollY & 7;

    int nameTableX = coarseScrollX;
    int nameTableY = coarseScrollY;
    int actualNameTableX;
    int actualNameTableY;
    int screenX = 0;
    int screenY = 8;
    int nameTableRowCount = fineScrollY == 0 ? 30 : 31;
    int nameTableColumnCount = 33;
    int nameTable;

    while (nameTableColumnCount > 0) {
        screenY = 0;
        nameTableRowCount = fineScrollY == 0 ? 30 : 31;
        nameTableY = coarseScrollY;
        nameTable = (ggvm.getNametableAddress() == Ppu.NAME_TABLE_0_BASE_ADDRESS) ? 0 : 1;
        if (toggleNametableEarly) {
            nameTable ^= 1;
        }
        while (nameTableRowCount > 0) {
            actualNameTableX = nameTableX % 32;
            actualNameTableY = nameTableY % 30;
            int whichNameTable = nameTable ^ (nameTableY / 30);

            int nameTableAddress = whichNameTable == 1 ? Ppu.NAME_TABLE_2_BASE_ADDRESS : Ppu.NAME_TABLE_0_BASE_ADDRESS;
            int attributeTableAddress = whichNameTable == 1 ? Ppu.ATTRIBUTE_TABLE_2_BASE_ADDRESS : Ppu.ATTRIBUTE_TABLE_0_BASE_ADDRESS;

            int index = ggvm.getNametableTile(nameTableAddress, actualNameTableX, actualNameTableY);
            int attribute = ggvm.getAttributeForNametableTile(attributeTableAddress, actualNameTableX, actualNameTableY);

            int indexRow = index >> 4;
            int indexColumn = index & 0x0f;
            Sprite sprite = patternTableManager.getSprite(patternTable, indexRow, indexColumn);//patternTableSprites[patternTableOffset * 16 + indexRow][indexColumn];
            sprite.setColor(0, attributes[attribute], 0, 0);
            if (!GGVmRegisterStatusBar.isSprite0HitStatusBarEnabled() || (screenY >= splitYStart && screenY < splitYEnd)) {
                sprite.setPosition(screenX - fineScrollX, 232 - screenY + fineScrollY);
                sprite.draw(spriteBatch);
            }
            screenY += 8;
            nameTableY++;
            nameTableRowCount--;
        }
        screenX += 8;
        nameTableX++;
        nameTableColumnCount--;
    }
}
 
Example 20
Project: skycity   File: Hud.java   Source Code and License 5 votes vote down vote up
public Hud(SpriteBatch batch){
    viewport = new FillViewport(Config.SCREEN_WIDTH,Config.SCREEN_HEIGHT,new OrthographicCamera());
    stage = new Stage(viewport,batch);
    labelHP = new Label("HP: 100/100", Assets.getInstance().getSkin());
    labelVP = new Label("VP: 100/100",Assets.getInstance().getSkin());

    table = new Table();
    table.setFillParent(true);
    table.top().right().padTop(20).padRight(20).setDebug(false);
    table.add(labelHP);
    table.row();
    table.add(labelVP);
    stage.addActor(table);
}
 
Example 21
Project: ggvm   File: VerticalMirroringRenderManager.java   Source Code and License 5 votes vote down vote up
private void drawNametable(GGVm ggvm, SpriteBatch spriteBatch, int startingNametableAddress, int scrollX, int scrollY, float splitYStart, float splitYEnd) {
    int patternTable = ggvm.getBackgroundPatternTableAddress() == 0 ? 0 : 1;

    int coarseScrollX = scrollX >> 3;
    int coarseScrollY = scrollY >> 3;
    int fineScrollX = scrollX & 7;
    int fineScrollY = scrollY & 7;

    int nameTableX = coarseScrollX;
    int nameTableY = coarseScrollY;
    int actualNameTableX;
    int actualNameTableY;
    int screenX = 0;
    int screenY = 0;
    int nameTableRowCount = fineScrollY == 0 ? 30 : 31;
    int nameTableColumnCount;
    int nameTable;

    while (nameTableRowCount > 0) {
        screenX = 0;
        nameTableColumnCount = fineScrollX == 0 ? 32 : 33;
        nameTableX = coarseScrollX;
        nameTable = (startingNametableAddress == Ppu.NAME_TABLE_0_BASE_ADDRESS || startingNametableAddress == Ppu.NAME_TABLE_2_BASE_ADDRESS) ? 0 : 1;
        while (nameTableColumnCount > 0) {
            actualNameTableX = nameTableX % 32;
            actualNameTableY = nameTableY % 30;
            int whichNameTable = nameTable ^ ((nameTableX >> 5) & 1);

            int nameTableAddress = whichNameTable == 1 ? Ppu.NAME_TABLE_1_BASE_ADDRESS : Ppu.NAME_TABLE_0_BASE_ADDRESS;
            int attributeTableAddress = whichNameTable == 1 ? Ppu.ATTRIBUTE_TABLE_1_BASE_ADDRESS : Ppu.ATTRIBUTE_TABLE_0_BASE_ADDRESS;

            int index = ggvm.getNametableTile(nameTableAddress, actualNameTableX, actualNameTableY);
            int attribute = ggvm.getAttributeForNametableTile(attributeTableAddress, actualNameTableX, actualNameTableY);

            int indexRow = index >> 4;
            int indexColumn = index & 0x0f;
            Sprite sprite = patternTableManager.getSprite(patternTable, indexRow, indexColumn);//patternTableSprites[patternTableOffset * 16 + indexRow][indexColumn];
            sprite.setColor(0, attributes[attribute], 0, 0);
            if (!GGVmRegisterStatusBar.isSprite0HitStatusBarEnabled() || (screenY >= splitYStart && screenY < splitYEnd)) {
                sprite.setPosition(screenX - fineScrollX, 232 - screenY + fineScrollY);
                sprite.draw(spriteBatch);
            }
            screenX += 8;
            nameTableX++;
            nameTableColumnCount--;
        }
        screenY += 8;
        nameTableY++;
        nameTableRowCount--;
    }
}
 
Example 22
Project: Polymorph   File: Splash.java   Source Code and License 5 votes vote down vote up
public Splash(final Polymorph polymorph) {
    this.polymorph = polymorph;
    batch = new SpriteBatch();

    initAssets();
    Timer.schedule(new Task() {
        @Override
        public void run() {
            polymorph.setScreen(new MainMenu(polymorph));
        }

    }, 3); //change screen after 3 seconds
}
 
Example 23
Project: INFSEN01-2   File: Program.java   Source Code and License 5 votes vote down vote up
@Override
public void create() {
    this.batch = new SpriteBatch();
    this.backgroundImage = new Texture("coffee.jpg");

    this.guiManager = new GUIManager(() -> {
        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);
}
 
Example 24
Project: school-game   File: Splashscreen.java   Source Code and License 5 votes vote down vote up
/**
 * Initialisierung
 *
 * @param game zeigt auf das SchoolGame, dass das Spiel verwaltet
 */
@Override
public void create(SchoolGame game) {
    this.game = game;
    batch = new SpriteBatch();

    Texture splashImg = new Texture(Gdx.files.internal("data/misc/splashscreen.png"));
    screenSprite = new Sprite(splashImg);
    screenSprite.setPosition(-screenSprite.getWidth() / 2, -screenSprite.getHeight() / 2);
    screenSprite.setAlpha(0);

    timer = SHOW_TIME + FADE_TIME * 2;
}
 
Example 25
Project: savethebunny   File: LevelItem.java   Source Code and License 5 votes vote down vote up
@Override
public void render(SpriteBatch batch) {
    if (this.visible) {
        super.render(batch);
        if (levelNum > -1) {
            Cache.font.draw(batch, text, textX, textY);
        }
    }
}
 
Example 26
Project: gdx-cclibs   File: ExampleRunner.java   Source Code and License 5 votes vote down vote up
@Override
public void create() {
    spriteBatch = new SpriteBatch();
    stage = new Stage(new ScreenViewport());
    skin = new Skin(Gdx.files.internal("uiskin.json"));
    Table table = new Table(skin);
    table.setFillParent(true);
    selectBox = new SelectBox<Class<? extends Example>>(skin){
        protected String toString (Class<? extends Example> obj) {
            return obj.getSimpleName();
        }
    };
    selectBox.setItems(examples);
    table.add(selectBox).fillX().space(20).row();
    stage.addActor(table);
    TextButton startButton = new TextButton("Start example", skin);
    startButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            runSelectedExample();
        }
    });
    table.add(startButton).fillX();

    if (arg != null && arg.length > 0) {
        Class<? extends Example> specifiedExample = getExample(arg[0]);
        if (specifiedExample != null){
            startExample(specifiedExample);
            return;
        }
    }

    setScreen(menuScreen);
}
 
Example 27
Project: SpaceChaos   File: DrawHPBarComponent.java   Source Code and License 5 votes vote down vote up
@Override
public void drawUILayer(GameTime time, CameraWrapper camera, SpriteBatch batch) {
    // get current HP in percent
    float percent = this.hpComponent.getPercent();

    // calculate x and y position
    float x = this.positionComponent.getX() + offsetX;
    float y = this.positionComponent.getY() + this.positionComponent.getHeight() + offsetY;

    // draw background
    SpriteBatcherUtils.fillRectangle(batch, x, y, barWidth, barHeight, backgroundColor);

    // draw foreground
    SpriteBatcherUtils.fillRectangle(batch, x, y, barWidth * percent, barHeight, foregroundColor);
}
 
Example 28
Project: savethebunny   File: PhaseItem.java   Source Code and License 5 votes vote down vote up
@Override
public void render(SpriteBatch batch) {
    super.render(batch);
    if (this.visible) {
        Cache.font.draw(batch, title, titleX, titleY);
        Cache.font.draw(batch, subtitle, subtitleX, subtitleY);
    }
}
 
Example 29
Project: Polymorph   File: PolyGame.java   Source Code and License 5 votes vote down vote up
public void render(SpriteBatch batch) {
    batch.disableBlending();
    //draw opaques
    for (Map map : maps) {
        map.render(batch);
    }

    batch.enableBlending();
    //draw transparents
    player.render(batch);
    for (Slot slot : slots) {
        slot.render(batch);
    }
}
 
Example 30
Project: miniventure   File: BounceEntity.java   Source Code and License 5 votes vote down vote up
@Override
public void render(SpriteBatch batch, float delta) {
	blinker.update(delta);
	
	if(time < lifetime * BLINK_THRESHOLD || blinker.shouldRender())
		super.render(batch, delta);
}
 
Example 31
Project: libgdx-learnlib   File: Clouds.java   Source Code and License 5 votes vote down vote up
@Override
public void render(SpriteBatch batch) {
    TextureRegion reg = regCloud;
    batch.draw(reg.getTexture(), position.x + origin.x, position.y
                    + origin.y, origin.x, origin.y, dimension.x, dimension.y,
            scale.x, scale.y, rotation, reg.getRegionX(),
            reg.getRegionY(), reg.getRegionWidth(),
            reg.getRegionHeight(), false, false);
}
 
Example 32
Project: guitar-finger-trainer   File: GftGame.java   Source Code and License 5 votes vote down vote up
@Override
public void create () {
	spriteBatch = new SpriteBatch();

	glyphLayout = new GlyphLayout();

	SettingsUtil.load();
	AssetsUtil.load();

	setScreen(new MainScreen(this));
}
 
Example 33
Project: TreasureHunting   File: GameRenderer.java   Source Code and License 5 votes vote down vote up
public GameRenderer(GameWorld world) {
    this.world = world;

    this.cam = new OrthographicCamera();
    cam.setToOrtho(true, com.home.knowhunt.screens.GameScreen.GAME_WIDTH, 204);

    batcher = new SpriteBatch();
    batcher.setProjectionMatrix(cam.combined);
    shapeRenderer = new ShapeRenderer();
    shapeRenderer.setProjectionMatrix(cam.combined);

    initGameObjects();
}
 
Example 34
Project: libgdx-learnlib   File: WaterOverlay.java   Source Code and License 5 votes vote down vote up
@Override
public void render(SpriteBatch batch) {
    TextureRegion reg = null;
    reg = regWaterOverlay;
    batch.draw(reg.getTexture(), position.x + origin.x, position.y
                    + origin.y, origin.x, origin.y, dimension.x, dimension.y,
            scale.x, scale.y, rotation, reg.getRegionX(), reg.getRegionY(),
            reg.getRegionWidth(), reg.getRegionHeight(), false, false);
}
 
Example 35
Project: libgdx-learnlib   File: Feather.java   Source Code and License 5 votes vote down vote up
@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);

}
 
Example 36
Project: Tower-Defense-Galaxy   File: TDScreen.java   Source Code and License 5 votes vote down vote up
@Override
public void show () {
    //orthographicCamera = new OrthographicCamera(3840, 2160);
    matrix4 = new Matrix4();
    spriteBatch = new SpriteBatch();
    viewport = new FitViewport(2560, 1440, new OrthographicCamera());
    viewport.apply();
    stage = new Stage(viewport);
    camera = createCamera();
    multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(stage);
    Gdx.input.setInputProcessor(multiplexer);
    if(TDGalaxy.preferences.isDebug())
        stage.setDebugAll(true);
}
 
Example 37
Project: miniventure   File: Tile.java   Source Code and License 5 votes vote down vote up
@Override
public void render(SpriteBatch batch, float delta) {
	
	// draw the ground sprite and overlaps
	renderTileType(groundType, batch);
	
	// draw the surface sprite and overlaps
	if(surfaceType != null)
		renderTileType(surfaceType, batch);
}
 
Example 38
Project: bobbybird   File: GameState.java   Source Code and License 5 votes vote down vote up
@Override
public void draw(SpriteBatch spriteBatch, float delta) {
    Gdx.gl.glClearColor(0, 113/255.0f, 188/255.0f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    
    camera.update();
    spriteBatch.setProjectionMatrix(camera.combined);
    spriteBatch.begin();
    manager.draw(spriteBatch, delta);
    spriteBatch.end();
    
    stage.draw();
}
 
Example 39
Project: FlappyChapa   File: MenuState.java   Source Code and License 5 votes vote down vote up
@Override
public void render(SpriteBatch spriteBatch) {
    spriteBatch.setProjectionMatrix(camera.combined);
    spriteBatch.begin();
    spriteBatch.draw(backGround, 0, 0);
    spriteBatch.draw(playButton, camera.position.x - playButton.getWidth() / 2, camera.position.y);
    spriteBatch.end();
}
 
Example 40
Project: SpaceChaos   File: ActionBar.java   Source Code and License 5 votes vote down vote up
@Override
public void drawLayer0(GameTime time, SpriteBatch batch) {
    // draw background
    batch.draw(this.bgTexture, getX(), getX());

    // draw items
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            // update item
            if (items[i][j] != null) {
                items[i][j].drawLayer0(time, batch);
            }
        }
    }
}
 
Example 41
Project: Klooni1010   File: TimeScorer.java   Source Code and License 5 votes vote down vote up
@Override
public void draw(SpriteBatch batch) {
    super.draw(batch);

    int timeLeft = pausedTimeLeft < 0 ? getTimeLeft() : pausedTimeLeft;
    timeLeftLabel.setText(Integer.toString(timeLeft));
    timeLeftLabel.setColor(Klooni.theme.currentScore);
    timeLeftLabel.draw(batch, 1f);
}
 
Example 42
Project: SpaceChaos   File: SpriteBatcherUtils.java   Source Code and License 5 votes vote down vote up
public static void fillRectangle(SpriteBatch batch, float x, float y, float width, float height, Color color) {
    initTextureIfAbsent();

    // backup color
    Color backupColor = batch.getColor();

    // set rectangle color
    batch.setColor(color);

    batch.draw(textureRegion, x, y, width, height);

    // reset color
    batch.setColor(backupColor);
}
 
Example 43
Project: CursedEcho   File: AssetHandler.java   Source Code and License 5 votes vote down vote up
public void renderProgressBar(SpriteBatch batch) {
	batch.begin();
	batch.draw(backgroundImg, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	batch.draw(progressBarBaseImg, pbPos.x, pbPos.y);
	batch.draw(progressBarImg, pbPos.x,pbPos.y,progressBarImg.getWidth()*getProgress(),progressBarImg.getHeight());
	font.draw(batch, "[BLACK]Loading...", pbPos.x+5, pbPos.y+progressBarImg.getHeight() - 10);
	batch.end();
}
 
Example 44
Project: INFSEN01-2   File: Program.java   Source Code and License 5 votes vote down vote up
@Override
public void create() {
    this.batch = new SpriteBatch();
    this.backgroundImage = new Texture("coffee.jpg");

    this.guiManager = new GUIManager(() -> {
        Gdx.app.exit();
    });
    this.drawVisitor = new DefaultDrawVisitor(this.batch);
    this.updateVisitor = new DefaultUpdateVisitor();
}
 
Example 45
Project: libGdx-xiyou   File: RankingDialog.java   Source Code and License 5 votes vote down vote up
public void render(SpriteBatch batch) {
	if (MyGdxGame.rankings == null || MyGdxGame.rankings.size() == 0) {
		return;
	}
	batch.begin();
	for (int i = 0; i < MyGdxGame.rankings.size(); i++) {
		mFont.draw(batch, (i + 1) + ".", x * MyGdxGame.WEIGHT_RATE - 175, y * MyGdxGame.HEIGHT_RATE + 50 - i * 80);
		mFont.draw(batch, MyGdxGame.rankings.get(i).name, x * MyGdxGame.WEIGHT_RATE - 95, y * MyGdxGame.HEIGHT_RATE + 50 - i * 80);
		mFont.draw(batch, MyGdxGame.rankings.get(i).score + "", x * MyGdxGame.WEIGHT_RATE - 95 + 140, y * MyGdxGame.HEIGHT_RATE + 50 - i * 80);
		mFont.draw(batch, MyGdxGame.rankings.get(i).time + "秒", x * MyGdxGame.WEIGHT_RATE - 95 + 235, y * MyGdxGame.HEIGHT_RATE + 50 - i * 80);
	}
	batch.end();
}
 
Example 46
Project: SpaceChaos   File: ScreenBasedGame.java   Source Code and License 5 votes vote down vote up
@Override
protected final void draw(GameTime time, SpriteBatch batch) {
    // draw all screens
    for (IScreen screen : this.screenManager.listActiveScreens()) {
        // draw screen
        screen.draw(time, batch);
    }
}
 
Example 47
Project: miniventure   File: MyUtils.java   Source Code and License 5 votes vote down vote up
public static void writeOutlinedText(BitmapFont font, SpriteBatch batch, String text, float x, float y, Color center, Color outline) {
	font.setColor(outline);
	font.draw(batch, text, x-1, y-1);
	font.draw(batch, text, x-1, y+1);
	font.draw(batch, text, x+1, y-1);
	font.draw(batch, text, x+1, y+1);
	font.setColor(center);
	font.draw(batch, text, x, y);
}
 
Example 48
Project: MMORPG_Prototype   File: ChoosingCharacterState.java   Source Code and License 4 votes vote down vote up
@Override
public void render(SpriteBatch batch)
{
	stage.draw();
}
 
Example 49
Project: cocos2d-java   File: GLProgramCache.java   Source Code and License 4 votes vote down vote up
final void init() {
	if(spriteBatchDefault == null) {
		spriteBatchDefault = SpriteBatch.createDefaultShader();
	}
}
 
Example 50
Project: SpaceChaos   File: TextButton.java   Source Code and License 4 votes vote down vote up
@Override
public void drawLayer2(GameTime time, SpriteBatch batch) {
    //
}
 
Example 51
Project: JGame   File: Crafting.java   Source Code and License 4 votes vote down vote up
public void render(SpriteBatch batch) {
	if (active) {
		shapes.begin(ShapeRenderer.ShapeType.Filled);
		shapes.setColor(Color.WHITE);
		shapes.rect(this.x - (this.wid / 2), this.y - (this.hei / 2), this.wid, this.hei);
		shapes.end();

		if (Gdx.input.getX() < this.x + (this.wid / 2) + widthExit
				&& Gdx.input.getX() > this.x + (this.wid / 2) - widthExit) {

			if ((Math.round(this.y * 2) - Gdx.input.getY()) < this.y + (this.hei / 2) - 5
					&& (Math.round(this.y * 2) - Gdx.input.getY()) > this.y + (this.hei / 2) - 5 - heightExit) {

				batch.begin();
				fontHandler.font32.setColor(Color.RED);
				fontHandler.font32.draw(batch, "Save", this.x - (widthSave / 2), this.y - (heightSave / 2) + 170);
				fontHandler.font32.setColor(Color.PINK);
				fontHandler.font32.draw(batch, "X", this.x + (this.wid / 2) - widthExit,
						this.y + (this.hei / 2) - 5);
				batch.end();

				if (Gdx.input.justTouched()) {
					active = false;
				}
			}

			else {
				batch.begin();
				fontHandler.font32.setColor(Color.RED);
				fontHandler.font32.draw(batch, "Save", this.x - (widthSave / 2), this.y - (heightSave / 2) + 170);
				fontHandler.font32.draw(batch, "X", this.x + (this.wid / 2) - widthExit,
						this.y + (this.hei / 2) - 5);
				batch.end();
			}
		}

		else {
			batch.begin();
			fontHandler.font32.setColor(Color.RED);
			fontHandler.font32.draw(batch, "Save", this.x - (widthSave / 2), this.y - (heightSave / 2) + 170);
			fontHandler.font32.draw(batch, "X", this.x + (this.wid / 2) - widthExit, this.y + (this.hei / 2) - 5);
			batch.end();
		}

		if (Gdx.input.getX() < (this.x) + widthSave / 2 && Gdx.input.getX() > this.x - (widthSave / 2)) {
			if ((Math.round(this.y * 2) - Gdx.input.getY()) < this.y - (heightSave / 2) + 170
					&& (Math.round(this.y * 2) - Gdx.input.getY()) > this.y - (heightSave * 2) + 175) {

				batch.begin();
				fontHandler.font32.setColor(Color.PINK);
				fontHandler.font32.draw(batch, "Save", this.x - (widthSave / 2), this.y - (heightSave / 2) + 170);
				fontHandler.font32.setColor(Color.RED);
				fontHandler.font32.draw(batch, "X", this.x + (this.wid / 2) - widthExit,
						this.y + (this.hei / 2) - 5);
				batch.end();

				shapes.begin(ShapeRenderer.ShapeType.Line);
				shapes.setColor(Color.BLACK);
				shapes.rect((this.x - widthSave / 2) - (widthSave / 20), this.y - (heightSave * 2) + 175,
						widthSave + (widthSave / 20), heightSave + 10);
				shapes.end();

				if (Gdx.input.justTouched()) {
					this.saveMap = true;

				}
			}

			else {
				batch.begin();
				fontHandler.font32.setColor(Color.RED);
				fontHandler.font32.draw(batch, "Save", this.x - (widthSave / 2), this.y - (heightSave / 2) + 170);
				fontHandler.font32.draw(batch, "X", this.x + (this.wid / 2) - widthExit,
						this.y + (this.hei / 2) - 5);
				batch.end();
			}
		}

	}

}
 
Example 52
Project: summer17-android   File: Level2.java   Source Code and License 4 votes vote down vote up
public Level2(GameStateManager gsm, int c) {
    super(gsm);
    a = c;
    cam.setToOrtho(false, GameTutorial.WIDTH / 2, GameTutorial.HEIGHT / 2);
    // INITIALIZING ANIMALS
    if (a == 1){
        sheep = new Sheep(150, 60);
    }
    if (a == 2){
        cow = new Cow(150, 60);
    }
    if (a == 3){
        pig = new Pig(150, 60);
    }
    if (a == 4){
        bunny = new Bunny(150, 60);
    }
    if (a == 5){
        chick = new Chick(150, 60);
    }
    farmer = new Farmer(-50, 60);
    ground = new Texture("CornFieldGround.png");
    background = new Texture("CornField.png");
    groundPos1 = new Vector2(cam.position.x - cam.viewportWidth / 2 - ground.getWidth(), GROUND_Y_OFFSET);
    groundPos2 = new Vector2(ground.getWidth() + groundPos1.x, GROUND_Y_OFFSET);
    bgPos1 = new Vector2(cam.position.x - cam.viewportWidth / 2 - bg_width, 0);
    bgPos2 = new Vector2(background.getWidth() + bgPos1.x, 0);
    bgPos3 = new Vector2(background.getWidth() + bgPos2.x, 0);

    //Obstacles
    mushroomTexture = new Texture("Mushroom.png");
    mushroom = new Obstacle(mushroomTexture, 700, 70, 2, 0.3f);
    mushroomIsTouched = false;
    mud = new Mud(260, 37);
    appleTexture = new Texture("Apple.png");
    apple = new Obstacle(appleTexture, 1000, 150, 2, 0.5f);
    appleIsTouched = false;
    barrel = new Barrel(300, 60);
    startTime = System.currentTimeMillis();
    batch = new SpriteBatch();
    font = new BitmapFont();
}
 
Example 53
Project: ggvm   File: SingleScreenMirroringRenderManager.java   Source Code and License 4 votes vote down vote up
@Override
protected void drawNametable(GGVm ggvm, SpriteBatch spriteBatch) {
    drawNametable(ggvm, spriteBatch, ggvm.getScrollX(), ggvm.getScrollY(), 0f, 240f);
}
 
Example 54
Project: summer17-android   File: GameStateManager.java   Source Code and License 4 votes vote down vote up
public void render(SpriteBatch sb){
    states.peek().render(sb);
}
 
Example 55
Project: MMORPG_Prototype   File: AuthenticationState.java   Source Code and License 4 votes vote down vote up
@Override
public void render(SpriteBatch batch)
{
	stage.draw();
}
 
Example 56
Project: bobbybird   File: MenuState.java   Source Code and License 4 votes vote down vote up
@Override
public void draw(SpriteBatch spriteBatch, float delta) {
    stage.draw();
}
 
Example 57
Project: INFSEN01-2   File: GDXDrawingAdapter.java   Source Code and License 4 votes vote down vote up
public GDXDrawingAdapter(SpriteBatch spriteBatch) {
    this.batch = spriteBatch;
    this.textureWhite = new Texture("white_pixel.jpg");
    this.font = new BitmapFont();
}
 
Example 58
Project: ggvm   File: TouchInputProcessor.java   Source Code and License 4 votes vote down vote up
private void drawCenteredTexture(SpriteBatch spriteBatch, Texture texture, float x, float y, float w, float h) {
    spriteBatch.draw(texture, (x - w/2), (y - h/2), w, h);
}
 
Example 59
Project: bad-wolf   File: Tile.java   Source Code and License 4 votes vote down vote up
public void render(SpriteBatch batch) {
    batch.draw(images[getRegionX()][getRegionY()], x * SIZE, y * SIZE, SIZE, SIZE);
}
 
Example 60
Project: INFSEN01-2   File: DefaultDrawVisitor.java   Source Code and License 4 votes vote down vote up
public DefaultDrawVisitor(SpriteBatch spriteBatch) {
    this.batch = spriteBatch;
    this.textureWhite = new Texture("white_pixel.jpg");
    this.font = new BitmapFont();
}