Java 类com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch 实例源码

项目:cocos2d-java    文件:Sprite.java   
@Override
public void onCommand(PolygonSpriteBatch batch) {
    if(_shaderProgram == null) {
        ShaderProgram p = GLProgramCache.getInstance().getSpriteBatchDefaultProgram();
        if(batch.getShader() != p) {
            batch.setShader(null);
        }
    } else {
        if(batch.getShader() != _shaderProgram) {
            batch.setShader(_shaderProgram);
        }
    }
    if(_sprite.getTexture() != null) {
        _sprite.draw(batch);
    }
}
项目:NoRiskNoFun    文件:GameObjectMap.java   
GameObjectMap(AssetMap assetMap) {

        this.assetMap = assetMap;
        batch = new PolygonSpriteBatch();
        shapeRenderer = new ShapeRenderer();

        Pixmap pix = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
        pix.setColor(Color.WHITE);
        pix.fill();
        texture = new Texture(pix);

        regionMap = new HashMap<>();
        regionNameMap = new HashMap<>();

        initPolygonRegions();
    }
项目:water2d-libgdx    文件:Water.java   
/**
 * Constructor that allows to specify if there is an effect of waves and splash particles.
 * @param waves Specifies whether the object will have waves
 * @param splashParticles Specifies whether the object will have splash particles
 */
public Water(boolean waves, boolean splashParticles) {

    this.waves = waves;
    this.splashParticles = splashParticles;
    this.fixturePairs = new HashSet<Pair<Fixture, Fixture>>();
    this.setDebugMode(false);

    if (waves) {
        textureWater = new TextureRegion(new Texture(Gdx.files.internal("water.png")));
        polyBatch = new PolygonSpriteBatch();
    }

    if (splashParticles) {
        textureDrop = new Texture(Gdx.files.internal("drop.png"));
        spriteBatch = new SpriteBatch();
        particles = new ArrayList<Particle>();
    }

    shapeBatch = new ShapeRenderer();
    shapeBatch.setColor(0, 0.5f, 1, 1);
}
项目:fabulae    文件:UsableGameObject.java   
@Override
public void draw(GameMapRenderer renderer, float deltaTime) {
    super.draw(renderer, deltaTime);
    if (!hasSprite()) {
        PlayerCharacterController controller = gameState.getPlayerCharacterController();
        Tool activeTool = controller.getActiveTool();

        PolygonSpriteBatch spriteBatch = renderer.getSpriteBatch();
        int src = spriteBatch.getBlendSrcFunc();
        int dst = spriteBatch.getBlendDstFunc();
        if (src != GL20.GL_SRC_ALPHA || dst != GL20.GL_ONE) {
            spriteBatch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
        }
        spriteBatch.setColor(isHovered() && activeTool == Tool.DISARM ? ColorUtil.GREEN_SEVENFIVE : ColorUtil.RED_SEVENFIVE);
        polygonRenderer.render(spriteBatch);
        if (src != GL20.GL_SRC_ALPHA || dst != GL20.GL_ONE) {
            spriteBatch.setBlendFunction(src, dst);
        }
    }
}
项目:RavTech    文件:RemoteEditLoadingScreen.java   
@Override
public void show () {
    font = new BitmapFont(Gdx.files.internal("fonts/font.fnt"));
    cache = font.getCache();

    if (Gdx.app.getType() == ApplicationType.Android)
        font.getData().setScale(2);
    polygonBatch = new PolygonSpriteBatch();
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    Pixmap pixMap = new Pixmap(1, 1, Format.RGB565);
    pixMap.setColor(Color.WHITE);
    pixMap.fill();
    emptyTexture = new Texture(pixMap);
    pixMap.dispose();
}
项目:libgdxcn    文件:PolygonRegionTest.java   
@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);
}
项目:libgdxcn    文件:PolygonSpriteTest.java   
@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"));

    renderer = new ShapeRenderer();

    camera = new OrthographicCamera(480, 320);
    camera.position.x = 240;
    camera.position.y = 160;
    camera.update();

    batch = new PolygonSpriteBatch();

    for (int i = 0; i < 50; i++) {
        PolygonSprite sprite = new PolygonSprite(region);
        sprite.setPosition(MathUtils.random(-30, 440), MathUtils.random(-30, 290));
        sprite.setColor(MathUtils.random(), MathUtils.random(), MathUtils.random(), 1.0f);
        sprite.setScale(MathUtils.random(0.5f, 1.5f), MathUtils.random(0.5f, 1.5f));
        sprites.add(sprite);
    }
}
项目:ead    文件:EditorApplicationListener.java   
protected Stage createStage() {
    batch = new PolygonSpriteBatch(2500) {
        final int MAX = 2500 * 5;

        @Override
        public void draw(Texture texture, float[] spriteVertices,
                int offset, int count) {
            while (count > MAX) {
                super.draw(texture, spriteVertices, offset, MAX);
                offset += MAX;
                count -= MAX;
            }
            super.draw(texture, spriteVertices, offset, count);
        }
    };
    return new Stage(new ScreenViewport(), batch);
}
项目:mini2Dx    文件:LibGdxGraphicsTest.java   
@Before
public void setup() {
    mockery = new Mockery();
    mockery.setImposteriser(ClassImposteriser.INSTANCE);
    gameWrapper = mockery.mock(GameWrapper.class);
    spriteBatch = mockery.mock(SpriteBatch.class);
    polygonSpriteBatch = mockery.mock(PolygonSpriteBatch.class);
    shapeRenderer = mockery.mock(ShapeRenderer.class);
    gdxGraphics = mockery.mock(com.badlogic.gdx.Graphics.class);
    Gdx.graphics = gdxGraphics;

    mockery.checking(new Expectations() {
        {
            one(gdxGraphics).getWidth();
            will(returnValue(800));
            one(gdxGraphics).getHeight();
            will(returnValue(600));
            one(spriteBatch).getColor();
            will(returnValue(null));
        }
    });

    graphics = new LibGdxGraphics(gameWrapper, spriteBatch, polygonSpriteBatch, shapeRenderer);
}
项目:cocos2d-java    文件:RenderCommand.java   
@Override
public void execute(Renderer render) {
    PolygonSpriteBatch batch = render.batch;
    if(!batch.isDrawing()) {
        batch.begin();
    }
    this._callback.onCommand(render.batch);
}
项目:cocos2d-java    文件:RenderCommand.java   
@Override
        public void execute(Renderer render) {
            PolygonSpriteBatch batch = render.batch;
            if(batch.isDrawing()) {
                batch.end();
            }
//          this._callback.onCommand(render.c);
        }
项目:cocos2d-java    文件:RenderCommand.java   
@Override
public void execute(Renderer render) {
    PolygonSpriteBatch batch = render.batch;
    if(batch.isDrawing()) {
        batch.end();
    }
    this._callback.onCommand();
}
项目:fabulae    文件:GameMapRenderer.java   
public GameMapRenderer(GameState gameState, GameMap map,
        PlayerCharacterController controller) {
    this.gameState = gameState;
    this.pcc = gameState.getPlayerCharacterController();
    this.pcg = GameState.getPlayerCharacterGroup();
    /*amplitudeWave = 0.5f;
    angleWave = 0;
    angleWaveSpeed = 1f;*/
    waterShader = WaterShader.createWaterShader();
    unitScaleX = map.getScaleX();
    unitScaleY = map.getScaleY();
    this.map = map;
    this.viewBounds = new Rectangle();
    this.spriteBatch = new PolygonSpriteBatch();
    this.controller = controller;
    textBatch = new SpriteBatch();
    textBatch.getProjectionMatrix().setToOrtho2D(0, 0,
            Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    combatPathRenderer = new CombatPathRenderer(controller);
    effectTargetRenderer = new EffectTargetRenderer(controller);
    shapeRenderer = new ShapeRenderer(100);
    cullingRectangle = new Rectangle();
    highlightedDrawables = new ObjectMap<Drawable, Color>();
    trapsToDraw = new ObjectMap<TrapLocation, FilledPolygonRenderer>(); 
    trapTiles = new Array<int[]>();
    normalColor = Color.toFloatBits(1f, 1f, 1f, 1f);
    fogColor = Color.toFloatBits(Configuration.getFogColor().r,
            Configuration.getFogColor().g, Configuration.getFogColor().b,
            1);
    frameBuffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    frameBufferTextureRegion = new TextureRegion();
}
项目:fabulae    文件:FilledPolygonRenderer.java   
public void render(PolygonSpriteBatch batch) {
    // lazy init of the polyReg to make sure the map is fully loaded
    if (polyReg == null) {
        setPolygon(polygon, map);
    }
    batch.draw(polyReg, 0, 0);
}
项目:SSTrain    文件:WorldRenderer.java   
public WorldRenderer(World world) {
    this.world = world;
    this.cam = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT);
    this.cam.position.set(0f, 0f, 0f);
    this.cam.update();
    spriteBatch = new PolygonSpriteBatch();
    renderer = new ShapeRenderer();
    layout = new GlyphLayout();
    loadTextures();
}
项目:SpaceRescueAndroid    文件:Terrain.java   
public Terrain(){
    random = new Random();
    shapeRenderer = new ShapeRenderer();
    speed = new Vector2(Commons.getInstance().backgroundSpeed);
    setPoints(new ArrayList<Vector2>());
    setTopPoints(new ArrayList<Vector2>());
    setPoints2(new ArrayList<Vector2>());
    setTopPoints2(new ArrayList<Vector2>());

    getPoints().add(new Vector2(0, Commons.getInstance().initialY));
    getPoints().add(new Vector2(Commons.getInstance().deviceWidth, Commons.getInstance().initialY));
    getTopPoints().add(new Vector2(0, Commons.getInstance().initialY + Commons.getInstance().wallsDifference));
    getTopPoints().add(new Vector2(Commons.getInstance().deviceWidth, Commons.getInstance().initialY + Commons.getInstance().wallsDifference));

    getPoints2().add(new Vector2(Commons.getInstance().deviceWidth, Commons.getInstance().initialY));
    getPoints2().add(new Vector2(Commons.getInstance().deviceWidth * 2, Commons.getInstance().initialY));
    getTopPoints2().add(new Vector2(Commons.getInstance().deviceWidth, Commons.getInstance().initialY + Commons.getInstance().wallsDifference));
    getTopPoints2().add(new Vector2(Commons.getInstance().deviceWidth * 2, Commons.getInstance().initialY + Commons.getInstance().wallsDifference));

    generateTerrain(1);
    generateTerrain(2);

    atlas = new TextureAtlas("terrain/textures/textures.pack.atlas");
    region = atlas.findRegion("terrain");
    batch = new PolygonSpriteBatch();

    updatePolygons();
}
项目:SIFTrain    文件:WorldRenderer.java   
public WorldRenderer(World world) {
    this.world = world;
    this.cam = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT);
    this.cam.position.set(0f, 0f, 0f);
    this.cam.update();
    spriteBatch = new PolygonSpriteBatch();
    renderer = new ShapeRenderer();
    layout = new GlyphLayout();
    loadTextures();
}
项目:vis-editor    文件:Editor.java   
@Override
public void create () {
    instance = this;

    Log.debug("Starting loading");

    try {
        GLFWIconSetter.newInstance().setIcon(Gdx.files.absolute(App.APP_FOLDER_PATH).child("cache/iconCache"),
                Gdx.files.internal("icon.ico"), Gdx.files.internal("icon.png"));
    } catch (IllegalStateException e) {
        Log.exception(e);
    }

    Assets.load();

    VisUI.load();
    VisUI.setDefaultTitleAlign(Align.center);
    Log.debug("VisUI " + VisUI.VERSION + " loaded");

    polygonSpriteBatch = new PolygonSpriteBatch();
    stage = createStage();
    Gdx.input.setInputProcessor(stage);

    uiRoot = new VisTable();
    uiRoot.setFillParent(true);

    stage.addActor(uiRoot);

    createUI();
    createModuleContainers();
    createModulesUI();

    Log.debug("Loading completed");

    if (experimentalSettings.isUIScale() || launchConfig.scaleUIEnabled) {
        stageViewport.setUnitsPerPixel(0.5f);
    }
}
项目:vis-editor    文件:SpineRenderSystem.java   
@Override
protected void initialize () {
    batch = renderBatchingSystem.getBatch();
    if (batch instanceof PolygonSpriteBatch) {
        skeletonRenderer = new SkeletonMeshRenderer();
    } else {
        skeletonRenderer = new SkeletonRenderer();
    }
}
项目:ead    文件:EngineApplicationListener.java   
/**
 * Creates a Stage as in {@link Stage#Stage()}, but using
 * {@link PolygonSpriteBatch} instead of {@link SpriteBatch}
 * 
 * PolygonSpriteBatch must be used for
 * {@link es.eucm.ead.engine.components.renderers.SpineActor} to work
 * properly.
 */
protected Stage createStage() {
    Viewport viewport = new ScalingViewport(Scaling.stretch,
            Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),
            new OrthographicCamera());
    PolygonSpriteBatch batch = new PolygonSpriteBatch();
    Stage newStage = new Stage(viewport, batch);
    return newStage;
}
项目:ead    文件:SpineActor.java   
@Override
public void draw(Batch batch, float parentAlpha) {
    skeleton.updateWorldTransform();
    /*
     * batch has to be casted to PolygonSpriteBatch as SkeletonRenderer has
     * two different draw methods: draw(Batch, Skeleton) and
     * draw(PolygonSpriteBatch, Skeleton).
     */
    skeletonRenderer.draw((PolygonSpriteBatch) batch, skeleton);
    bounds.update(skeleton, true);
}
项目:ead    文件:GeoTester.java   
@Override
public void create() {
    sb = new SpriteBatch();
    font = new BitmapFont();
    polyBatch = new PolygonSpriteBatch();
    shapeRenderer = new ShapeRenderer();

    Gdx.gl.glClearColor(1f, 1f, 1f, 1.0f);
}
项目:evilrain    文件:RainGame.java   
@Override
public void create() {
    TextureManager.reload();
    polyBatch = new PolygonSpriteBatch();
    shapeRenderer = new ShapeRenderer();

    TextureManager.getAtlas("pack.atlas");

    //setLevel("level1", false);
    setScreen(new SplashScreen());
    Gdx.gl.glClearColor(1, 1, 1, 1);
    TextureManager.setLinearFilter(SettingsManager.getSmoothTextureType());
}
项目:RubeLoader    文件:PolySpatial.java   
public void render(PolygonSpriteBatch batch, float delta) {
    if (mBody != null)
    {
        mTmp.set(mBody.getPosition());
        mSprite.setRotation(mBody.getAngle()*MathUtils.radiansToDegrees);
        mSprite.setPosition(mTmp.x, mTmp.y);
        mSprite.draw(batch);
    }
    else
    {
        mSprite.draw(batch);
    }
}
项目:RubeLoader    文件:PolySpatial.java   
public void render(PolygonSpriteBatch batch, float delta) {
    if (mBody != null)
    {
        mTmp.set(mBody.getPosition());
        mSprite.setRotation(mBody.getAngle()*MathUtils.radiansToDegrees);
        mSprite.setPosition(mTmp.x, mTmp.y);
        mSprite.draw(batch);
    }
    else
    {
        mSprite.draw(batch);
    }
}
项目:RubeLoader    文件:RubeLoaderTest.java   
@Override
public void create()
{
   float w = Gdx.graphics.getWidth();
   float h = Gdx.graphics.getHeight();

   mBitmapFont = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);

   Gdx.input.setInputProcessor(this);

   mCamPos = new Vector3();
   mCurrentPos = new Vector3();

   mCam = new OrthographicCamera(100, 100 * h / w);
   mCam.position.set(50, 50, 0);
   mCam.zoom = 1.8f;
   mCam.update();

   mTextCam = new OrthographicCamera(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
   mTextCam.position.set(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2,0);
   mTextCam.zoom = 1;
   mTextCam.update();

   mDebugRender = new Box2DDebugRenderer();

   mBatch = new SpriteBatch();
   mPolyBatch = new PolygonSpriteBatch();

   mTextureMap = new HashMap<String, Texture>();
   mTextureRegionMap = new HashMap<Texture, TextureRegion>();

   mState = mNextState = GAME_STATE.STARTING;
}
项目:mini2Dx    文件:GameWrapper.java   
protected Graphics createGraphicsContext() {
    SpriteBatch spriteBatch = new SpriteBatch();
    PolygonSpriteBatch polygonSpriteBatch = new PolygonSpriteBatch();
    ShapeRenderer shapeRenderer = new ShapeRenderer();

    return new LibGdxGraphics(this, spriteBatch, polygonSpriteBatch, shapeRenderer);
}
项目:mini2Dx    文件:LibGdxGraphics.java   
public LibGdxGraphics(GameWrapper gameWrapper, SpriteBatch spriteBatch, PolygonSpriteBatch polygonSpriteBatch, ShapeRenderer shapeRenderer) {
    super();
    this.gameWrapper = gameWrapper;
    this.spriteBatch = spriteBatch;
    this.shapeRenderer = shapeRenderer;
    this.polygonSpriteBatch = polygonSpriteBatch;

    this.windowWidth = Gdx.graphics.getWidth();
    this.windowHeight = Gdx.graphics.getHeight();

    defaultTint = spriteBatch.getColor();
    if (defaultTint != null) {
        font = new BitmapFont(true);
    }
    tint = defaultTint;

    lineHeight = 1;
    color = Color.WHITE;
    backgroundColor = Color.BLACK;
    colorTextureCache = new ShapeTextureCache();

    translationX = 0;
    translationY = 0;
    scaleX = 1f;
    scaleY = 1f;
    rotation = 0f;
    rotationX = 0f;
    rotationY = 0f;

    /* Create Ortho camera so that 0,0 is in top-left */
    camera = new OrthographicCamera();
}
项目:cocos2d-java    文件:Renderer.java   
public Renderer() {
    batch = new PolygonSpriteBatch(2000, GLProgramCache.getInstance().getSpriteBatchDefaultProgram());
    commandQueue = new Array<>(128);
    shapeCommandQueue = new Array<>(64);
    _director = Director.justInstance();
}
项目:jenjin    文件:SkeletonMeshRenderer.java   
@SuppressWarnings("null")
public void draw (PolygonSpriteBatch batch, Skeleton skeleton) {
    boolean premultipliedAlpha = this.premultipliedAlpha;
    BlendMode blendMode = null;

    float[] vertices = null;
    short[] triangles = null;
    Array<Slot> drawOrder = skeleton.drawOrder;
    for (int i = 0, n = drawOrder.size; i < n; i++) {
        Slot slot = drawOrder.get(i);
        Attachment attachment = slot.attachment;
        Texture texture = null;
        if (attachment instanceof RegionAttachment) {
            RegionAttachment region = (RegionAttachment)attachment;
            vertices = region.updateWorldVertices(slot, premultipliedAlpha);
            triangles = quadTriangles;
            texture = region.getRegion().getTexture();

        } else if (attachment instanceof MeshAttachment) {
            MeshAttachment mesh = (MeshAttachment)attachment;
            vertices = mesh.updateWorldVertices(slot, premultipliedAlpha);
            triangles = mesh.getTriangles();
            texture = mesh.getRegion().getTexture();

        } else if (attachment instanceof SkeletonAttachment) {
            Skeleton attachmentSkeleton = ((SkeletonAttachment)attachment).getSkeleton();
            if (attachmentSkeleton == null) continue;
            Bone bone = slot.getBone();
            Bone rootBone = attachmentSkeleton.getRootBone();
            float oldScaleX = rootBone.getScaleX();
            float oldScaleY = rootBone.getScaleY();
            float oldRotation = rootBone.getRotation();
            attachmentSkeleton.setPosition(bone.getWorldX(), bone.getWorldY());
            // rootBone.setScaleX(1 + bone.getWorldScaleX() - oldScaleX);
            // rootBone.setScaleY(1 + bone.getWorldScaleY() - oldScaleY);
            // Set shear.
            rootBone.setRotation(oldRotation + bone.getWorldRotationX());
            attachmentSkeleton.updateWorldTransform();

            draw(batch, attachmentSkeleton);

            attachmentSkeleton.setPosition(0, 0);
            rootBone.setScaleX(oldScaleX);
            rootBone.setScaleY(oldScaleY);
            rootBone.setRotation(oldRotation);
        }

        if (texture != null) {
            BlendMode slotBlendMode = slot.data.getBlendMode();
            if (slotBlendMode != blendMode) {
                blendMode = slotBlendMode;
                batch.setBlendFunction(blendMode.getSource(premultipliedAlpha), blendMode.getDest());
            }
            batch.draw(texture, vertices, 0, vertices.length, triangles, 0, triangles.length);
        }
    }
}
项目:fabulae    文件:GameMapRenderer.java   
public PolygonSpriteBatch getSpriteBatch() {
    return spriteBatch;
}
项目:fabulae    文件:GameCharacter.java   
private void drawPaperdoll(GameMapRenderer renderer, float deltaTime, int[] slots) {
    float stateTime = getAnimationStateTime();
    GameMap map = getMap();
    boolean loadIfRequired = !map.isDisposed();
    boolean isometric = map.isIsometric();
    float tileSizeX = map.getTileSizeX();
    float tileSizeY = map.getTileSizeY();
    float scaleX = getScaleX();
    float scaleY = getScaleY();
    PolygonSpriteBatch spriteBatch = renderer.getSpriteBatch();

    Vector2 projectedCoordinates = position.setVector2(MathUtil.getVector2());
    map.projectFromTiles(projectedCoordinates);
    float x = projectedCoordinates.x;
    float y = projectedCoordinates.y;
    MathUtil.freeVector2(projectedCoordinates);

    for (int i = 0; i < slots.length; ++i) {
        int key = slots[i];
        Animation animation = itemAnimations.get(key);
        ItemAnimationMap animations = itemAnimationMaps.get(key);
        if (animations == null) {
            continue;
        }
        if (animation == null) {
            animation = animations.getAnimation(s_state, s_orientation, loadIfRequired);
            if (animation != null) {
                itemAnimations.put(key, animation);
            } else {
                continue;
            }
        }

        Vector2 offset = animations.getMiddleOffset(s_state, s_orientation);
        float offsetX, offsetY;
        if (isometric) {
            offsetX = (-offset.x + tileSizeX) * scaleX;
            offsetY = -offset.y * scaleY;
        } else {
            offsetX = (-offset.x + tileSizeX / 2) * scaleX;
            offsetY = (-offset.y + tileSizeY / 2) * scaleY;
        }

        spriteBatch.draw(animation.getKeyFrame(stateTime), x+offsetX, y+offsetY, animation.getFrameWidth() * scaleX,
                animation.getFrameHeight() * scaleY);
    }
}
项目:libgdxjam    文件:RenderingSystem.java   
public RenderingSystem(Viewport viewport,
                       Rectangle cameraFocusRect,
                       Vector2 cameraTarget,
                       Stage stage,
                       World world,
                       RayHandler rayHandler) {
    super(Family.all(RootComponent.class, NodeComponent.class).get());

    logger.info("initialize");

    this.viewport = viewport;
    this.cameraFocusRect = cameraFocusRect;
    this.cameraTarget = cameraTarget;
    this.stage = stage;
    this.world = world;
    this.rayHandler = rayHandler;

    //batch = new SpriteBatch();
    batch = new PolygonSpriteBatch();

    shapeRenderer = new ShapeRenderer();

    boolean drawBodies = true;
    boolean drawJoints = true;
    boolean drawABBs = true;
    boolean drawInactiveBodies = true;
    boolean drawVelocities = true;
    boolean drawContacts = true;
    box2DRenderer = new Box2DDebugRenderer(
        drawBodies,
        drawJoints,
        drawABBs,
        drawInactiveBodies,
        drawVelocities,
        drawContacts
    );

    spineRenderer = new SkeletonRenderer();
    spineDebugRenderer = new SkeletonRendererDebug();

    renderable = Family.all(
        NodeComponent.class,
        TransformComponent.class,
        SizeComponent.class
    ).one(
        TextureComponent.class,
        ParticleComponent.class,
        SpineComponent.class
    ).get();

}
项目:vis-editor    文件:Editor.java   
public PolygonSpriteBatch getPolygonSpriteBatch () {
    return polygonSpriteBatch;
}
项目:vis-editor    文件:SpineEditorRenderSystem.java   
@Override
protected void process (int entityId) {
    VisSpine spine = spineCm.get(entityId);
    Transform transform = transformCm.get(entityId);
    Tint tint = tintCm.get(entityId);

    spine.state.update(world.delta);
    spine.state.apply(spine.skeleton); // Poses skeleton using current animations. This sets the bones' local SRT.
    spine.skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.
    skeletonRenderer.draw((PolygonSpriteBatch) batch, spine.skeleton); // Draw the skeleton images.

    if (transform.isDirty() || tint.isDirty()) {
        spine.updateValues(transform.getX(), transform.getY(), tint.getTint());
    }

    SpineBounds boundsComponent = boundsCm.get(entityId);

    if (boundsComponent.boundsRequested) {
        boundsComponent.boundsRequested = false;

        Array<Slot> slots = spineCm.get(entityId).skeleton.getSlots();
        boundsComponent.bounds = null;

        for (Slot slot : slots) {
            Attachment attachment = slot.getAttachment();
            if (attachment == null) continue;

            float[] vertices = null;
            if (attachment instanceof BoundingBoxAttachment)
                vertices = ((BoundingBoxAttachment) attachment).getVertices();
            if (attachment instanceof RegionAttachment)
                vertices = ((RegionAttachment) attachment).getWorldVertices();
            if (attachment instanceof MeshAttachment)
                vertices = ((MeshAttachment) attachment).getWorldVertices();
            if (attachment instanceof MeshAttachment)
                vertices = ((MeshAttachment) attachment).getWorldVertices();

            if (vertices == null) continue;

            float minX = vertices[0];
            float minY = vertices[1];
            float maxX = vertices[0];
            float maxY = vertices[1];

            for (int i = 5; i < vertices.length; i += 5) {
                minX = minX > vertices[i] ? vertices[i] : minX;
                minY = minY > vertices[i + 1] ? vertices[i + 1] : minY;
                maxX = maxX < vertices[i] ? vertices[i] : maxX;
                maxY = maxY < vertices[i + 1] ? vertices[i + 1] : maxY;
            }

            Rectangle partBounds = new Rectangle();
            partBounds.x = minX;
            partBounds.y = minY;
            partBounds.width = maxX - minX;
            partBounds.height = maxY - minY;

            if (boundsComponent.bounds == null)
                boundsComponent.bounds = partBounds;
            else
                boundsComponent.bounds.merge(partBounds);
        }
    }
}
项目:vis-editor    文件:SkeletonMeshRenderer.java   
@SuppressWarnings("null")
public void draw (PolygonSpriteBatch batch, Skeleton skeleton) {
    boolean premultipliedAlpha = this.premultipliedAlpha;

    float[] vertices = null;
    short[] triangles = null;
    Array<Slot> drawOrder = skeleton.drawOrder;
    for (int i = 0, n = drawOrder.size; i < n; i++) {
        Slot slot = drawOrder.get(i);
        Attachment attachment = slot.attachment;
        Texture texture = null;
        if (attachment instanceof RegionAttachment) {
            RegionAttachment region = (RegionAttachment)attachment;
            vertices = region.updateWorldVertices(slot, premultipliedAlpha);
            triangles = quadTriangles;
            texture = region.getRegion().getTexture();

        } else if (attachment instanceof MeshAttachment) {
            MeshAttachment mesh = (MeshAttachment)attachment;
            vertices = mesh.updateWorldVertices(slot, premultipliedAlpha);
            triangles = mesh.getTriangles();
            texture = mesh.getRegion().getTexture();

        } else if (attachment instanceof SkeletonAttachment) {
            Skeleton attachmentSkeleton = ((SkeletonAttachment)attachment).getSkeleton();
            if (attachmentSkeleton == null) continue;
            Bone bone = slot.getBone();
            Bone rootBone = attachmentSkeleton.getRootBone();
            float oldScaleX = rootBone.getScaleX();
            float oldScaleY = rootBone.getScaleY();
            float oldRotation = rootBone.getRotation();
            attachmentSkeleton.setPosition(skeleton.getX() + bone.getWorldX(), skeleton.getY() + bone.getWorldY());
            // rootBone.setScaleX(1 + bone.getWorldScaleX() - oldScaleX);
            // rootBone.setScaleY(1 + bone.getWorldScaleY() - oldScaleY);
            // Set shear.
            rootBone.setRotation(oldRotation + bone.getWorldRotationX());
            attachmentSkeleton.updateWorldTransform();

            draw(batch, attachmentSkeleton);

            attachmentSkeleton.setPosition(0, 0);
            rootBone.setScaleX(oldScaleX);
            rootBone.setScaleY(oldScaleY);
            rootBone.setRotation(oldRotation);
        }

        if (texture != null) {
            BlendMode blendMode = slot.data.getBlendMode();
            batch.setBlendFunction(blendMode.getSource(premultipliedAlpha), blendMode.getDest());
            batch.draw(texture, vertices, 0, vertices.length, triangles, 0, triangles.length);
        }
    }
}
项目:ead    文件:EngineStage.java   
public EngineStage(Viewport viewport, PolygonSpriteBatch batch) {
    super(viewport, batch);
}
项目:ead    文件:TexturedShapeEditor.java   
@Override
public void create() {
    super.create();

    executor = new AsyncExecutor(1);

    // create a string of generally-overlapping polygons, will draw in
    // blue
    GeoTester.randomPolys(3, 40, 80, new Vector2(100, 300), blue);
    float s = 10;
    Polygon p0 = new Polygon(new float[] {
            // north-west, low, north-east
            0, 3 * s, 0, 2 * s, 2 * s, 0, 3 * s, 0, 4.5f * s, 2 * s, 6 * s,
            0, 7 * s, 0, 9 * s, 2 * s, 9 * s, 3 * s,
            // north-east, high, north-west
            8 * s, 3 * s, 6.5f * s, 1 * s, 5 * s, 3 * s, 4 * s, 3 * s,
            2.5f * s, s, 1 * s, 3 * s });
    blue.add(p0);
    // merge them into a single polygon, will draw in red
    for (Polygon bp : blue) {
        GeometryUtils.merge(geo, bp);
    }
    Geometry collapsed = GeometryUtils.collapse(geo);
    Polygon p = GeometryUtils.jtsCoordsToGdx(collapsed.getCoordinates());
    red.add(p);

    triangles = GeometryUtils.triangulate(collapsed);
    Gdx.app.error("GeoTester", "ready to display triangles worth "
            + triangles.length + " vertices");

    // use the polygon to clip a randomly-generated texture
    textureSolid = new Texture(GeoTester.randomPixmap(100, 100, null),
            false);

    PolygonRegion polyReg = new PolygonRegion(new TextureRegion(
            textureSolid), p.getVertices(), triangles);
    poly = new PolygonSprite(polyReg);
    poly.setOrigin(p.getVertices()[0], p.getVertices()[1]);
    polyBatch = new PolygonSpriteBatch();

    // prepare rendering aids
    shapeRenderer = new ShapeRenderer();

    Gdx.input.setInputProcessor(this);
}
项目:cocos2d-java    文件:RenderCommand.java   
public void onCommand(PolygonSpriteBatch batch);