@Override public void create() { float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); camera = new OrthographicCamera(1, h / w); batch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("data/libgdx.png")); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); texture_nave = new Texture(Gdx.files.internal("data/nave.png")); sprite_nave = new Sprite(texture_nave, 128, 64); sprite_nave.setPosition(-0.5f, -0.5f); sprite_nave.setSize(0.5f, 0.5f); TextureRegion region = new TextureRegion(texture, 0, 0, 512, 275); sprite = new Sprite(region); sprite2 = new Sprite(region); sprite.setSize(0.9f, 0.9f * sprite.getHeight() / sprite.getWidth()); sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); sprite.setPosition(-sprite.getWidth() / 2, -sprite.getHeight() / 2); sprite.setPosition(0, 0); sprite.setRotation(25); }
/** @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); }
public MainMenuScreen(MissileCommand game) { this.game = game; guiCam = new OrthographicCamera( com.intel.libgdxmissilecommand.common.Assets.screenWidth, com.intel.libgdxmissilecommand.common.Assets.screenHeight); guiCam.position.set( com.intel.libgdxmissilecommand.common.Assets.screenWidth / 2, com.intel.libgdxmissilecommand.common.Assets.screenHeight / 2, 0); startButton = new Sprite(com.intel.libgdxmissilecommand.common.Assets.startButtonTextureRegion); startButton.setPosition( com.intel.libgdxmissilecommand.common.Assets.screenWidth / 2 - startButton.getWidth() / 2, startButton.getHeight() * 2.5f); creditsButton = new Sprite(com.intel.libgdxmissilecommand.common.Assets.creditsButtonTextureRegion); creditsButton.setPosition( com.intel.libgdxmissilecommand.common.Assets.screenWidth / 2 - creditsButton.getWidth() / 2, creditsButton.getHeight()); touchPoint = new Vector3(); }
private void createSprites() { // background backgroundTexture = new Texture(Gdx.files.internal("data/cr/map1bg.png")); backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear); backgroundSprite = new Sprite(backgroundTexture); backgroundSprite.setSize(WIDTH_WORLD, HEIGHT_WORLD); backgroundSprite.setPosition(-WIDTH_WORLD / 2f, 0); // planet planetTexture = new Texture(Gdx.files.internal("data/cr/planet_terrain.png")); planetTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear); planetSprite = new Sprite(planetTexture); planetSprite.setSize( PLANET_WIDTH, PLANET_WIDTH * planetSprite.getHeight() / planetSprite.getWidth()); // planet core planetCoreTexture = new Texture(Gdx.files.internal("data/cr/planet_core.png")); planetCoreTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear); planetCoreSprite = new Sprite(planetCoreTexture); planetCoreSprite.setSize( PLANET_CORE_WIDTH, PLANET_CORE_WIDTH * planetCoreSprite.getHeight() / planetCoreSprite.getWidth()); // balls ballTexture = new Texture(Gdx.files.internal("data/gfx/ball.png")); ballTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear); ballSprites = new Sprite[MAX_BALLS]; for (int i = 0; i < MAX_BALLS; i++) { ballSprites[i] = new Sprite(ballTexture); ballSprites[i].setSize(BALL_RADIUS * 2, BALL_RADIUS * 2); ballSprites[i].setOrigin(BALL_RADIUS, BALL_RADIUS); } }
public Fly(float x, float y, int fly_type, int slot_number) { // set static data of fly(x, y, ect) xCoord = x; yCoord = y; fly_size = fly_type; slotNumber = slot_number; switch (fly_type) { case 1: // small fly texture = new Texture(Gdx.files.internal("data/medium_fly.png")); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); TextureRegion region = new TextureRegion(texture, 0, 0, 212, 143); fly_sprite = new Sprite(region); fly_sprite.setSize(.0745f, .06155f); fly_sprite.setOrigin(fly_sprite.getWidth() / 2, fly_sprite.getHeight() / 2); fly_sprite.setPosition(x, y); break; case 2: // small fly texture = new Texture(Gdx.files.internal("data/medium_fly.png")); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); region = new TextureRegion(texture, 0, 0, 212, 143); fly_sprite = new Sprite(region); fly_sprite.setSize(.0745f, .06155f); fly_sprite.setOrigin(fly_sprite.getWidth() / 2, fly_sprite.getHeight() / 2); fly_sprite.setPosition(x, y); break; case 3: // medium fly texture = new Texture(Gdx.files.internal("data/medium_fly.png")); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); region = new TextureRegion(texture, 0, 0, 212, 143); fly_sprite = new Sprite(region); fly_sprite.setSize(.115f, .097f); fly_sprite.setOrigin(fly_sprite.getWidth() / 2, fly_sprite.getHeight() / 2); fly_sprite.setPosition(x, y); break; case 4: // large fly texture = new Texture(Gdx.files.internal("data/medium_fly.png")); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); region = new TextureRegion(texture, 0, 0, 212, 143); fly_sprite = new Sprite(region); fly_sprite.setSize(.155f, .135f); fly_sprite.setOrigin(fly_sprite.getWidth() / 2, fly_sprite.getHeight() / 2); fly_sprite.setPosition(x, y); break; default: break; } }
private void initialize() { switch (scene) { case 5: enemySprite = new Sprite(assets.animationBigEnemy.getKeyFrame(0.1f)); enemySprite.setSize(enemySprite.getWidth() / 2, enemySprite.getHeight() / 2); speed = 5f; type = enemyBIG; enemyRec = new Rectangle( startPos.x, startPos.y, enemySprite.getWidth() - 10, enemySprite.getHeight()); // Range normalRange = 500; targetRange = 500; // Freeze freezeTime = 1; soundController = 0; break; default: enemySprite = new Sprite(assets.animationNormalEnemyRight.getKeyFrame(0.1f)); enemySprite.setSize(enemySprite.getWidth() / 2, enemySprite.getHeight() / 2); speed = 8f; type = enemyNORMAL; enemyRec = new Rectangle( startPos.x, startPos.y, enemySprite.getWidth() - 5, enemySprite.getHeight()); // Range normalRange = 50; targetRange = 80; freezeTime = 3; break; } stateTime = 0; isTarget = false; isFreeze = false; freezeController = 0; // Horizontal if (pol.getVertices()[0] != pol.getVertices()[2]) { isHorizontal = true; if (pol.getVertices()[2] < 0) { isLeft = true; } } // Vertical else if (pol.getVertices()[1] != pol.getVertices()[3]) { isHorizontal = false; // isUp = true; if (this.pol.getVertices()[3] < 0) { this.pol.getVertices()[3] *= -1; } } }
/** コンストラクタ */ public Interface() { weapon = new ArrayList<Sprite>(); // テクスチャ画像読み込み Texture texture = new Texture(Gdx.files.internal("data/interface.png")); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); // 巻物アニメーション TextureRegion[][] tmp = TextureRegion.split(texture, 128, 128); TextureRegion[] frame = new TextureRegion[3]; int index = 0; for (int i = 0; i < frame.length; i++) frame[index++] = tmp[0][i]; scrollAnimation = new Animation(5.0f, frame); scroll = new Sprite(scrollAnimation.getKeyFrame(0, false)); scroll.setOrigin(scroll.getWidth() * 0.5f, scroll.getHeight() * 0.5f); scroll.setScale(ScrollNinja.scale); nowFrame = scrollAnimation.getKeyFrame(0, false); // HP部分 TextureRegion tmpRegion = new TextureRegion(texture, 0, 128, 512, 128); hp = new Sprite(tmpRegion); hp.setOrigin(hp.getWidth() * 0.5f, hp.getHeight() * 0.5f); hp.setScale(ScrollNinja.scale); // 巻物の右端部分 tmpRegion = new TextureRegion(texture, 384, 0, 128, 128); scrollRight = new Sprite(tmpRegion); scrollRight.setOrigin(scrollRight.getWidth() * 0.5f, scrollRight.getHeight() * 0.5f); scrollRight.setScale(ScrollNinja.scale); // ひょうたん tmpRegion = new TextureRegion(texture, 0, 256, 128, 128); hyoutan = new Sprite(tmpRegion); hyoutan.setOrigin(hyoutan.getWidth() * 0.5f, hyoutan.getHeight() * 0.5f); hyoutan.setScale(ScrollNinja.scale); // チャクラ tmpRegion = new TextureRegion(texture, 128, 256, 128, 128); chakra = new Sprite(tmpRegion); chakra.setOrigin(chakra.getWidth() * 0.5f, chakra.getHeight() * 0.5f); chakra.setScale(ScrollNinja.scale); // 最初の設定; percentHP = 1; countHP = percentHP; percentChakra = 0; countChakra = percentChakra; calculateHP = false; calculateChakra = false; stopHP = true; stopChakra = true; stateTime = 0; transrateX = 0; }
private void renderDoorLight(SpriteBatch batch) { BatchUtils.setBlendFuncAdd(batch); Sprite s = Assets.openingDoorLight; s.setColor(1, 1, 1, 1); s.setScale(1, doorLightScale); Utils.drawCenter(batch, s, -114f, (s.getHeight() / 2 - 28) * doorLightScale); float tint = ((float) Math.sin(stateTime * 2) + 1) / 2 * 0.5f + 0.0f; tint *= doorLightScale; s.setColor(tint, tint, tint, 1); Utils.drawCenter(batch, s, -114f, (s.getHeight() / 2 - 28) * doorLightScale); BatchUtils.setBlendFuncNormal(batch); }
@Override public void show() { sprite = new Sprite(AssetLoader.logo); sprite.setColor(1, 1, 1, 0); float width = Gdx.graphics.getWidth(); float height = Gdx.graphics.getHeight(); float desiredWidth = width * .7f; float scale = desiredWidth / sprite.getWidth(); sprite.setSize(sprite.getWidth() * scale, sprite.getHeight() * scale); sprite.setPosition( (width / 2) - (sprite.getWidth() / 2), (height / 2) - (sprite.getHeight() / 2)); setupTween(); batcher = new SpriteBatch(); }
/** * 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); }
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); }
@Override public void render() { camera.update(); // Step the physics simulation forward at a rate of 60hz world.step(1f / 60f, 6, 2); sprite.setPosition( (body.getPosition().x * PIXELS_TO_METERS) - sprite.getWidth() / 2, (body.getPosition().y * PIXELS_TO_METERS) - sprite.getHeight() / 2); sprite.setRotation((float) Math.toDegrees(body2.getAngle())); sprite2.setPosition( (body2.getPosition().x * PIXELS_TO_METERS) - sprite2.getWidth() / 2, (body2.getPosition().y * PIXELS_TO_METERS) - sprite2.getHeight() / 2); sprite2.setRotation((float) Math.toDegrees(body.getAngle())); Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(camera.combined); batch.begin(); batch.draw( sprite, sprite.getX(), sprite.getY(), sprite.getOriginX(), sprite.getOriginY(), sprite.getWidth(), sprite.getHeight(), sprite.getScaleX(), sprite.getScaleY(), sprite.getRotation()); batch.draw( sprite2, sprite2.getX(), sprite2.getY(), sprite2.getOriginX(), sprite2.getOriginY(), sprite2.getWidth(), sprite2.getHeight(), sprite2.getScaleX(), sprite2.getScaleY(), sprite2.getRotation()); batch.end(); }
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); }
// ============================================================================================== // 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 void initCancelButton() { // Cancel Button cancelButtonHelper = new ButtonHelper("menu/save-score-popup/cancel-button.png", 71, 71, 0, 0, 0, 71, game); cancelButton = cancelButtonHelper.getButton(); cancelButton.setPosition( (dialogSprite.getX() + dialogSprite.getWidth() - (cancelButton.getWidth() / 2) - 15), dialogSprite.getY() + dialogSprite.getHeight() - cancelButton.getHeight() + 15); }
public void update(float dt, OrthographicCamera cam) { stage.act(dt); if (Core.persistentAssets.update() && !assetsLoaded) { GameSave.save(); assetsLoaded = true; layout = new Table(Core.persistentAssets.get("skins/uiskin.json", Skin.class)); layout.setFillParent(true); layout.center().bottom(); pressBtn = new Label( "Press any key to continue", Core.persistentAssets.get("skins/uiskin.json", Skin.class)); layout.add(pressBtn).padBottom(40); layout.debug(); stage.addActor(layout); stage.addListener( new InputListener() { public boolean keyUp(InputEvent event, int keycode) { gsm.setState(GameStateManager.MENU); return false; } public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { return true; } public void touchUp(InputEvent event, float x, float y, int pointer, int button) { gsm.setState(GameStateManager.MENU); } }); } if (Core.persistentAssets.isLoaded("images/main-menu/background.jpg")) { if (!bgLoaded) { bgLoaded = true; bg = new Sprite(Core.persistentAssets.get("images/main-menu/background.jpg", Texture.class)); float[] size = ImageUtils.minimalStretch(bg.getWidth(), bg.getHeight(), Core.WIDTH, Core.HEIGHT); bg.setSize(size[0], size[1]); bg.setPosition(size[2], size[3]); } bgOpacity += bgOpacityModifier * dt; bgOpacity = bgOpacity > 1 ? 1 : bgOpacity; } }
public GameState(TitleState title) { this.title = title; this.title.reset(); prefs = Gdx.app.getPreferences("highscore"); adsController = MainGame.adsController; restartButton = new RestartButton(MainGame.WIDTH / 2 - 78, MainGame.HEIGHT / 2 - 100); menuButton = new MenuButton(MainGame.WIDTH / 2 - 125, MainGame.HEIGHT / 2); unpauseButton = new UnpauseButton(MainGame.WIDTH / 2 - 78, MainGame.HEIGHT / 2 + 100); highScore = prefs.getInteger("highscore", 0); gameOverOverlay = new Sprite(new Texture(Gdx.files.internal("gui/gameoverlay.png"))); gameOverOverlay.setPosition(0, MainGame.HEIGHT / 2 - (gameOverOverlay.getHeight() / 2)); backGroundFade = new Sprite(new Texture(Gdx.files.internal("gui/bgfade.png"))); backGroundFade.setPosition(0, 0); backGroundFade.setSize(MainGame.WIDTH, MainGame.HEIGHT); backGroundFade.setAlpha(0.6f); grid = new Grid(15, 15, 390, 390, prefs); parameter.size = 20; parameter.shadowColor = new Color(0, 0, 0, 1f); parameter.shadowOffsetX = 1; parameter.shadowOffsetY = 1; score = grid.getScore(); scoreFont = generator.generateFont(parameter); highscoreFont = generator.generateFont(parameter); redCounter = new Sprite(new Texture(Gdx.files.internal("gui/score/scorecounter.png"))); redCounter.setSize(144, 26.4f); redCounter.setPosition(18, MainGame.HEIGHT - redCounter.getHeight() - 260); blueCounter = new Sprite(new Texture(Gdx.files.internal("gui/score/highscorecounter.png"))); blueCounter.setSize(144, 26.4f); blueCounter.setPosition( MainGame.WIDTH - blueCounter.getWidth() - 18, MainGame.HEIGHT - blueCounter.getHeight() - 260); scoreFont.setColor(Color.WHITE); scoreFont.setFixedWidthGlyphs("0123456789"); highscoreFont.setFixedWidthGlyphs("0123456789"); grid.setPaused(false); }
@Override public void create() { batch = new SpriteBatch(); img = new Texture("scale.png"); sprite = new Sprite(img); sprite.setPosition( Gdx.graphics.getWidth() / 2 - sprite.getWidth() / 2, Gdx.graphics.getHeight() / 2 - sprite.getHeight() / 2); Gdx.input.setInputProcessor(this); }
public void draw(SpriteBatch batch, float parentAlpha) { stateTime += Gdx.graphics.getDeltaTime(); Sprite toRender = currentAnimation.getKeyFrame(stateTime); // -1 to account for the sword below his feet toRender.setPosition(getX(), getY() - 1); toRender.setOrigin( toRender.getX() + toRender.getWidth(), toRender.getY() + toRender.getHeight()); toRender.setRotation(getRotation()); setSize(toRender.getWidth(), toRender.getHeight()); setOrigin(toRender.getOriginX(), toRender.getOriginY()); toRender.draw(batch); if (TheLoveOfRice.DRAW_DEBUG) { drawDebug(batch); } }
@Override public void draw(SpriteBatch batch, float parentAlpha) { super.draw(batch, parentAlpha); Vector2 worldPos = getPosition(); sprite.setPosition(worldPos.x - (sprite.getWidth() / 2), worldPos.y - sprite.getHeight() / 2); sprite.setRotation(getRotation()); sprite.draw(batch); }
/** * An Entity with a square physics Body. * * @param sprite the sprite for this * @param friction the coefficient of friction 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 */ public SpriteEntity(Sprite sprite, float friction, World world, float mass, float x, float y) { this( 1F, sprite, friction, world, mass, x, y, sprite.getWidth(), sprite.getHeight(), IS_STATIC_DEFAULT); }
/** * An Entity with a square physics Body. * * @param sprite the sprite 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 */ public SpriteEntity(Sprite sprite, World world, float mass, float x, float y, boolean isStatic) { this( 1F, sprite, DEFAULT_FRICTION, world, mass, x, y, sprite.getWidth(), sprite.getHeight(), isStatic); }
/** * An Entity with a square physics Body. * * @param sprite the sprite 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 */ public SpriteEntity(float scale, Sprite sprite, World world, float mass, float x, float y) { this( scale, sprite, DEFAULT_FRICTION, world, mass, x, y, sprite.getWidth(), sprite.getHeight(), IS_STATIC_DEFAULT); }
public void initDialogBG() { dialogBGPath = "menu/save-score-popup/bg.png"; // Dialog Texture dialogTexture = game.assetManager.getTexture(dialogBGPath); dialogSprite = new Sprite(dialogTexture); dialogSprite.setSize(536, 286); dialogSprite.setPosition( (stage.getWidth() / 2) - (dialogSprite.getWidth() / 2), (stage.getHeight() / 2) - (dialogSprite.getHeight() / 2)); }
public void renderLoading(float delta) { Gdx.gl.glClearColor(0, 0, 0, wrapper.getF()); stateTime += delta; Sprite frameSprite = new Sprite(loadingAnim().getKeyFrame(stateTime, true)); loadingBatch.begin(); frameSprite.setColor(wrapper.getF(), wrapper.getF(), wrapper.getF(), wrapper.getF()); // frameSprite.setSize(Gdx.graphics.getHeight(), Gdx.graphics.getHeight()*ratio); frameSprite.setPosition( (Gdx.graphics.getWidth() / 2) - (frameSprite.getWidth() / 2), (Gdx.graphics.getHeight() / 2) - (frameSprite.getHeight() / 2)); frameSprite.draw(loadingBatch, wrapper.getF()); loadingBatch.end(); }
/** * Constructs a new Entity * * @param texture the texture to display with the Entity * @param vel the initial velocity of the Entity */ public Entity(TextureRegion texture, Vector2 vel, float rotation) { sprite = new Sprite(texture); Vector2 size = new Vector2(sprite.getWidth() / 2, sprite.getHeight() / 2); sprite.setOrigin(size.x, size.y); entities.add(this); sprite.rotate(rotation); maxSize = size.len(); velocity = vel; id = objCount++; initVelocity = vel; initRotation = rotation; initPos = new Vector2(0, 0); }
@Override public void create() { // creates everything you need LOL batch = new SpriteBatch(); img = new Texture("Alien.png"); sprite = new Sprite(img); // sets the sprite in the middle of the screen sprite.setPosition( Gdx.graphics.getWidth() / 2 - sprite.getWidth() / 2, Gdx.graphics.getHeight() / 2); // This is were the magic happens, this is the "physics world" created where the gravity is set // to 98 // The 'f' makes 98 a float, the true means that it is active, vector 2d just means it takes x y // coor world = new World(new Vector2(0, -98f), true); // The body is the "object" set in the world, BodyDef makes the world aware of the object // basically so world Senpai notices BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; // using 1 to 1 dimensions, meaning 1 in physics engine is 1px // set the body to the same position as the sprite bodyDef.position.set(sprite.getX(), sprite.getY()); // now create the body in the world! body = world.createBody(bodyDef); // now make the "shape" of the body that you just created shape = new PolygonShape(); // in this example I made a box (you can make circles too and stuff) that surrounds the sprite // aka the hit-box // so make the shape the same dimensions as the sprite image we are using shape.setAsBox(sprite.getWidth() / 2, sprite.getHeight() / 2); // FixtureDef is used to add physical properties to the shape // Ex. density, mass, area etc. fixtureDef = new FixtureDef(); // now assign the FixtureDef to the new shape that we just made fixtureDef.shape = shape; // Adding density using FixtureDef & adding it to the body so again world senpai notices fixtureDef.density = 1f; fixture = body.createFixture(fixtureDef); // the shape can be disposed to reduce clutter that will slow down the game shape.dispose(); }
/** * An Entity with a square physics Body. * * @param sprite the sprite for this * @param friction the coefficient of friction 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 */ public SpriteEntity( Sprite sprite, float friction, World world, float mass, float x, float y, boolean isStatic) { this( 1F, sprite, friction, DEFAULT_RESTITUTION, world, mass, x, y, sprite.getWidth(), sprite.getHeight(), isStatic, CAN_ROTATE_DEFAULT); }
@Override public void render(float delta) { begin1.setColor(color); begin2.setColor(rayColor); mid1.setColor(color); mid2.setColor(rayColor); end1.setColor(color); end2.setColor(rayColor); mid1.setSize(mid1.getWidth(), len); mid2.setSize(mid1.getWidth(), len); begin1.setPosition(positon.x, positon.y); begin2.setPosition(positon.x, positon.y); mid1.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight()); mid2.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight()); end1.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight() + mid1.getHeight()); end2.setPosition(begin1.getX(), begin1.getY() + begin1.getHeight() + mid1.getHeight()); begin1.setOrigin(begin1.getWidth() / 2, 0); begin2.setOrigin(begin1.getWidth() / 2, 0); mid1.setOrigin(mid1.getWidth() / 2, -begin1.getHeight()); mid2.setOrigin(mid2.getWidth() / 2, -begin1.getHeight()); end1.setOrigin(mid1.getWidth() / 2, -begin1.getHeight() - mid1.getHeight()); end2.setOrigin(mid2.getWidth() / 2, -begin1.getHeight() - mid2.getHeight()); begin1.setRotation(degrees); begin2.setRotation(degrees); mid1.setRotation(degrees); mid2.setRotation(degrees); end1.setRotation(degrees); end2.setRotation(degrees); Engine.getSpriteBatch().setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE); begin1.draw(Engine.getSpriteBatch()); begin2.draw(Engine.getSpriteBatch()); mid1.draw(Engine.getSpriteBatch()); mid2.draw(Engine.getSpriteBatch()); end1.draw(Engine.getSpriteBatch()); end2.draw(Engine.getSpriteBatch()); Engine.getSpriteBatch().setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); }
public GameLoadingScreen(StrategyGame inGame) { this.game = inGame; this.font = game.font; this.batch = game.batch; stage = new Stage(new ScreenViewport()); camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); Texture tex = new Texture(Gdx.files.internal("ui/game_loading.png")); background = new Sprite(tex); background.scale(1.0f); background.setPosition( (Gdx.graphics.getWidth() - background.getWidth()) / 2, (Gdx.graphics.getHeight() - background.getHeight()) / 2); }