List of usage examples for com.badlogic.gdx.graphics.g2d Sprite setSize
public void setSize(float width, float height)
From source file:CB_UI_Base.GL_UI.Controls.GestureHelp.java
License:Open Source License
@Override protected void render(Batch batch) { Sprite sprite = Sprites.Bubble.get(UseLastBtnBackground ? 4 : 3); sprite.setPosition(0, 0);/*from www.jav a 2s . c o m*/ sprite.setSize(getWidth(), getHeight()); sprite.draw(batch); super.render(batch); }
From source file:com.alma42.mapgen.game.WorldController.java
License:Apache License
private void createUser() { final int width = 32; final int height = 32; final Pixmap pixmap = createUser(width, height); // Create a new texture from pixmap data final Texture texture = new Texture(pixmap); // Create new sprites using the just created texture final Sprite spr = new Sprite(texture); // Define sprite size to be 1m x 1m in game world spr.setSize(1, 1); // Set origin to sprites center spr.setOrigin(spr.getWidth() / 2.0f, spr.getHeight() / 2.0f); spr.setPosition(0, 0);/*from www .ja v a 2 s. co m*/ // Put new sprite into array this.testSprites.add(spr); }
From source file:com.alma42.mapgen.game.WorldController.java
License:Apache License
private void initTestObjects() { this.map = new Map(6000, 10000, BiomeManagerFactory.ISLAND); this.map.createMap(); this.testSprites = new ArrayList<Sprite>(); createUser();/*from ww w .j a v a 2s . c o m*/ // Create new sprites using a random texture region for (final AGridComponent component : this.map.getGrid().getChilds().values()) { final Pixmap pixmap = createProceduralPixmap(component); // Create a new texture from pixmap data final Texture texture = new Texture(pixmap); final Sprite spr = new Sprite(texture); // Define sprite size to be 1m x 1m in game world spr.setSize((float) component.getSize(), (float) component.getSize()); final Point center = component.getCenter(); // Set origin to sprites center spr.setOrigin((float) center.getX(), (float) center.getY()); // Calculate random position for sprite spr.setPosition((float) center.getX(), (float) center.getY()); // spr.setColor(biomeManager.getBiome(component).getValue()); // Put new sprite into array this.testSprites.add(spr); } // Set first sprite as selected one this.selectedSprite = 0; }
From source file:com.example.squarejam.HelpAnimation.java
License:Open Source License
public static void start(List<Sprite> displayList, TweenManager manager, Texture dark_hand, Texture light_hand, Texture medium_hand, Texture tan_hand, Texture texBlue, Texture texGreen, Texture texPurple, Texture texOrange, Texture tablet, Texture help_bg) { final float squareApparitionDelay = 0.3f; final float squareApparitionTime = 1.3f; final float squareDelayBetweenApparitions = 0.5f; final float squareSlideDelay = squareApparitionDelay + squareDelayBetweenApparitions * 3 + squareApparitionTime + 0.8f; final float squareSlideTime = 2.2f; final float squareDelayBetweenSlides = 0.7f; final float tabletApparitionDelay = squareSlideDelay + squareDelayBetweenSlides * 3 + squareSlideTime + -0.3f;/* w w w. j a v a2 s. com*/ final float tabletApparitionTime = 1.1f; final float handApparitionDelay = tabletApparitionDelay + tabletApparitionTime + 0.3f; //TODO list other hand timings float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); //TODO condense into methods TextureRegion region = new TextureRegion(help_bg, 0, 0, 1024, 1024); Sprite bgSprite = new Sprite(region); bgSprite.setSize(1, 1); bgSprite.setOrigin(bgSprite.getWidth() / 2.0f, bgSprite.getHeight() / 2.0f); bgSprite.setPosition(-0.5f, -0.5f); displayList.add(bgSprite); //Add purple square and animate region = new TextureRegion(texPurple, 0, 0, 1, 1); Sprite purpleSprite = new Sprite(region); purpleSprite.setSize(0.15f, 0.15f); purpleSprite.setOrigin(purpleSprite.getWidth() / 2.0f, purpleSprite.getHeight() / 2.0f); purpleSprite.setPosition(-0.075f, 0.1f); displayList.add(purpleSprite); Tween.set(purpleSprite, SpriteAccessor.SIZE_XY).target(0, 0).start(manager); Tween.to(purpleSprite, SpriteAccessor.SIZE_XY, squareApparitionTime).target(1, 1) .delay(squareApparitionDelay + squareDelayBetweenApparitions * 0).start(manager); //Add blue square and animate region = new TextureRegion(texBlue, 0, 0, 1, 1); Sprite blueSprite = new Sprite(region); blueSprite.setSize(0.15f, 0.15f); blueSprite.setOrigin(blueSprite.getWidth() / 2.0f, blueSprite.getHeight() / 2.0f); blueSprite.setPosition(-0.25f, -0.075f); displayList.add(blueSprite); Tween.set(blueSprite, SpriteAccessor.SIZE_XY).target(0, 0).start(manager); Tween.to(blueSprite, SpriteAccessor.SIZE_XY, squareApparitionTime).target(1, 1) .delay(squareApparitionDelay + squareDelayBetweenApparitions * 1).start(manager); //Add orange square and animate region = new TextureRegion(texOrange, 0, 0, 1, 1); Sprite orangeSprite = new Sprite(region); orangeSprite.setSize(0.15f, 0.15f); orangeSprite.setOrigin(orangeSprite.getWidth() / 2.0f, orangeSprite.getHeight() / 2.0f); orangeSprite.setPosition(0.1f, -0.075f); displayList.add(orangeSprite); Tween.set(orangeSprite, SpriteAccessor.SIZE_XY).target(0, 0).start(manager); Tween.to(orangeSprite, SpriteAccessor.SIZE_XY, squareApparitionTime).target(1, 1) .delay(squareApparitionDelay + squareDelayBetweenApparitions * 2).start(manager); //Add green square and animate region = new TextureRegion(texGreen, 0, 0, 1, 1); Sprite greenSprite = new Sprite(region); greenSprite.setSize(0.15f, 0.15f); greenSprite.setOrigin(greenSprite.getWidth() / 2.0f, greenSprite.getHeight() / 2.0f); greenSprite.setPosition(-0.075f, -0.25f); displayList.add(greenSprite); Tween.set(greenSprite, SpriteAccessor.SIZE_XY).target(0, 0).start(manager); Tween.to(greenSprite, SpriteAccessor.SIZE_XY, squareApparitionTime).target(1, 1) .delay(squareApparitionDelay + squareDelayBetweenApparitions * 3).start(manager); //Slides Tween.to(purpleSprite, SpriteAccessor.POSITION_Y, squareSlideTime).target(1.1f) .delay(squareSlideDelay + squareDelayBetweenSlides * 0).start(manager); Tween.to(blueSprite, SpriteAccessor.POSITION_X, squareSlideTime).target(-1.25f) .delay(squareSlideDelay + squareDelayBetweenSlides * 1).start(manager); Tween.to(orangeSprite, SpriteAccessor.POSITION_X, squareSlideTime).target(1.1f) .delay(squareSlideDelay + squareDelayBetweenSlides * 2).start(manager); Tween.to(greenSprite, SpriteAccessor.POSITION_Y, squareSlideTime).target(-1.25f) .delay(squareSlideDelay + squareDelayBetweenSlides * 3).start(manager); //Add Tablet and animate region = new TextureRegion(tablet, 0, 0, 512, 386); Sprite tabSprite = new Sprite(region); tabSprite.setSize(0.5f, 386.0f / 512.0f / 2.0f); tabSprite.setOrigin(tabSprite.getWidth() / 2, tabSprite.getHeight() / 2); tabSprite.setPosition(-0.25f, h / w / 2); displayList.add(tabSprite); Tween.to(tabSprite, SpriteAccessor.POSITION_XY, tabletApparitionTime).target(-0.25f, -0.2f) .ease(Cubic.INOUT).delay(tabletApparitionDelay).start(manager); //Add dark hand and animate region = new TextureRegion(dark_hand, 120, 0, 256, 256); Sprite dhSprite = new Sprite(region); dhSprite.setSize(0.25f, 0.25f); dhSprite.setOrigin(0.09f, 0.23f); dhSprite.setPosition(0, 0.3f); dhSprite.setRotation(180); displayList.add(dhSprite); Tween.to(dhSprite, SpriteAccessor.POSITION_XY, 1.3f).target(0.07f, -0.13f).delay(handApparitionDelay + 0.2f) .start(manager); Tween.to(dhSprite, SpriteAccessor.POSITION_XY, 1.3f).target(-0.03f, -0.33f) .delay(handApparitionDelay + 2.3f).start(manager); Tween.to(dhSprite, SpriteAccessor.POSITION_XY, 1.0f).target(0.07f, -0.33f).delay(handApparitionDelay + 4.4f) .start(manager); Tween.to(dhSprite, SpriteAccessor.POSITION_XY, 2.0f).target(-0.07f, 0.03f).delay(handApparitionDelay + 6.5f) .start(manager); //Add light hand and animate region = new TextureRegion(light_hand, 120, 0, 256, 256); Sprite lhSprite = new Sprite(region); lhSprite.setSize(0.25f, 0.25f); lhSprite.setOrigin(0.09f, 0.23f); lhSprite.setPosition(-0.7f, 0.0f); lhSprite.setRotation(270); displayList.add(lhSprite); Tween.to(lhSprite, SpriteAccessor.POSITION_XY, 2.3f).target(-0.03f, -0.13f).delay(handApparitionDelay) .start(manager); Tween.to(lhSprite, SpriteAccessor.POSITION_XY, 1.3f).target(-0.25f, -0.23f) .delay(handApparitionDelay + 3.1f).start(manager); Tween.to(lhSprite, SpriteAccessor.POSITION_XY, 1.0f).target(-0.5f, -0.25f).delay(handApparitionDelay + 5.2f) .start(manager); //Add tan hand and animate region = new TextureRegion(tan_hand, 120, 0, 256, 256); Sprite thSprite = new Sprite(region); thSprite.setSize(0.25f, 0.25f); thSprite.setOrigin(0.09f, 0.23f); thSprite.setPosition(0.5f, -0.2f); thSprite.setRotation(90); displayList.add(thSprite); Tween.to(thSprite, SpriteAccessor.POSITION_XY, 2.0f).target(-0.03f, -0.23f) .delay(handApparitionDelay + 0.1f).start(manager); Tween.to(thSprite, SpriteAccessor.POSITION_XY, 1.2f).target(-0.13f, -0.25f) .delay(handApparitionDelay + 2.5f).start(manager); Tween.to(thSprite, SpriteAccessor.POSITION_XY, 1.2f).target(-0.13f, -0.14f) .delay(handApparitionDelay + 3.8f).start(manager); Tween.to(thSprite, SpriteAccessor.POSITION_XY, 1.5f).target(-0.23f, -0.35f) .delay(handApparitionDelay + 6.0f).start(manager); Tween.to(thSprite, SpriteAccessor.POSITION_XY, 2.0f).target(0.3f, -0.2f).delay(handApparitionDelay + 8.1f) .start(manager); //Add medium hand and animate region = new TextureRegion(medium_hand, 120, 0, 256, 256); Sprite mhSprite = new Sprite(region); mhSprite.setSize(0.25f, 0.25f); mhSprite.setOrigin(0.09f, 0.23f); mhSprite.setPosition(0.0f, -0.6f); displayList.add(mhSprite); Tween.to(mhSprite, SpriteAccessor.POSITION_XY, 1.8f).target(-0.13f, -0.33f) .delay(handApparitionDelay + 0.4f).start(manager); Tween.to(mhSprite, SpriteAccessor.POSITION_XY, 1.4f).target(0.07f, -0.23f).delay(handApparitionDelay + 3.3f) .start(manager); Tween.to(mhSprite, SpriteAccessor.POSITION_XY, 2.0f).target(-0.25f, -0.13f) .delay(handApparitionDelay + 5.5f).start(manager); Tween.to(mhSprite, SpriteAccessor.POSITION_XY, 2.0f).target(0.0f, -0.5f).delay(handApparitionDelay + 8.1f) .start(manager); }
From source file:com.example.squarejam.MyGdxGame.java
License:Open Source License
private void addMenuItem(Texture squareTexture, float x, float y, float size, float delayTime, float animTime, int texX, int texY, int texHeight, int texWidth) { TextureRegion region = new TextureRegion(squareTexture, texX, texY, texHeight, texWidth); Sprite introSquare = new Sprite(region); introSquare.setSize(size, size); introSquare.setOrigin(0, 0);//ww w . j a v a 2s. co m introSquare.setPosition(x, 0.8f); //Viewport goes from -0.5f to 0.5f Tween.to(introSquare, SpriteAccessor.POSITION_XY, animTime).target(x, y).ease(Back.OUT).delay(delayTime) .start(manager); displayList.add(introSquare); }
From source file:com.example.squarejam.MyGdxGame.java
License:Open Source License
public void intro() { gameStep = 0;/*from w ww .j a v a 2 s.c o m*/ gameTimeSeconds = 0; gameState = INTRO_MENU; float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); displayList.clear(); addMenuItem(help_bg, -0.5f, -0.5f, 1.0f, 0, 0, 0, 0, 1024, 1024); addMenuItem(question, -0.03f, -h / w / 2 + 0.01f, 0.06f, 3.4f, 0.8f); addMenuItem(two, -0.19f, -0.10f, 0.1f, 2.8f, 0.5f); //This must be the third square addMenuItem(three, -0.05f, -0.10f, 0.1f, 2.8f, 0.5f); //This must be the fourth square addMenuItem(four, 0.09f, -0.10f, 0.1f, 2.8f, 0.5f); //This must be the fifth square addMenuItem(S, -0.265f, h / w / 2 - 0.12f, 0.08f, 0.2f, 0.5f); addMenuItem(Q, -0.175f, h / w / 2 - 0.12f, 0.08f, 0.4f, 0.5f); addMenuItem(U, -0.085f, h / w / 2 - 0.12f, 0.08f, 0.6f, 0.5f); addMenuItem(A, 0.005f, h / w / 2 - 0.12f, 0.08f, 0.8f, 0.5f); addMenuItem(R, 0.095f, h / w / 2 - 0.12f, 0.08f, 1.0f, 0.5f); addMenuItem(E, 0.185f, h / w / 2 - 0.12f, 0.08f, 1.2f, 0.5f); addMenuItem(J, -0.13f, h / w / 2 - 0.22f, 0.08f, 1.8f, 0.5f); addMenuItem(JAM_A, -0.04f, h / w / 2 - 0.22f, 0.08f, 2.0f, 0.5f); addMenuItem(M, 0.05f, h / w / 2 - 0.22f, 0.08f, 2.2f, 0.5f); TextureRegion region = new TextureRegion(twitt, 0, 0, 143, 13); Sprite twittSprite = new Sprite(region); twittSprite.setSize(0.5f, 13.0f / 143.0f / 2.0f); twittSprite.setOrigin(twittSprite.getWidth() / 2, twittSprite.getHeight() / 2); twittSprite.setPosition(-0.25f, -h / w / 2 + 0.1f); Tween.set(twittSprite, SpriteAccessor.OPACITY).target(0).start(manager); Tween.to(twittSprite, SpriteAccessor.OPACITY, 3.0f).target(1.0f).delay(4.3f).start(manager); displayList.add(twittSprite); }
From source file:com.example.squarejam.MyGdxGame.java
License:Open Source License
public void endGame() { gameStep = 0;//from www. j a v a 2 s . c o m gameState = SCORE_SCREEN; scoreScreenPaused = true; destroyGrid(0, 0); System.out.println("Orange: " + orangeScore); System.out.println("Blue: " + blueScore); System.out.println("Green: " + greenScore); System.out.println("Purple: " + purpleScore); System.out.println("DONE!"); float w = Gdx.graphics.getWidth(); float h = Gdx.graphics.getHeight(); float maxScore = Math.max(Math.max(purpleScore, blueScore), Math.max(greenScore, orangeScore)); if (maxScore == 0) { //Prevent divide by 0 maxScore = 1; } Sprite purpleScoreRect = new Sprite(new TextureRegion(texPurple, 0, 0, 1, 1)); purpleScoreRect.setSize(0.25f, 1); purpleScoreRect.setOrigin(0, 0); purpleScoreRect.setPosition(0.25f, -h / (2 * w)); Sprite blueScoreRect = new Sprite(new TextureRegion(texBlue, 0, 0, 1, 1)); blueScoreRect.setSize(0.25f, 1); blueScoreRect.setOrigin(0, 0); blueScoreRect.setPosition(-0.25f, -h / (2 * w)); Sprite greenScoreRect = new Sprite(new TextureRegion(texGreen, 0, 0, 1, 1)); greenScoreRect.setSize(0.25f, 1); greenScoreRect.setOrigin(0, 0); greenScoreRect.setPosition(-0.0f, -h / (2 * w)); Sprite orangeScoreRect = new Sprite(new TextureRegion(texOrange, 0, 0, 1, 1)); orangeScoreRect.setSize(0.25f, 1); orangeScoreRect.setOrigin(0, 0); orangeScoreRect.setPosition(-0.5f, -h / (2 * w)); tweenRectYSize(purpleScoreRect, 0, 0, 0); tweenRectYSize(blueScoreRect, 0, 0, 0); tweenRectYSize(greenScoreRect, 0, 0, 0); tweenRectYSize(orangeScoreRect, 0, 0, 0); tweenRectYSize(orangeScoreRect, orangeScore * (h / w) / maxScore, 1.0f * orangeScore * (h / w) / maxScore + 0.5f, 0); tweenRectYSize(blueScoreRect, blueScore * (h / w) / maxScore, 1.0f * blueScore * (h / w) / maxScore + 0.5f, 1.7f); tweenRectYSize(greenScoreRect, greenScore * (h / w) / maxScore, 1.0f * greenScore * (h / w) / maxScore + 0.5f, 3.4f); tweenRectYSize(purpleScoreRect, purpleScore * (h / w) / maxScore, 1.0f * purpleScore * (h / w) / maxScore + 0.5f, 5.1f); Tween.call(new ScoreScreenCallback(this)).delay(5.0f).start(manager); displayList.add(purpleScoreRect); displayList.add(blueScoreRect); displayList.add(greenScoreRect); displayList.add(orangeScoreRect); purpleScore = 0; blueScore = 0; greenScore = 0; orangeScore = 0; }
From source file:com.kotcrab.vis.editor.module.physicseditor.PRigidBodiesScreen.java
License:Apache License
private void createBall(Vector2 orig, Vector2 force) { Random rand = new Random(); float radius = rand.nextFloat() * 0.02f + 0.02f; BodyDef bd = new BodyDef(); bd.type = BodyType.DynamicBody;/*from w w w . ja v a 2 s. c om*/ bd.angularDamping = 0.5f; bd.linearDamping = 0.5f; bd.position.set(orig); bd.angle = rand.nextFloat() * MathUtils.PI; Body b = world.createBody(bd); b.applyLinearImpulse(force, orig, true); ballsBodies.add(b); CircleShape shape = new CircleShape(); shape.setRadius(radius); FixtureDef fd = new FixtureDef(); fd.density = 1f; fd.friction = 0.5f; fd.restitution = 1f; fd.shape = shape; b.createFixture(fd); Sprite sp = new Sprite(Assets.getMiscRegion("ball")); sp.setSize(radius * 2, radius * 2); sp.setOrigin(sp.getWidth() / 2, sp.getHeight() / 2); ballsSprites.add(sp); }
From source file:com.laex.cg2d.render.impl.BackgroundManager.java
License:Open Source License
@Override public void create() { backgroundTextures = new LinkedList<Sprite>(); for (CGLayer layer : manipulator.model().getLayersList()) { for (CGShape shape : layer.getShapeList()) { if (!(shape.getEditorShapeType() == CGEditorShapeType.BACKGROUND_SHAPE)) { continue; }/* w w w .j a va 2 s . com*/ FileHandle handle = Gdx.files.absolute(shape.getBackgroundResourceFile().getResourceFileAbsolute()); Texture tex = new Texture(handle); tex.setFilter(TextureFilter.Linear, TextureFilter.Linear); /* for clamping edge of background textures */ tex.setWrap(TextureWrap.Repeat, TextureWrap.Repeat); Sprite sprite = new Sprite(tex); float x = shape.getBounds().getX(); float y = shape.getBounds().getY(); float width = shape.getBounds().getWidth(); float height = shape.getBounds().getHeight(); Vector2 scrPos = new Vector2(x, y); Vector2 worldPos = ScreenToWorld.inst(manipulator.model()).screenToWorldFlipped(scrPos, height); sprite.setPosition(worldPos.x, worldPos.y); float w = (width / manipulator.ptmRatio()); float h = (height / manipulator.ptmRatio()); sprite.setSize(w, h); backgroundTextures.add(sprite); } } }
From source file:com.laex.cg2d.render.impl.EntityManager.java
License:Open Source License
/** * Creates the entity./*from www . j a va 2 s.co m*/ * * @param shape * the shape * @param animationName * the animation name * @return the body * @throws IOException * Signals that an I/O exception has occurred. */ public Body createEntity(CGShape shape, String animationName) throws IOException { CGEditorShapeType eType = shape.getEditorShapeType(); if (eType == CGEditorShapeType.BACKGROUND_SHAPE) { return null; } /* We alo create shapes */ if (eType == CGEditorShapeType.SIMPLE_SHAPE_BOX || eType == CGEditorShapeType.SIMPLE_SHAPE_CIRCLE || eType == CGEditorShapeType.SIMPLE_SHAPE_HEDGE || eType == CGEditorShapeType.SIMPLE_SHAPE_VEDGE) { Body b = manipulator.createBody(shape, null, null); b.setUserData(shape); return b; } /* For Entities */ String entPath = shape.getEntityRefFile().getResourceFileAbsolute(); final CGEntity entity = CGEntity.parseFrom(Gdx.files.absolute(entPath).read()); shapeToEntityMap.put(shape, entity); /* Entity Animation */ CGEntityAnimation ea = null; /* If name is not provided, get default animation */ if (animationName == null) { ea = RunnerUtil.getDefaultAnimation(entity); } else { ea = RunnerUtil.getAnimationFrom(entity, animationName); } Body b = manipulator.createBody(shape, entity, ea); b.setUserData(shape); // Resource file empty indicates this entity might not have // image & collision shape defined. if (ea.getSpritesheetFile().getResourceFileAbsolute().trim().isEmpty()) { manipulator.world().destroyBody(b); return null; } FileHandle handle = Gdx.files.absolute(ea.getSpritesheetFile().getResourceFileAbsolute()); Texture tex = new Texture(handle); tex.setFilter(TextureFilter.Linear, TextureFilter.Linear); Array<TextureRegion> walkFrames = new Array<TextureRegion>(); for (CGEntitySpritesheetItem cgEi : ea.getSpritesheetItemsList()) { CGBounds bnds = cgEi.getExtractBounds(); TextureRegion tr = new TextureRegion(tex, (int) bnds.getX(), (int) bnds.getY(), (int) bnds.getWidth(), (int) bnds.getHeight()); walkFrames.add(tr); } Animation spriteAnimation = new Animation(ea.getAnimationDuration(), walkFrames); shapeToAnimationMap.put(shape, spriteAnimation); Sprite spr = new Sprite(spriteAnimation.getKeyFrame(stateTime, true)); // Set the position & size float x = shape.getBounds().getX(); float y = shape.getBounds().getY(); float width = shape.getBounds().getWidth(); float height = shape.getBounds().getHeight(); Vector2 scrPos = new Vector2(x, y); Vector2 worldPos = ScreenToWorld.inst(manipulator.model()).screenToWorldFlipped(scrPos, height); spr.setPosition(worldPos.x, worldPos.y); // the position circle (collision shape) will vary with that of // a box. so // we need to check and set position for each types if (ea.getCollisionType() == CGEntityCollisionType.CIRCLE) { Vector3 origin = shapeToAnimationOriginMap.get(shape); float radius = origin.z; float x1 = (worldPos.x - radius); float y1 = (worldPos.y - radius); spr.setPosition(x1, y1); } float w = ((float) width / manipulator.ptmRatio()); float h = ((float) height / manipulator.ptmRatio()); spr.setSize(w, h); shapeToSpriteMap.put(shape, spr); return b; }