当前位置: 首页>>代码示例>>Java>>正文


Java PolygonRegion类代码示例

本文整理汇总了Java中com.badlogic.gdx.graphics.g2d.PolygonRegion的典型用法代码示例。如果您正苦于以下问题:Java PolygonRegion类的具体用法?Java PolygonRegion怎么用?Java PolygonRegion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PolygonRegion类属于com.badlogic.gdx.graphics.g2d包,在下文中一共展示了PolygonRegion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getIntersectionPiece

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
/**
 * @param xCor left coordinate of intersection
 * @param yCor right coordinate of intersection
 * @return PolygonRegion of intersection piece which lies on intersection with coordinates xCor and yCor, null if no game piece lies on that space
 */
private PolygonRegion getIntersectionPiece(int xCor, int yCor) {

    for (PolygonRegion pr : villages) {
        float xV0 = pr.getVertices()[0];
        float yV0 = pr.getVertices()[1];

        float xPos = (xCor * BASE);
        float yPos = -1 * (yCor * LENGTH / 2);

        if (xV0 == xPos - PIECEBASE / 2.0 && yV0 == yPos - PIECEBASE / 2.0) {
            return pr;
        }
    }

    return null;
}
 
开发者ID:teobaranga,项目名称:Catan,代码行数:22,代码来源:SessionScreen.java

示例2: getEdgePiece

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
/**
 * @param xCorFirst  left coordinate of first intersection
 * @param yCorFirst  right coordinate of first intersection
 * @param xCorSecond left coordinate of second intersection
 * @param yCorSecond right coordinate of second intersection
 * @return PolygonRegion of edge piece which lies between (xCorFirst,yCorFirst) and (xCorSecond,yCorSecon), null if no game piece lies on that space
 */
private PolygonRegion getEdgePiece(int xCorFirst, int yCorFirst, int xCorSecond, int yCorSecond) {

    for (PolygonRegion pr : edgeUnits) {
        float xVM = pr.getVertices()[0];
        float yVM = pr.getVertices()[1];

        float xCorM = (float) (Math.min(xCorFirst, xCorSecond) + (Math.max(xCorFirst, xCorSecond) - Math.min(xCorFirst, xCorSecond)) / 2.0);
        float yCorM = (float) (Math.min(yCorFirst, yCorSecond) + (Math.max(yCorFirst, yCorSecond) - Math.min(yCorFirst, yCorSecond)) / 2.0);

        if (xVM == xCorM && yVM == yCorM) {
            return pr;
        }
    }
    return null;
}
 
开发者ID:teobaranga,项目名称:Catan,代码行数:23,代码来源:SessionScreen.java

示例3: draw

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
@Override
public void draw (Batch batch, float parentAlpha) {
    batch.end();

    Gdx.gl.glLineWidth(10);

    for (PolygonRegion region : polygonRegions) {

        this.batch.begin();
        this.batch.draw(region, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        this.batch.end();

        Polyline line = new Polyline(region.getVertices());
        line.setScale(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

        shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
        shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
        shapeRenderer.setColor(Color.BROWN);
        shapeRenderer.polyline(line.getTransformedVertices());
        shapeRenderer.end();
    }

    batch.begin();
}
 
开发者ID:cpppwner,项目名称:NoRiskNoFun,代码行数:25,代码来源:GameObjectMap.java

示例4: apply

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
protected int apply (float[] vertices, int vertexStartingIndex, AttributeOffsets offsets, int vertexSize) {
	final PolygonRegion region = this.region;
	final TextureRegion tRegion = region.getRegion();
	if (!sizeSet && region != null) {
		width = tRegion.getRegionWidth();
		height = tRegion.getRegionHeight();
	}

	float color = this.color;
	for (int i = 0, v = vertexStartingIndex + offsets.color0; i < numVertices; i++, v += vertexSize) {
		vertices[v] = color;
	}

	float[] textureCoords = region.getTextureCoords();
	for (int i = 0, v = vertexStartingIndex
		+ offsets.textureCoordinate0, n = textureCoords.length; i < n; i += 2, v += vertexSize) {
		vertices[v] = textureCoords[i];
		vertices[v + 1] = textureCoords[i + 1];
	}

	return 0; // handled by subclass
}
 
开发者ID:CypherCove,项目名称:gdx-cclibs,代码行数:23,代码来源:Poly.java

示例5: createCircleRegion

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
PolygonRegion createCircleRegion (float degrees) {
	final int steps = Math.abs((int)degrees);
	if (steps < 3) {
		return new PolygonRegion(new TextureRegion(emptyTexture), new float[0], new short[0]);
	}

	float[] vertecies = new float[steps * 2];
	vertecies[0] = 0;
	vertecies[1] = 0;

	for (int i = 2; i < (vertecies.length); i += 2) {
		float subDegrees = degrees * ((float)i - 2) / (vertecies.length - 4);
		vertecies[i] = (float)Math.cos(Math.toRadians(subDegrees));
		vertecies[i + 1] = (float)Math.sin(Math.toRadians(subDegrees));
	}

	short[] triangles = new short[(steps - 2) * 3];

	for (int i = 0; i < (steps - 2) * 3; i += 3) {
		triangles[i] = 0;
		triangles[i + 1] = (short)((i / 3) + 1);
		triangles[i + 2] = (short)((i / 3) + 2);
	}

	return new PolygonRegion(new TextureRegion(emptyTexture), vertecies, triangles);
}
 
开发者ID:Quexten,项目名称:RavTech,代码行数:27,代码来源:RemoteEditLoadingScreen.java

示例6: AssetManager

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
/** Creates a new AssetManager with all default loaders. */
public AssetManager (FileHandleResolver resolver) {
	setLoader(BitmapFont.class, new BitmapFontLoader(resolver));
	setLoader(Music.class, new MusicLoader(resolver));
	setLoader(Pixmap.class, new PixmapLoader(resolver));
	setLoader(Sound.class, new SoundLoader(resolver));
	setLoader(TextureAtlas.class, new TextureAtlasLoader(resolver));
	setLoader(Texture.class, new TextureLoader(resolver));
	setLoader(Skin.class, new SkinLoader(resolver));
	setLoader(ParticleEffect.class, new ParticleEffectLoader(resolver));
	setLoader(PolygonRegion.class, new PolygonRegionLoader(resolver));
	setLoader(I18NBundle.class, new I18NBundleLoader(resolver));
	setLoader(Model.class, ".g3dj", new G3dModelLoader(new JsonReader(), resolver));
	setLoader(Model.class, ".g3db", new G3dModelLoader(new UBJsonReader(), resolver));
	setLoader(Model.class, ".obj", new ObjLoader(resolver));
	executor = new AsyncExecutor(1);
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:18,代码来源:AssetManager.java

示例7: create

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
@Override
public void create () {
	texture = new Texture(Gdx.files.internal("data/tree.png"));

	PolygonRegionLoader loader = new PolygonRegionLoader();
	region = loader.load(new TextureRegion(texture), Gdx.files.internal("data/tree.psh"));

	// create a region from an arbitrary set of vertices (a triangle in this case)
	region2 = new PolygonRegion(new TextureRegion(texture), new float[] {0, 0, 100, 100, 0, 100}, new short[] {0, 1, 2});

	camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	camera.position.x = 0;
	camera.position.y = 0;

	batch = new PolygonSpriteBatch();
	debugRenderer = new PolygonRegionDebugRenderer();

	Gdx.input.setInputProcessor(this);
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:20,代码来源:PolygonRegionTest.java

示例8: removeVillage

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
/**
 * removes polygon of village at given coordinates from the board
 *
 * @param xCor left coordinate of intersection
 * @param yCor right coordinate of intersection
 * @return true if a village was removed from the board
 */
private boolean removeVillage(int xCor, int yCor) {
    PolygonRegion village = getIntersectionPiece(xCor, yCor);
    if (village != null) {
        villages.remove(village);
        return true;
    }
    return false;
}
 
开发者ID:teobaranga,项目名称:Catan,代码行数:16,代码来源:SessionScreen.java

示例9: updateIntersection

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
/**
 * renders the village with appropriate color and kind at the given position. If position is already occupied, the currently placed village will be removed and replaced
 *
 * @param position of intersection to update
 * @param color    of player who owns the new Village
 * @param kind     of new Village
 */
public void updateIntersection(CoordinatePair position, PlayerColor color, VillageKind kind) {

    int offsetX = position.getLeft();
    int offsetY = position.getRight();

    // Removes village on given coordinate
    removeVillage(offsetX, offsetY);

    PolygonRegion village = null;
    switch (kind) {
        case CITY:
            village = gamePieces.createCity(offsetX, offsetY, BASE, LENGTH, PIECEBASE, color);
            break;
        case SCIENCE_METROPOLIS:
            village = gamePieces.createMetropolis(offsetX, offsetY, BASE, LENGTH, PIECEBASE, kind);
            break;
        case SETTLEMENT:
            village = gamePieces.createSettlement(offsetX, offsetY, BASE, LENGTH, PIECEBASE, color);
            break;
        case TRADE_METROPOLIS:
            village = gamePieces.createMetropolis(offsetX, offsetY, BASE, LENGTH, PIECEBASE, kind);
            break;
        case POLITICS_METROPOLIS:
            village = gamePieces.createMetropolis(offsetX, offsetY, BASE, LENGTH, PIECEBASE, kind);
            break;
        default:
            break;
    }
    if (village != null)
        villages.add(village);
}
 
开发者ID:teobaranga,项目名称:Catan,代码行数:39,代码来源:SessionScreen.java

示例10: updateEdge

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
/**
 * renders the road with appropriate color and position. If edge is already occupied, it removes current edge piece and replaces it with this one
 *
 * @param firstCoordinate  end point of edge
 * @param secondCoordinate other end point of edge
 * @param kind             of new edge unit (SHIP or ROAD)
 * @param color            of player who owns the new edge unit
 */
public void updateEdge(CoordinatePair firstCoordinate, CoordinatePair secondCoordinate, EdgeUnitKind kind, PlayerColor color) {
    if (firstCoordinate == null || secondCoordinate == null) {
        return;
    }

    int xCorFirst = firstCoordinate.getLeft();
    int yCorFirst = firstCoordinate.getRight();
    int xCorSecond = secondCoordinate.getLeft();
    int yCorSecond = secondCoordinate.getRight();

    System.out.println("Road placed at " + firstCoordinate + " " + secondCoordinate);

    // removes edge on given coordinate
    removeEdgeUnit(xCorFirst, yCorFirst, xCorSecond, yCorSecond);

    PolygonRegion edgeUnit = null;
    switch (kind) {
        case ROAD:
            edgeUnit = gamePieces.createRoad(xCorFirst, yCorFirst, xCorSecond, yCorSecond, BASE, LENGTH, PIECEBASE, color);
            break;
        case SHIP:
            edgeUnit = gamePieces.createShip(xCorFirst, yCorFirst, xCorSecond, yCorSecond, BASE, LENGTH, PIECEBASE, color);
            break;
        default:
            break;
    }
    if (edgeUnit != null)
        edgeUnits.add(edgeUnit);
}
 
开发者ID:teobaranga,项目名称:Catan,代码行数:38,代码来源:SessionScreen.java

示例11: setRegionColor

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
/**
 * Re-color a given region
 * @param color New Color for the Region
 * @param region Region to re-color
 */
private void setRegionColor(Color color, AssetMap.Region region) {
    Pixmap pix = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    pix.setColor(color);
    pix.fill();

    Texture regionTexture = new Texture(pix);
    PolygonRegion polygonRegion = regionMap.get(region);
    polygonRegion.getRegion().setTexture(regionTexture);
}
 
开发者ID:cpppwner,项目名称:NoRiskNoFun,代码行数:15,代码来源:GameScene.java

示例12: initPolygonRegions

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
private void initPolygonRegions() {

        polygonRegions = new ArrayList<>(assetMap.getRegions().size());


        for (AssetMap.Region region : assetMap.getRegions()) {
            PolygonRegion polyReg = new PolygonRegion(new TextureRegion(texture),
                    region.getVertices(),
                    new EarClippingTriangulator().computeTriangles(region.getVertices()).toArray());

            regionMap.put(region, polyReg);
            regionNameMap.put(region.getName(), region);
            polygonRegions.add(polyReg);
        }
    }
 
开发者ID:cpppwner,项目名称:NoRiskNoFun,代码行数:16,代码来源:GameObjectMap.java

示例13: apply

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
@Override
protected int apply (float[] vertices, int vertexStartingIndex, AttributeOffsets offsets, int vertexSize) {
	super.apply(vertices, vertexStartingIndex, offsets, vertexSize);
	final PolygonRegion region = this.region;
	final TextureRegion tRegion = region.getRegion();

	final float originX = this.originX;
	final float originY = this.originY;
	final float scaleX = this.scaleX;
	final float scaleY = this.scaleY;
	final float[] regionVertices = region.getVertices();

	final float worldOriginX = x + originX;
	final float worldOriginY = y + originY;
	final float sX = width / tRegion.getRegionWidth();
	final float sY = height / tRegion.getRegionHeight();
	final float cos = MathUtils.cosDeg(rotation);
	final float sin = MathUtils.sinDeg(rotation);

	float fx, fy;
	for (int i = 0, v = vertexStartingIndex + offsets.position, n = regionVertices.length; i < n; i += 2, v += vertexSize) {
		fx = (regionVertices[i] * sX - originX) * scaleX;
		fy = (regionVertices[i + 1] * sY - originY) * scaleY;
		vertices[v] = cos * fx - sin * fy + worldOriginX;
		vertices[v + 1] = sin * fx + cos * fy + worldOriginY;
	}

	return numVertices;
}
 
开发者ID:CypherCove,项目名称:gdx-cclibs,代码行数:30,代码来源:Poly2D.java

示例14: drawHoldBeam

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
private void drawHoldBeam(Vector2 from, Vector2 to, float orgSize, float dstSize) {
    Vector2 delta = from.cpy().sub(to);

    float w = Math.max(orgSize, dstSize);
    float h = delta.len();

    float tw = holdBG.getRegionWidth();
    float th = holdBG.getRegionHeight();

    float factorScale = (tw / w) * 0.5f;
    float topFactor = Math.max(dstSize - orgSize, 0f) * factorScale;
    float botFactor = Math.max(orgSize - dstSize, 0f) * factorScale;

    float[] points = {
            topFactor,
            0f,

            botFactor,
            th,

            tw - botFactor,
            th,

            tw - topFactor,
            0f
    };

    PolygonRegion clamped = new PolygonRegion(holdBG, points, triangles);
    spriteBatch.draw(clamped, from.x - w * 0.5f, from.y, w * 0.5f, 0f, w, h, 1f, 1f, delta.angle() + 90);
}
 
开发者ID:kbz,项目名称:SSTrain,代码行数:31,代码来源:WorldRenderer.java

示例15: PolySpatial

import com.badlogic.gdx.graphics.g2d.PolygonRegion; //导入依赖的package包/类
public PolySpatial(PolygonRegion region, Body body, Color color)
{
	this(region,color);
	mBody = body;
	mTmp.set(mBody.getPosition());
	mSprite.setOrigin(0, 0);
}
 
开发者ID:tescott,项目名称:RubeLoader,代码行数:8,代码来源:PolySpatial.java


注:本文中的com.badlogic.gdx.graphics.g2d.PolygonRegion类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。