@Override public void render(float delta) { Gdx.gl.glClearColor(0.39f, 0.58f, 0.92f, 1.0f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Update deltaTime & animationTime deltaTime = Gdx.graphics.getDeltaTime(); animationTime += Gdx.graphics.getDeltaTime(); // Store Spritesheet to sprite sprite = new Sprite(animation.getKeyFrame(animationTime, true)); sprite.setPosition(xPosition, 0); sprite.setScale(1.8f); // Set camera to batch and undate camera batch.setProjectionMatrix(camera.combined); camera.update(); tiledMapRenderer.setView(camera); tiledMapRenderer.render(background); tiledMapRenderer.render(foreground); // Display on Screen batch.begin(); sprite.draw(batch); batch.end(); // update xPosition xPosition = xPosition + (speed * deltaTime); HUDBatch.begin(); font1.draw(HUDBatch, "SCORE:100", 100, 450); HUDBatch.end(); }
/** * An Entity with a square physics Body. * * @param sprite the sprite for this * @param friction the coefficient of friction for this * @param restitution the restitution for this * @param world the physics world that is in * @param mass the mass of this in grams * @param x the x ordinate of this in pixels * @param y the y ordinate of this in pixels * @param isStatic if this is capable of having motion * @param canRotate if this is capable of rotating */ public SpriteEntity( float scale, Sprite sprite, float friction, float restitution, World world, float mass, float x, float y, boolean isStatic, boolean canRotate) { this( scale, sprite, friction, restitution, world, mass, x, y, sprite.getWidth(), sprite.getHeight(), isStatic, canRotate); }
/** Draw 描画 */ public void Draw() { hp.draw(GameMain.spriteBatch); scrollRight.draw(GameMain.spriteBatch); scroll.draw(GameMain.spriteBatch); chakra.draw(GameMain.spriteBatch); hyoutan.draw(GameMain.spriteBatch); }
/** * Returns the position of the Entity. * * @return the position, in Vector2 form */ public Vector2 getOriginPosition() { if (sprite != null) { return new Vector2(sprite.getX() + sprite.getOriginX(), sprite.getY() + sprite.getOriginY()); } else { return new Vector2((edges[0].x + edges[1].x) / 2, (edges[0].y + edges[1].y) / 2); } }
public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // tell the camera to update its matrices. camera.update( car.body.getPosition().x * PIXELS_PER_METER, car.body.getPosition().y * PIXELS_PER_METER); spriteBatch.setProjectionMatrix(camera.getCombined()); if (Gdx.input.isKeyPressed(Input.Keys.UP) || Gdx.input.isTouched()) { car.setAccelerate(Car.ACC_ACCELERATE); } else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) { car.setAccelerate(Car.ACC_BRAKE); } else { car.setAccelerate(Car.ACC_NONE); } if (Gdx.input.isKeyPressed(Input.Keys.LEFT) || Gdx.input.getAccelerometerY() < -2.5) { car.setSteer(Car.STEER_HARD_LEFT); } else if (Gdx.input.getAccelerometerY() < -1) { car.setSteer(Car.STEER_LEFT); } else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) || Gdx.input.getAccelerometerY() > 2.5) { car.setSteer(Car.STEER_HARD_RIGHT); } else if (Gdx.input.getAccelerometerY() > 1) { car.setSteer(Car.STEER_RIGHT); } else { car.setSteer(Car.STEER_NONE); } car.update(Gdx.app.getGraphics().getDeltaTime()); /** * Have box2d update the positions and velocities (and etc) of all tracked objects. The second * and third argument specify the number of iterations of velocity and position tests to perform * -- higher is more accurate but is also slower. */ world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3); world.clearForces(); // draw the sprites spriteBatch.begin(); playerSprite.setPosition( PIXELS_PER_METER * car.body.getPosition().x - playerTexture.getRegionWidth() / 2, PIXELS_PER_METER * car.body.getPosition().y - playerTexture.getRegionHeight() / 2); playerSprite.setRotation((MathUtils.radiansToDegrees * car.body.getAngle())); playerSprite.setFlip(false, true); playerSprite.setScale(0.3f); playerSprite.draw(spriteBatch); spriteBatch.end(); /** Draw this last, so we can see the collision boundaries on top of the sprites and map. */ debugRenderer.render( world, camera.getCombined().scale(PIXELS_PER_METER, PIXELS_PER_METER, PIXELS_PER_METER)); }
@Override public void draw(float delta, SpriteBatch spriteBatch) { for (Sprite cell : cells) { cell.draw(spriteBatch); } super.draw(delta, spriteBatch); }
@Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { unprojectVec.set(screenX, screenY, 0); cameraManager.getCamera().unproject(unprojectVec); float x = unprojectVec.x; float y = unprojectVec.y; if (state == GameState.RUNNING && pauseSprite.getBoundingRectangle().contains(x, y)) { soundController.playClick(); state = GameState.PAUSED; resumeSprite.setAlpha(1); } if (state == GameState.PAUSED && resumeSprite.getBoundingRectangle().contains(x, y)) { soundController.playClick(); state = GameState.RUNNING; resumeSprite.setAlpha(0); } if (state == GameState.GET_READY) { soundController.playClick(); state = GameState.RUNNING; readySprite.setAlpha(0); } return false; }
/** @param path */ public LoadTexture(String path) { array_Texs.add(new Texture(path)); array_Texs.get(BACKGROUND).setFilter(TextureFilter.Linear, TextureFilter.Linear); array_Texs.add(new Texture(Gdx.files.internal("data/arrow-down.png"))); array_Texs.add(new Texture(Gdx.files.internal("data/arrow-up.png"))); array_Texs.add(new Texture(Gdx.files.internal("data/menu.png"))); for (int i = 0; i < array_Texs.size(); i++) { array_TexRegions.add( new TextureRegion( array_Texs.get(i), 0, 0, array_Texs.get(i).getWidth(), array_Texs.get(i).getHeight())); array_Sprites.add(new Sprite(array_TexRegions.get(i))); } // 背景画像設定 Sprite sprite = array_Sprites.get(BACKGROUND); sprite.setSize(sprite.getRegionWidth(), sprite.getRegionHeight()); sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); sprite.setPosition(-sprite.getWidth() / 2, -sprite.getHeight() / 2); array_Sprites.set(BACKGROUND, sprite); }
@Override protected void process(Entity e) { if (cullableMapper.get(e).culled) return; Sprite sprite = renderableMapper.get(e).sprite; sprite.draw(batch); }
public void render() { // the artistic drawing function that draws everything out (such talent) // make the frame ticker thing that actually makes pretty pictures move // in this case you are updating the world you just made // apparently you aren't suppose to update this in the render loop but w/e // also have no idea what 6 & 2 mean so again w/e (sensai plssss) world.step(Gdx.graphics.getDeltaTime(), 6, 2); // move the sprite with the body! sprite.setPosition(body.getPosition().x, body.getPosition().y); // just a limit for when it falls off the screen since there is no ground LOL System.out.println(body.getPosition().y); if (body.getPosition().y < (10)) { body.setAwake(false); } else { body.setAwake(true); } // Again not box2dStuff just cool things I added HandleTouch(); // the Background color // This doesn't look like it does anything? Gdx.gl.glClearColor(1, 1, 1, 1); // clears the background after each fram update // Same with this? Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // this is where the sprite img is rendered and updated etc. batch.begin(); batch.draw(sprite, sprite.getX(), sprite.getY()); batch.end(); }
@Override public void create() { final float w = Gdx.graphics.getWidth(); final float h = Gdx.graphics.getHeight(); // create the camera and the SpriteBatch camera = new OrthographicCamera(); camera.setToOrtho(false, w, h); viewport = new FitViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, camera); batch = new SpriteBatch(); img = new Texture(Gdx.files.internal("playerSprite_1.png")); // create a new sprite based on our image sprite = new Sprite(img); sprite.setPosition(ScreenWidth / 2 - playerWidth, ScreenHeight / 2 - playerHeight); tiledMap = new TmxMapLoader().load("ritualsite.tmx"); tiledMapRenderer = new OrthogonalTiledMapRendererWithSprites(tiledMap); tiledMapRenderer.addSprite(sprite); Gdx.input.setInputProcessor(this); targetPos = new Vector2(sprite.getX(), sprite.getY()); // create a sprite batch batch = new SpriteBatch(); direction = new Vector2(); playerDirection = new Vector2(); getCollidingRects(); }
@Override public void render(SpriteBatch sb) { delta = (TimeUtils.millis() - startTime + 700) / 1000; tweenManager.update(delta); bgManager.render(sb); sb.setProjectionMatrix(camera.combined); sb.begin(); backButton.render(sb); randomCardButton.draw(sb); rareCardButton.draw(sb); Fonts.MFont.draw( sb, "Cost: " + randomCardCost, randomCardButton.getX(), randomCardButton.getY() - 40); Fonts.MFont.draw( sb, "Cost: " + rareCardCost, rareCardButton.getX(), rareCardButton.getY() - 40); Fonts.MFont.draw( sb, currGold, MainGame.WIDTH - Fonts.MFont.getBounds(currGold).width - 40, MainGame.HEIGHT - 50); if (showingCard) { sb.draw(alpha, 0, 0, MainGame.WIDTH, MainGame.HEIGHT); purchasedCard.render( new Vector2( MainGame.WIDTH / 2 - (Card.WIDTH / 2 * cardAnimSprite.getScaleX()), MainGame.HEIGHT / 2 - (Card.HEIGHT / 2 * cardAnimSprite.getScaleX())), cardAnimSprite.getScaleX(), sb); unlockedText.draw(sb); } sb.end(); }
@Override public void create() { GeneralStorage.load(); MenuStorage.load(); SplashStorage.load(); MenuStorage.load(); PauseStorage.load(); RunningStorage.load(); GameOverStorage.load(); GeneralStorage.estado = GeneralStorage.state.splash; MenuStorage.HelpTouched = false; // Init the particle effect particle1 = new ParticleEffect(); particleLeft = new ParticleEffect(); particleRight = new ParticleEffect(); // load the particle, first parameter is path and name file when is the particle, // second one the fold when is the particle image. particle1.load(Gdx.files.internal("efectos/vuelo2"), Gdx.files.internal("efectos")); particleLeft.load(Gdx.files.internal("efectos/efLateral3"), Gdx.files.internal("efectos")); particleRight.load(Gdx.files.internal("efectos/efLateral3"), Gdx.files.internal("efectos")); // Sprites of button of the menu screen to music, sound and button help spHelp = new Sprite(GeneralStorage.imgBTHelp); spHelp.setSize(GeneralStorage.w / 10, GeneralStorage.w / 10); spHelp.setPosition( GeneralStorage.w - GeneralStorage.w / 4 - spHelp.getWidth() / 2, GeneralStorage.h / 4); // storage the background color colorFondo = MenuStorage.spBackGroundGame.getColor(); // Time to splash screen. timer = 100; }
public void draw(SpriteBatch sb) { if (mCogs_ReallyBig.size() > 0) { mCogs_ReallyBig.get(0).setCenterX(121); mCogs_ReallyBig.get(0).setCenterY(156); mCogs_ReallyBig.get(0).draw(sb); } if (mCogs_Big.size() > 0) { mCogs_Big.get(0).setCenterX(326); mCogs_Big.get(0).setCenterY(112); mCogs_Big.get(0).draw(sb); } if (mCogs_Medium.size() > 0) { mCogs_Medium.get(0).setCenterX(498); mCogs_Medium.get(0).setCenterY(95); mCogs_Medium.get(0).draw(sb); } if (mCogs_Small.size() > 0) { mCogs_Small.get(0).setCenterX(633); mCogs_Small.get(0).setCenterY(83); mCogs_Small.get(0).draw(sb); } if (mCogs_Tiny.size() > 0) { mCogs_Tiny.get(0).setCenterX(732); mCogs_Tiny.get(0).setCenterY(69); mCogs_Tiny.get(0).draw(sb); } mSprite.setPosition(0, 0); mSprite.draw(sb); }
public void setUp() { BodyDef bodyDef = new BodyDef(); bodyDef.position.set(x + width / 2, y + height / 2); bodyDef.type = BodyDef.BodyType.KinematicBody; PolygonShape shape = new PolygonShape(); shape.setAsBox(width / 2, height / 2); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; body = world.createBody(bodyDef); body.createFixture(fixtureDef); body.setUserData(Constants.robotNinjaID); body.setLinearVelocity(Constants.standardVelocity); sprite = new Sprite(texture); sprite.setSize(width, height); sprite.setOrigin(width / 2, height / 2); sprite.flip(false, flipy); sprite.setPosition(x, y); dead = false; }
@Override public int getValues(Sprite sprite, int i, float[] floats) { switch (Mode.values()[i]) { case SCALE: floats[0] = sprite.getScaleX(); return 1; case ALPHA: floats[0] = sprite.getColor().a; return 1; case POSITION: floats[0] = sprite.getX(); floats[1] = sprite.getY(); return 2; case ROTATION: floats[0] = sprite.getRotation(); return 1; default: assert false; return -1; } }
public static void wyswietlBitmape(Sprite sprite, int x, int y) { PrzechowalniaAssets.spriteBatch.begin(); sprite.setPosition(x, y); sprite.draw(PrzechowalniaAssets.spriteBatch); PrzechowalniaAssets.spriteBatch.end(); }
public void draw(Batch batch, float x, float y, float width, float height) { sprite.setBounds(x, y, width, height); Color color = sprite.getColor(); sprite.setColor(Color.tmp.set(color).mul(batch.getColor())); sprite.draw(batch); sprite.setColor(color); }
@Override public boolean touchUp(int x, int y, int pointer, int button) { System.out.println("powered: " + powered.getX() + " " + powered.getY()); System.out.println("gdx: " + gdx.getX() + " " + gdx.getY()); System.out.println(); return true; }
@Override public void render() { Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); lote.setProjectionMatrix(camara.combined); stateTime += Gdx.graphics.getDeltaTime(); Sprite ciano = animadoCiano.getKeyFrame(stateTime, true); // ciano.setPosition(-ciano.getWidth() / 2, // -ciano.getHeight() / 2); // ciano.setRotation(stateTime * 10); // inanimadoVerde.setSize(0.5f, 0.5f); // inanimadoVerde.setPosition(-inanimadoVerde.getWidth() / 2, // -inanimadoVerde.getHeight() / 2); lote.setProjectionMatrix(camara.combined); lote.setBlendFunction(GL11.GL_SRC_ALPHA, GL11.GL_ONE); lote.begin(); ciano.draw(lote); // inanimadoCastanho.draw(lote); lote.end(); }
public void draw(SpriteBatch batch) { if (!hidden) { fadedBG.draw(batch); dialogSprite.draw(batch); } }
private void creatingRegisterButton() { Sprite spriteRegisterButton = new Sprite(Assets.registerButton); Assets.spriteDefaultColor(spriteRegisterButton); spriteRegisterButton.setSize( (Constant.CONSTANT_WIDTH_FIELD_AND_BUTTON), (Constant.CONSTANCE_HEIGHT_BUTTONS)); SpriteDrawable registerSpriteDrawable = new SpriteDrawable(spriteRegisterButton); registerButton = new ImageButton(registerSpriteDrawable); }
public void update() { if (body.getUserData() == Constants.robotNinjaID) { body.setLinearVelocity(Constants.standardVelocity.x, 0); } sprite.setPosition( body.getPosition().x - sprite.getWidth() / 2, body.getPosition().y - sprite.getHeight() / 2); }
public void draw(Batch batch) { if (type == enemyNORMAL) { enemySprite.setPosition(enemyRec.x - 2.5f, enemyRec.y - 3); } else { enemySprite.setPosition(enemyRec.x - 5, enemyRec.y - 8); } enemySprite.draw(batch); }
public Sprite loadSprite(String id, String file, float scaleX, float scaleY) { Sprite sprite = new Sprite(new Texture(Gdx.files.internal(file))); sprite.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Nearest); sprite.setScale(scaleX, scaleY); sprite.setOrigin(0, 0); sprites.put(id, sprite); return sprite; }
@Override public void render(Batch batch) { if (!isVisible()) { return; } Sprite s = option.on() ? Assets.optionsMenuOn : Assets.optionsMenuOff; s.setAlpha(alpha_); Utils.drawCenter(batch, s, getX(), getY()); }
public void victory() { victory.setPosition( -victory.getWidth() / 2 + Gdx.graphics.getWidth() / 2, -victory.getHeight() / 2 + 50 * HW4.SCALE + Gdx.graphics.getHeight() / 2); gameEnd.begin(); victory.draw(gameEnd); gameEnd.end(); if (rs.getStage() == null) stage.addActor(rs); }
private void renderTestObjects() { worldController.cameraHelper.applyTo(camera); batch.setProjectionMatrix(camera.combined); batch.begin(); for (Sprite sprite : worldController.testSprites) { sprite.draw(batch); } batch.end(); }
// ============================================================================================== // NOT BOX 2D STUFF JUST COOL THINGS I ADDED TO MAKE THE PROGRAM MORE "FUN" public void HandleTouch() { float fSprite_Width = sprite.getWidth(); float fSprite_Height = sprite.getHeight(); if (Gdx.input.isTouched()) { Vector3 touchPos = new Vector3(); // Using vector 3 as a 2-D vector for touch coordinates touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0); body.setTransform(touchPos.x - (fSprite_Width / 2), (touchPos.y - (fSprite_Height / 2)), 0); } }
public GameMap() { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Sprite cell = new Sprite(TextureManager.instance().loadTexture("cell.png")); cell.setPosition(x * 16, y * 16); cells.add(cell); } } }