/** * 读取gdx textureAtlas文件 * @param filePath atlas 文件路径 也可以自定义 * @param atlas */ public void addSpriteFrameWithTextureAtlas(String filePath, TextureAtlas atlas) { if(_atlases.containsKey(filePath)) { CCLog.debug(this.getClass(), "file loaded : " + filePath); return; } _atlases.put(filePath, atlas); Array<AtlasRegion> rs = atlas.getRegions(); for(AtlasRegion r : rs) { TextureRegion ret = _spriteFrames.put(r.name, r); if(ret != null) { CCLog.debug(this.getClass(), "region name exists : " + r.name); } } }
private void createRope(Body bodyA, Vector2 anchorA, Body bodyB, Vector2 anchorB, float sag, AtlasRegion ropeRegion) { RopeJointDef jd = new RopeJointDef(); jd.bodyA = bodyA; jd.bodyB = bodyB; jd.localAnchorA.set(anchorA.x, anchorA.y); jd.localAnchorB.set(anchorB.x, anchorB.y); // Max length of joint = current distance between bodies * sag float ropeLength = bodyA.getWorldPoint(anchorA).sub(bodyB.getWorldPoint(anchorB)).len() * sag; jd.maxLength = ropeLength; // Create joint RopeJoint joint = (RopeJoint)world.createJoint(jd); GdxRopeJoint ropeJoint = new GdxRopeJoint(joint, jd.localAnchorA, jd.localAnchorB); VRope newRope = new VRope(ropeJoint, this, ropeRegion); ropes.add(newRope); }
public VRope(GdxRopeJoint aJoint, Group group, AtlasRegion region, //(CCSpriteBatchNode*)spriteSheetArg List<VPoint> points, List<VStick> sticks, List<Image> sprites) { joint = aJoint; // spriteSheet = spriteSheetArg; this.group = group; this.region = region; vPoints = points; vSticks = sticks; ropeSprites = sprites; numPoints = vPoints.size(); }
AtlasRegion getSprite(int spriteIndex, boolean isOverlapSprite, Tile tile, float timeElapsed) { if(!isOverlapSprite && tileType != tile.getGroundType() && tileType != tile.getSurfaceType()) System.err.println("Warning: fetching sprite for tile "+tile+" that doesn't have the intended type " + tileType); Array<AtlasRegion> frames; String typeName = tileType.name().toLowerCase(); String indexString = (spriteIndex < 10 ? "0" : "") + spriteIndex; if(isOverlapSprite) { frames = tileOverlapAnimations.get(typeName).get(indexString); return overlay.getSprite(tile, frames, (int)(timeElapsed/overlayFrameTime)); } else { frames = tileConnectionAnimations.get(typeName).get(indexString); //if(!indexString.equals("00")) // System.out.println("fetching sprites for " + typeName + " at " + indexString + " as a connection sprite, from the main animation type " + main + "; frames="+frames); return main.getSprite(tile, frames, (int)(timeElapsed/mainFrameTime)); } }
@Override public void create () { entityAtlas = new TextureAtlas("sprites/entities.txt"); tileAtlas = new TextureAtlas("sprites/tiles.txt"); tileConnectionAtlas = new TextureAtlas("sprites/tileconnectmap.txt"); iconAtlas = new TextureAtlas("sprites/icons.txt"); batch = new SpriteBatch(); font = new BitmapFont(); // uses libGDX's default Arial font for(AtlasRegion region: iconAtlas.getRegions()) icons.put(region.name, region); game = this; this.setScreen(new MainMenuScreen()); }
public void setRegion (TextureRegion region) { if (region == null) throw new IllegalArgumentException("region cannot be null."); this.region = region; float[] vertices = this.vertices; if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) { vertices[U3] = region.getU(); vertices[V3] = region.getV2(); vertices[U4] = region.getU(); vertices[V4] = region.getV(); vertices[U1] = region.getU2(); vertices[V1] = region.getV(); vertices[U2] = region.getU2(); vertices[V2] = region.getV2(); } else { vertices[U2] = region.getU(); vertices[V2] = region.getV2(); vertices[U3] = region.getU(); vertices[V3] = region.getV(); vertices[U4] = region.getU2(); vertices[V4] = region.getV(); vertices[U1] = region.getU2(); vertices[V1] = region.getV2(); } }
public AnimatedSprite(String key, float totalDuration, Integer numLoops, State state) { super(); Array<AtlasRegion> frames = AssetManager.getInstance().getTextureRegions(key); float frameDuration = ConversionUtils.ms2s(totalDuration / frames.size); rawAnimation = new Animation(frameDuration, frames); this.numLoops = numLoops; if (numLoops == null || numLoops > 1) { rawAnimation.setPlayMode(PlayMode.LOOP); } this.state = state; setRegion(getCurrentFrame()); }
@Override public void act(float delta) { super.act(delta); PageGroup pp = PageGroup.this; Vector2 pointerPos = pp.screenToLocal(Gdx.input.getX(), Gdx.input.getY()); boolean withinPage = tmpBounds.set(0f, 0f, pp.getWidth(), pp.getHeight()).contains(pointerPos); if (!withinPage && active) { clearSpotlight(); } if (withinPage) { AtlasRegion region = hitRegion(pointerPos); if (region != null) { spotlightRegion(region); } if (region == null && active) { clearSpotlight(); } } }
private void spotlightRegion(AtlasRegion region) { if (this.region == region) return; this.region = region; active = true; // You can customize what is shown when user hover on region in here StringBuilder sb = new StringBuilder(); sb.append(region.name); if (region.index >= 0) { sb.append("[#fbf236ff] idx:" + region.index); } font.getData().setScale(1f); glText.setText(font, sb.toString(), Color.WHITE, 0f, Align.left, false); }
public GigaGalAssets(TextureAtlas atlas) { standingLeft = atlas.findRegion(Constants.STANDING_LEFT); standingRight = atlas.findRegion(Constants.STANDING_RIGHT); walkingLeft = atlas.findRegion(Constants.WALKING_LEFT_2); walkingRight = atlas.findRegion(Constants.WALKING_RIGHT_2); jumpingLeft = atlas.findRegion(Constants.JUMPING_LEFT); jumpingRight = atlas.findRegion(Constants.JUMPING_RIGHT); Array<AtlasRegion> walkingLeftFrames = new Array<AtlasRegion>(); walkingLeftFrames.add(atlas.findRegion(Constants.WALKING_LEFT_2)); walkingLeftFrames.add(atlas.findRegion(Constants.WALKING_LEFT_1)); walkingLeftFrames.add(atlas.findRegion(Constants.WALKING_LEFT_2)); walkingLeftFrames.add(atlas.findRegion(Constants.WALKING_LEFT_3)); walkingLeftAnimation = new Animation(Constants.WALK_LOOP_DURATION, walkingLeftFrames, PlayMode.LOOP); Array<AtlasRegion> walkingRightFrames = new Array<AtlasRegion>(); walkingRightFrames.add(atlas.findRegion(Constants.WALKING_RIGHT_2)); walkingRightFrames.add(atlas.findRegion(Constants.WALKING_RIGHT_1)); walkingRightFrames.add(atlas.findRegion(Constants.WALKING_RIGHT_2)); walkingRightFrames.add(atlas.findRegion(Constants.WALKING_RIGHT_3)); walkingRightAnimation = new Animation(Constants.WALK_LOOP_DURATION, walkingRightFrames, PlayMode.LOOP); }
public ExitPortalAssets(TextureAtlas atlas) { final AtlasRegion exitPortal1 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_1); final AtlasRegion exitPortal2 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_2); final AtlasRegion exitPortal3 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_3); final AtlasRegion exitPortal4 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_4); final AtlasRegion exitPortal5 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_5); final AtlasRegion exitPortal6 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_6); Array<AtlasRegion> exitPortalFrames = new Array<AtlasRegion>(); // TODO: Add the frames to the exitPortalFrames array exitPortalFrames.addAll(exitPortal1, exitPortal2, exitPortal3, exitPortal4, exitPortal5, exitPortal6); // TODO: Package the frames into an animation, using the frame duration constant // Go define that constant in Constants.java if you haven't already exitPortal = new Animation(Constants.EXIT_PORTAL_FRAME_DURATION, exitPortalFrames); }
/** * loads a specific animated sprite. The loaded sprite can then be retrieved with the * getAnimatedSprite() method. * Increases the accesscounter of the sprite if already loaded. * * @param texture type of texture to be used for the sprite */ public void loadAnimatedSprite(TextureType texture) { // check if texture atlas map contains the atlas type that should be used if (spriteMap != null && !spriteMap.containsKey(texture) && textureAtlasMap != null && textureAtlasMap.containsKey(texture.getTextureAtlasPath())) { // check if the atlas regions were successfully loaded for the texture atlas TextureAtlas textureAtlas = textureAtlasMap.get(texture.getTextureAtlasPath()).getResource(); if (atlasRegionMap != null && atlasRegionMap.containsKey(textureAtlas)) { Map<TextureType, AtlasRegion> regionMap = atlasRegionMap.get(textureAtlas); if (regionMap != null && regionMap.containsKey(texture)) { // create sprite out of texture atlas region's texture AnimatedSprite animatedSprite = new AnimatedSprite(regionMap.get(texture), texture); spriteMap.put(texture, new Resource<AnimatedSprite>(animatedSprite)); } } else { Gdx.app.log(GameConstants.LOG_TAG_INFO, "TextureAtlas does not contain region: " + texture.getAtlasRegionName()); } } else { // increase resource counter spriteMap.get(texture).incCounter(); } }
public ExitPortalAssets(TextureAtlas atlas) { final AtlasRegion exitPortal1 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_1); final AtlasRegion exitPortal2 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_2); final AtlasRegion exitPortal3 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_3); final AtlasRegion exitPortal4 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_4); final AtlasRegion exitPortal5 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_5); final AtlasRegion exitPortal6 = atlas.findRegion(Constants.EXIT_PORTAL_SPRITE_6); Array<AtlasRegion> exitPortalFrames = new Array<AtlasRegion>(); // TODO: Add the frames to the exitPortalFrames array // TODO: Package the frames into an animation, using the frame duration constant // Go define that constant in Constants.java if you haven't already }