List of usage examples for com.badlogic.gdx.math Polygon setScale
public void setScale(float scaleX, float scaleY)
From source file:com.bladecoder.engine.loader.ChapterXMLLoader.java
License:Apache License
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if (currentVerb != null) { // INSIDE VERB if (!localName.equals(XMLConstants.ACTION_TAG)) { SAXParseException e2 = new SAXParseException("TAG not supported inside VERB: " + localName, locator);//from ww w .j av a 2s . co m error(e2); throw e2; } parseAction(atts, actor != null ? actor.getId() : null); } else if (currentDialog != null) { // INSIDE DIALOG if (!localName.equals(XMLConstants.OPTION_TAG)) { SAXParseException e2 = new SAXParseException("Only 'option' tag allowed in dialogs", locator); error(e2); throw e2; } parseOption(atts); } else if (localName.equals(XMLConstants.ACTOR_TAG)) { parseActor(atts); } else if (localName.equals(XMLConstants.ANIMATION_TAG)) { parseAnimation(atts); } else if (localName.equals(XMLConstants.VERB_TAG)) { parseVerb(atts, actor != null ? ((InteractiveActor) actor).getVerbManager() : scene.getVerbManager()); } else if (localName.equals(XMLConstants.DIALOG_TAG)) { String id = atts.getValue(XMLConstants.ID_ATTR); currentDialog = new Dialog(); currentDialog.setId(id); currentDialog.setActor(actor.getId()); ((CharacterActor) actor).addDialog(currentDialog); } else if (localName.equals(XMLConstants.SOUND_TAG)) { parseSound(atts, (InteractiveActor) actor); } else if (localName.equals(XMLConstants.CHAPTER_TAG)) { initScene = atts.getValue(XMLConstants.INIT_SCENE_ATTR); } else if (localName.equals(XMLConstants.WALK_ZONE_TAG)) { PolygonalNavGraph polygonalPathFinder = new PolygonalNavGraph(); Polygon poly = new Polygon(); Param.parsePolygon(poly, atts.getValue(XMLConstants.POLYGON_ATTR), atts.getValue(XMLConstants.POS_ATTR)); poly.setScale(scale, scale); poly.setPosition(poly.getX() * scale, poly.getY() * scale); polygonalPathFinder.setWalkZone(poly); scene.setPolygonalNavGraph(polygonalPathFinder); } else if (localName.equals(XMLConstants.SCENE_TAG)) { parseScene(atts); } else if (localName.equals(XMLConstants.LAYER_TAG)) { parseLayer(atts); } else { // SAXParseException e = new SAXParseException("Wrong label '" // + localName + "' loading Scene.", locator); // error(e); // throw e; EngineLogger.error( "TAG not supported in Chapter document: " + localName + " LINE: " + locator.getLineNumber()); } }
From source file:com.cafeitvn.myballgame.screen.Box2DMapObjectParser.java
License:Apache License
/** * creates a {@link Fixture} from a {@link MapObject} * @param mapObject the {@link MapObject} which to parse * @return the parsed {@link Fixture}// w w w . ja v a 2 s . c o m */ public Fixture createFixture(MapObject mapObject) { MapProperties properties = mapObject.getProperties(); String type = properties.get("type", String.class); Body body = bodies.get( type.equals(aliases.object) ? mapObject.getName() : properties.get(aliases.body, String.class)); if (!type.equals(aliases.fixture) && !type.equals(aliases.object)) throw new IllegalArgumentException("type of " + mapObject + " is \"" + type + "\" instead of \"" + aliases.fixture + "\" or \"" + aliases.object + "\""); FixtureDef fixtureDef = new FixtureDef(); Shape shape = null; if (mapObject instanceof RectangleMapObject) { shape = new PolygonShape(); Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle(); rectangle.x *= unitScale; rectangle.y *= unitScale; rectangle.width *= unitScale; rectangle.height *= unitScale; ((PolygonShape) shape).setAsBox(rectangle.width / 2, rectangle.height / 2, new Vector2(rectangle.x - body.getPosition().x + rectangle.width / 2, rectangle.y - body.getPosition().y + rectangle.height / 2), body.getAngle()); } else if (mapObject instanceof PolygonMapObject) { shape = new PolygonShape(); Polygon polygon = ((PolygonMapObject) mapObject).getPolygon(); polygon.setPosition(polygon.getX() * unitScale - body.getPosition().x, polygon.getY() * unitScale - body.getPosition().y); polygon.setScale(unitScale, unitScale); ((PolygonShape) shape).set(polygon.getTransformedVertices()); } else if (mapObject instanceof PolylineMapObject) { shape = new ChainShape(); Polyline polyline = ((PolylineMapObject) mapObject).getPolyline(); polyline.setPosition(polyline.getX() * unitScale - body.getPosition().x, polyline.getY() * unitScale - body.getPosition().y); polyline.setScale(unitScale, unitScale); ((ChainShape) shape).createChain(polyline.getTransformedVertices()); } else if (mapObject instanceof CircleMapObject) { shape = new CircleShape(); Circle circle = ((CircleMapObject) mapObject).getCircle(); circle.setPosition(circle.x * unitScale - body.getPosition().x, circle.y * unitScale - body.getPosition().y); circle.radius *= unitScale; ((CircleShape) shape).setPosition(new Vector2(circle.x, circle.y)); ((CircleShape) shape).setRadius(circle.radius); } else if (mapObject instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); if (ellipse.width == ellipse.height) { CircleMapObject circleMapObject = new CircleMapObject(ellipse.x, ellipse.y, ellipse.width / 2); circleMapObject.setName(mapObject.getName()); circleMapObject.getProperties().putAll(mapObject.getProperties()); circleMapObject.setColor(mapObject.getColor()); circleMapObject.setVisible(mapObject.isVisible()); circleMapObject.setOpacity(mapObject.getOpacity()); return createFixture(circleMapObject); } IllegalArgumentException exception = new IllegalArgumentException( "Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s that are not circles are not supported"); Gdx.app.error(getClass().getSimpleName(), exception.getMessage(), exception); throw exception; } else if (mapObject instanceof TextureMapObject) { IllegalArgumentException exception = new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s are not supported"); Gdx.app.error(getClass().getSimpleName(), exception.getMessage(), exception); throw exception; } else assert false : mapObject + " is a not known subclass of " + MapObject.class.getName(); fixtureDef.shape = shape; fixtureDef.density = (Float) getProperty(properties, aliases.density, fixtureDef.density, Float.class); fixtureDef.filter.categoryBits = (Short) getProperty(properties, aliases.categoryBits, fixtureDef.filter.categoryBits, Short.class); fixtureDef.filter.groupIndex = (Short) getProperty(properties, aliases.groupIndex, fixtureDef.filter.groupIndex, Short.class); fixtureDef.filter.maskBits = (Short) getProperty(properties, aliases.maskBits, fixtureDef.filter.maskBits, Short.class); fixtureDef.friction = (Float) getProperty(properties, aliases.friciton, fixtureDef.friction, Float.class); fixtureDef.isSensor = (Boolean) getProperty(properties, aliases.isSensor, fixtureDef.isSensor, Boolean.class); fixtureDef.restitution = (Float) getProperty(properties, aliases.restitution, fixtureDef.restitution, Float.class); Fixture fixture = body.createFixture(fixtureDef); shape.dispose(); String name = mapObject.getName(); if (fixtures.containsKey(name)) { int duplicate = 1; while (fixtures.containsKey(name + duplicate)) duplicate++; name += duplicate; } fixtures.put(name, fixture); return fixture; }
From source file:com.kotcrab.vis.runtime.entity.TextEntity.java
License:Apache License
private void calculateBoundingRectangle() { Polygon polygon = new Polygon(new float[] { 0, 0, textLayout.width, 0, textLayout.width, textLayout.height, 0, textLayout.height });/*from w w w.j ava 2 s. c om*/ polygon.setPosition(x, y); polygon.setRotation(rotation); polygon.setScale(scaleX, scaleY); polygon.setOrigin(originX, originY); boundingRectangle = polygon.getBoundingRectangle(); }
From source file:com.rubentxu.juegos.core.utils.dermetfan.box2d.Box2DMapObjectParser.java
License:Apache License
/** * creates a {@link Fixture} from a {@link MapObject} * * @param mapObject the {@link MapObject} to parse * @return the parsed {@link Fixture}/*from ww w .j a va 2s. c o m*/ */ public Fixture createFixture(MapObject mapObject) { MapProperties properties = mapObject.getProperties(); String type = properties.get("type", String.class); Body body = bodies.get( type.equals(aliases.object) ? mapObject.getName() : properties.get(aliases.body, String.class)); if (!type.equals(aliases.fixture) && !type.equals(aliases.object)) throw new IllegalArgumentException("type of " + mapObject + " is \"" + type + "\" instead of \"" + aliases.fixture + "\" or \"" + aliases.object + "\""); FixtureDef fixtureDef = new FixtureDef(); Shape shape = null; if (mapObject instanceof RectangleMapObject) { shape = new PolygonShape(); Rectangle rectangle = new Rectangle(((RectangleMapObject) mapObject).getRectangle()); rectangle.x *= unitScale; rectangle.y *= unitScale; rectangle.width *= unitScale; rectangle.height *= unitScale; ((PolygonShape) shape).setAsBox(rectangle.width / 2, rectangle.height / 2, new Vector2(rectangle.x - body.getPosition().x + rectangle.width / 2, rectangle.y - body.getPosition().y + rectangle.height / 2), body.getAngle()); } else if (mapObject instanceof PolygonMapObject) { shape = new PolygonShape(); Polygon polygon = ((PolygonMapObject) mapObject).getPolygon(); polygon.setPosition(polygon.getX() * unitScale - body.getPosition().x, polygon.getY() * unitScale - body.getPosition().y); polygon.setScale(unitScale, unitScale); ((PolygonShape) shape).set(polygon.getTransformedVertices()); } else if (mapObject instanceof PolylineMapObject) { shape = new ChainShape(); Polyline polyline = ((PolylineMapObject) mapObject).getPolyline(); polyline.setPosition(polyline.getX() * unitScale - body.getPosition().x, polyline.getY() * unitScale - body.getPosition().y); polyline.setScale(unitScale, unitScale); float[] vertices = polyline.getTransformedVertices(); Vector2[] vectores = new Vector2[vertices.length / 2]; for (int i = 0, j = 0; i < vertices.length; i += 2, j++) { vectores[j].x = vertices[i]; vectores[j].y = vertices[i + 1]; } ((ChainShape) shape).createChain(vectores); } else if (mapObject instanceof CircleMapObject) { shape = new CircleShape(); Circle circle = ((CircleMapObject) mapObject).getCircle(); circle.setPosition(circle.x * unitScale - body.getPosition().x, circle.y * unitScale - body.getPosition().y); circle.radius *= unitScale; ((CircleShape) shape).setPosition(new Vector2(circle.x, circle.y)); ((CircleShape) shape).setRadius(circle.radius); } else if (mapObject instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); /* b2ChainShape* chain = (b2ChainShape*)addr; b2Vec2* verticesOut = new b2Vec2[numVertices]; for( int i = 0; i < numVertices; i++ ) verticesOut[i] = b2Vec2(verts[i<<1], verts[(i<<1)+1]); chain->CreateChain( verticesOut, numVertices ); delete verticesOut; */ if (ellipse.width == ellipse.height) { CircleMapObject circleMapObject = new CircleMapObject(ellipse.x, ellipse.y, ellipse.width / 2); circleMapObject.setName(mapObject.getName()); circleMapObject.getProperties().putAll(mapObject.getProperties()); circleMapObject.setColor(mapObject.getColor()); circleMapObject.setVisible(mapObject.isVisible()); circleMapObject.setOpacity(mapObject.getOpacity()); return createFixture(circleMapObject); } IllegalArgumentException exception = new IllegalArgumentException( "Cannot parse " + mapObject.getName() + " because that are not circles are not supported"); Gdx.app.error(getClass().getName(), exception.getMessage(), exception); throw exception; } else if (mapObject instanceof TextureMapObject) { IllegalArgumentException exception = new IllegalArgumentException( "Cannot parse " + mapObject.getName() + " because s are not supported"); Gdx.app.error(getClass().getName(), exception.getMessage(), exception); throw exception; } else assert false : mapObject + " is a not known subclass of " + MapObject.class.getName(); fixtureDef.shape = shape; fixtureDef.density = getProperty(properties, aliases.density, fixtureDef.density); fixtureDef.filter.categoryBits = getProperty(properties, aliases.categoryBits, GRUPO.STATIC.getCategory()); fixtureDef.filter.groupIndex = getProperty(properties, aliases.groupIndex, fixtureDef.filter.groupIndex); fixtureDef.filter.maskBits = getProperty(properties, aliases.maskBits, Box2DPhysicsObject.MASK_STATIC); fixtureDef.friction = getProperty(properties, aliases.friciton, fixtureDef.friction); fixtureDef.isSensor = getProperty(properties, aliases.isSensor, fixtureDef.isSensor); fixtureDef.restitution = getProperty(properties, aliases.restitution, fixtureDef.restitution); Fixture fixture = body.createFixture(fixtureDef); fixture.setUserData(body.getUserData()); shape.dispose(); String name = mapObject.getName(); if (fixtures.containsKey(name)) { int duplicate = 1; while (fixtures.containsKey(name + duplicate)) duplicate++; name += duplicate; } fixtures.put(name, fixture); return fixture; }
From source file:net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** creates a {@link Fixture} from a {@link MapObject} * @param mapObject the {@link MapObject} to parse * @param body the {@link Body} to create the {@link Fixture Fixtures} on * @return the parsed {@link Fixture} */ public Fixture createFixture(MapObject mapObject, Body body) { MapProperties properties = mapObject.getProperties(); Shape shape = null;/* w w w . j a v a2s . c om*/ if (mapObject instanceof RectangleMapObject) { shape = new PolygonShape(); Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle(); float x = rectangle.x * unitScale, y = rectangle.y * unitScale, width = rectangle.width * unitScale, height = rectangle.height * unitScale; ((PolygonShape) shape).setAsBox(width / 2, height / 2, vec2.set(x - body.getPosition().x + width / 2, y - body.getPosition().y + height / 2), body.getAngle()); } else if (mapObject instanceof PolygonMapObject) { shape = new PolygonShape(); Polygon polygon = new Polygon(((PolygonMapObject) mapObject).getPolygon().getTransformedVertices()); polygon.setScale(unitScale, unitScale); polygon.setPosition(-body.getPosition().x, -body.getPosition().y); ((PolygonShape) shape).set(polygon.getTransformedVertices()); } else if (mapObject instanceof PolylineMapObject) { shape = new ChainShape(); Polyline polyline = new Polyline( ((PolylineMapObject) mapObject).getPolyline().getTransformedVertices()); polyline.setPosition(polyline.getX() * unitScale - body.getPosition().x, polyline.getY() * unitScale - body.getPosition().y); polyline.setScale(unitScale, unitScale); ((ChainShape) shape).createChain(polyline.getTransformedVertices()); } else if (mapObject instanceof CircleMapObject) { shape = new CircleShape(); Circle mapObjectCircle = ((CircleMapObject) mapObject).getCircle(); Circle circle = new Circle(mapObjectCircle.x, mapObjectCircle.y, mapObjectCircle.radius); circle.setPosition(circle.x * unitScale - body.getPosition().x, circle.y * unitScale - body.getPosition().y); circle.radius *= unitScale; CircleShape circleShape = (CircleShape) shape; circleShape.setPosition(vec2.set(circle.x, circle.y)); circleShape.setRadius(circle.radius); } else if (mapObject instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); if (ellipse.width == ellipse.height) { CircleMapObject circleMapObject = new CircleMapObject(ellipse.x + ellipse.width / 2, ellipse.y + ellipse.height / 2, ellipse.width / 2); circleMapObject.setName(mapObject.getName()); circleMapObject.getProperties().putAll(mapObject.getProperties()); circleMapObject.setColor(mapObject.getColor()); circleMapObject.setVisible(mapObject.isVisible()); circleMapObject.setOpacity(mapObject.getOpacity()); return createFixture(circleMapObject, body); } throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s that are not circles are not supported"); } else if (mapObject instanceof TextureMapObject) throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because " + mapObject.getClass().getSimpleName() + "s are not supported"); else assert false : mapObject + " is a not known subclass of " + MapObject.class.getName(); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; assignProperties(fixtureDef, heritage); assignProperties(fixtureDef, mapProperties); assignProperties(fixtureDef, layerProperties); assignProperties(fixtureDef, properties); Fixture fixture = body.createFixture(fixtureDef); fixture.setUserData(getProperty(layerProperties, aliases.userData, fixture.getUserData())); fixture.setUserData(getProperty(properties, aliases.userData, fixture.getUserData())); shape.dispose(); fixtures.put(findAvailableName(mapObject.getName(), fixtures), fixture); return fixture; }
From source file:org.bladecoder.bladeengine.loader.ChapterXMLLoader.java
License:Apache License
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if (currentVerb != null) { parseAction(localName, atts, actor != null ? actor.getId() : null); } else if (currentDialog != null) { if (!localName.equals("option")) { SAXParseException e2 = new SAXParseException("Only 'option' tag allowed in dialogs", locator); error(e2);//www . j a v a 2 s . c o m throw e2; } String text = atts.getValue("text"); String responseText = atts.getValue("response_text"); String verb = atts.getValue("verb"); String next = atts.getValue("next"); if (verb != null && verb.trim().isEmpty()) verb = null; if (text == null || text.trim().isEmpty()) { SAXParseException e2 = new SAXParseException("'text' atribute mandatory for <option> tag", locator); error(e2); throw e2; } String visibleStr = atts.getValue("visible"); DialogOption o = new DialogOption(); o.setText(text); o.setResponseText(responseText); o.setVerbId(verb); o.setNext(next); o.setParent(currentOption); if (visibleStr != null && !visibleStr.trim().isEmpty()) { o.setVisible(Boolean.parseBoolean(visibleStr)); } currentOption = o; if (o.getParent() == null) currentDialog.addOption(o); else o.getParent().addOption(o); } else if (localName.equals("actor")) { String type = atts.getValue("type"); if (type == null || type.isEmpty()) { SAXParseException e2 = new SAXParseException("Actor 'type' attribute not found or empty", locator); error(e2); throw e2; } if (type.equals("background")) { actor = new Actor(); } else { actor = new SpriteActor(); if (type.equals("atlas") || type.equals("foreground")) { // ATLAS // ACTOR ((SpriteActor) actor).setRenderer(new AtlasRenderer()); } else if (type.equals("3d")) { // 3D ACTOR Sprite3DRenderer r = new Sprite3DRenderer(); ((SpriteActor) actor).setRenderer(r); Vector3 camPos, camRot; float fov = 67; try { Vector2 spriteSize = Param.parseVector2(atts.getValue("sprite_size")); spriteSize.x *= scale; spriteSize.y *= scale; r.setSpriteSize(spriteSize); if (atts.getValue("cam_pos") != null) { camPos = Param.parseVector3(atts.getValue("cam_pos")); r.setCameraPos(camPos.x, camPos.y, camPos.z); } if (atts.getValue("cam_rot") != null) { camRot = Param.parseVector3(atts.getValue("cam_rot")); r.setCameraRot(camRot.x, camRot.y, camRot.z); } fov = Float.parseFloat(atts.getValue("fov")); r.setCameraFOV(fov); if (atts.getValue("camera_name") != null) { r.setCameraName(atts.getValue("camera_name")); } } catch (Exception e) { SAXParseException e2 = new SAXParseException("Wrong sprite3d params", locator, e); error(e2); throw e2; } } else if (type.equals("spine")) { // SPINE RENDERER SpineRenderer r = new SpineRenderer(); ((SpriteActor) actor).setRenderer(r); } if (atts.getValue("walking_speed") != null && !atts.getValue("walking_speed").isEmpty()) { float s = Float.parseFloat(atts.getValue("walking_speed")) * scale; ((SpriteActor) actor).setWalkingSpeed(s); } initFrameAnimation = atts.getValue("init_frame_animation"); // PARSE DEPTH MAP USE String depthType = atts.getValue("depth_type"); ((SpriteActor) actor).setDepthType(DepthType.NONE); if (depthType != null && !depthType.isEmpty()) { if (depthType.equals("vector")) ((SpriteActor) actor).setDepthType(DepthType.VECTOR); } } // PARSE BBOX Polygon p = null; if (atts.getValue("bbox") != null) { try { p = Param.parsePolygon(atts.getValue("bbox")); p.setScale(scale, scale); } catch (NumberFormatException e) { SAXParseException e2 = new SAXParseException("Wrong Bounding Box Definition", locator, e); error(e2); throw e2; } actor.setBbox(p); } else if (type.equals("background")) { SAXParseException e2 = new SAXParseException("Bounding box definition not set for actor", locator); error(e2); throw e2; } else { p = new Polygon(); actor.setBbox(p); ((SpriteActor) actor).setBboxFromRenderer(true); } // PARSE POSTITION Vector2 pos = Param.parseVector2(atts.getValue("pos")); if (pos == null) { SAXParseException e2 = new SAXParseException("Wrong actor XML position", locator); error(e2); throw e2; } pos.x *= scale; pos.y *= scale; actor.setPosition(pos.x, pos.y); if (atts.getValue("interaction") != null) { boolean interaction = Boolean.parseBoolean(atts.getValue("interaction")); actor.setInteraction(interaction); } if (atts.getValue("visible") != null) { boolean visible = Boolean.parseBoolean(atts.getValue("visible")); actor.setVisible(visible); } if (atts.getValue("obstacle") != null) { boolean obstacle = Boolean.parseBoolean(atts.getValue("obstacle")); actor.setWalkObstacle(obstacle); } String id = atts.getValue("id"); String desc = atts.getValue("desc"); String state = atts.getValue("state"); if (id == null || id.isEmpty()) { SAXParseException e2 = new SAXParseException("Actor 'id' attribute not found or empty", locator); error(e2); throw e2; } actor.setId(id); if (desc != null) actor.setDesc(desc); if (state != null) actor.setState(state); if (type.equals("foreground")) { scene.addFgActor((SpriteActor) actor); } else { scene.addActor(actor); } } else if (localName.equals("frame_animation")) { if (actor == null || !(actor instanceof SpriteActor)) { SAXParseException e = new SAXParseException("'frame_animation' TAG must be inside sprite actors", locator); error(e); throw e; } String speedstr = atts.getValue("speed"); String animationTypestr = atts.getValue("animation_type"); String delaystr = atts.getValue("delay"); String countstr = atts.getValue("count"); String soundId = atts.getValue("sound"); String inDstr = atts.getValue("inD"); String outDstr = atts.getValue("outD"); String preloadstr = atts.getValue("preload"); String disposewhenplayedstr = atts.getValue("dispose_when_played"); float speed = 1f; float delay = 0f; int animationType; int count = Tween.INFINITY; Vector2 inD = null, outD = null; boolean preload = true; boolean disposeWhenPlayed = false; String id = atts.getValue("id"); if (id == null || id.isEmpty()) { SAXParseException e = new SAXParseException("Animation 'id' not found or empty", locator); error(e); throw e; } String source = atts.getValue("source"); if (source == null || source.isEmpty()) { SAXParseException e2 = new SAXParseException("Source name not found or empty", locator); error(e2); throw e2; } try { if (speedstr != null && !speedstr.isEmpty()) speed = Float.parseFloat(speedstr); if (delaystr != null && !delaystr.isEmpty()) delay = Float.parseFloat(delaystr); if (countstr != null && !countstr.isEmpty()) count = Integer.parseInt(countstr); if (preloadstr != null && !preloadstr.isEmpty()) preload = Boolean.parseBoolean(preloadstr); if (disposewhenplayedstr != null && !disposewhenplayedstr.isEmpty()) disposeWhenPlayed = Boolean.parseBoolean(disposewhenplayedstr); if (inDstr != null && !inDstr.isEmpty()) { inD = Param.parseVector2(inDstr); } if (outDstr != null && !outDstr.isEmpty()) { outD = Param.parseVector2(outDstr); } } catch (NumberFormatException e) { SAXParseException e2 = new SAXParseException("Wrong Sprite Animation parameters", locator, e); error(e2); throw e2; } if (animationTypestr == null || animationTypestr.isEmpty() || animationTypestr.equalsIgnoreCase("repeat")) { animationType = Tween.REPEAT; } else if (animationTypestr.equalsIgnoreCase("reverse")) { animationType = Tween.REVERSE; } else if (animationTypestr.equalsIgnoreCase("yoyo")) { animationType = Tween.PINGPONG; } else { animationType = Tween.NO_REPEAT; } AtlasFrameAnimation sa = new AtlasFrameAnimation(); sa.set(id, source, speed, delay, count, animationType, soundId, inD, outD, preload, disposeWhenPlayed); ((SpriteActor) actor).getRenderer().addFrameAnimation(sa); } else if (localName.equals("verb")) { parseVerb(localName, atts, actor != null ? actor.getVerbManager() : scene.getVerbManager()); } else if (localName.equals("dialog")) { String id = atts.getValue("id"); currentDialog = new Dialog(); currentDialog.setId(id); currentDialog.setActor(actor.getId()); currentOption = null; actor.addDialog(id, currentDialog); } else if (localName.equals("sound")) { parseSound(localName, atts, actor); } else if (localName.equals("chapter")) { initScene = atts.getValue("init_scene"); } else if (localName.equals("walk_zone")) { PolygonalNavGraph polygonalPathFinder = new PolygonalNavGraph(); Polygon poly = Param.parsePolygon(atts.getValue("polygon"), atts.getValue("pos")); poly.setScale(scale, scale); poly.setPosition(poly.getX() * scale, poly.getY() * scale); polygonalPathFinder.setWalkZone(poly); scene.setPolygonalNavGraph(polygonalPathFinder); } else if (localName.equals("obstacle")) { PolygonalNavGraph polygonalPathFinder = scene.getPolygonalNavGraph(); Polygon poly = Param.parsePolygon(atts.getValue("polygon"), atts.getValue("pos")); poly.setScale(scale, scale); poly.setPosition(poly.getX() * scale, poly.getY() * scale); polygonalPathFinder.addObstacle(poly); } else if (localName.equals("scene")) { this.scene = new Scene(); scenes.add(scene); if (initScene == null) initScene = this.scene.getId(); String idScn = atts.getValue("id"); String bgFilename = atts.getValue("background"); String lightmap = atts.getValue("lightmap"); String musicFilename = atts.getValue("music"); String loopMusicStr = atts.getValue("loop_music"); String initialMusicDelayStr = atts.getValue("initial_music_delay"); String repeatMusicDelayStr = atts.getValue("repeat_music_delay"); scene.setDepthVector(Param.parseVector2(atts.getValue("depth_vector"))); player = atts.getValue("player"); if (idScn == null || idScn.isEmpty()) { SAXParseException e2 = new SAXParseException("Scene 'id' not found or empty", locator); error(e2); throw e2; } scene.setId(idScn); scene.setBackground(bgFilename, lightmap); if (musicFilename != null) { boolean loopMusic = false; float initialDelay = 0; float repeatDelay = -1; if (loopMusicStr != null) loopMusic = Boolean.parseBoolean(loopMusicStr); if (initialMusicDelayStr != null) initialDelay = Float.parseFloat(initialMusicDelayStr); if (repeatMusicDelayStr != null) repeatDelay = Float.parseFloat(repeatMusicDelayStr); scene.setMusic(musicFilename, loopMusic, initialDelay, repeatDelay); } } else { // SAXParseException e = new SAXParseException("Wrong label '" // + localName + "' loading Scene.", locator); // error(e); // throw e; EngineLogger.error( "TAG not supported in Chapter document: " + localName + " LINE: " + locator.getLineNumber()); } }
From source file:org.bladecoder.bladeengine.polygonalpathfinder.PolygonalNavGraph.java
License:Apache License
@SuppressWarnings("unchecked") @Override/* w ww. ja v a 2 s. co m*/ public void read(Json json, JsonValue jsonData) { walkZone = json.readValue("walkZone", Polygon.class, jsonData); obstacles = json.readValue("obstacles", ArrayList.class, Polygon.class, jsonData); for (Polygon poly : obstacles) { poly.setScale(EngineAssetManager.getInstance().getScale(), EngineAssetManager.getInstance().getScale()); poly.setPosition(poly.getX() * EngineAssetManager.getInstance().getScale(), poly.getY() * EngineAssetManager.getInstance().getScale()); } }
From source file:org.catrobat.catroid.content.Look.java
License:Open Source License
public Polygon[] getCurrentCollisionPolygon() { Polygon[] originalPolygons;// w w w.j av a 2 s . co m if (getLookData() == null) { originalPolygons = new Polygon[0]; } else { if (getLookData().getCollisionInformation().collisionPolygons == null) { getLookData().getCollisionInformation().loadOrCreateCollisionPolygon(); } originalPolygons = getLookData().getCollisionInformation().collisionPolygons; } Polygon[] transformedPolygons = new Polygon[originalPolygons.length]; for (int p = 0; p < transformedPolygons.length; p++) { Polygon poly = new Polygon(originalPolygons[p].getTransformedVertices()); poly.translate(getX(), getY()); poly.setRotation(getRotation()); poly.setScale(getScaleX(), getScaleY()); poly.setOrigin(getOriginX(), getOriginY()); transformedPolygons[p] = poly; } return transformedPolygons; }
From source file:pl.kotcrab.libgdx.util.Text.java
License:Apache License
private void calculateBoundingRectangle() { Polygon polygon = new Polygon(new float[] { 0, 0, textBounds.width, 0, textBounds.width, textBounds.height, 0, textBounds.height });/*w ww . j av a 2s . com*/ polygon.setPosition(gx, gy); polygon.setRotation(rotation); polygon.setScale(scaleX, scaleY); polygon.setOrigin(originX, originY); boundingRectangle = polygon.getBoundingRectangle(); }