LIBGDX ScissorStack示例? [英] LIBGDX ScissorStack Example?

查看:116
本文介绍了LIBGDX ScissorStack示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在Sprite单元周围创建战争迷雾风格的效果,并被告知剪裁钉可以胜任这项工作,但我不知道自己在做什么错...

I am looking to create a fog-of-war style effect around on sprite units and was told scissorstack would do the job but I can't figure out what i am doing wrong...

我已经建立了典型的libgdx.每个游戏角色都有一堂课.我想通过配置每个类来控制每个单元看到的距离".假设我要让MainPlayer具有战争迷雾5,但要使Pawn单位所在的方块周围有1个空间的战争迷雾.

I have the typical libgdx set up. I have a class for every Game Character. I would like to control 'how far out' each unit sees by configuring each class. So say I want MainPlayer with fog of war 5, but a Pawn unit to have a fog of war of 1 space around the tile the unit is located in.

我已经加载了精灵,tmx贴图和碰撞检测工作正常.现在,我只是不知道应该在哪里将剪裁代码放到Player类中/如何使它起作用.我还想知道雾周围可见瓷砖的坐标...

I have the sprite loaded, tmx map and collision detection working fine. Now I just can't figure out where I should put the scissorstack code in the Player class / how to get it working. I'd also like to know the coordinates of the visible tiles around the fog...

public class Player extends Sprite implements InputProcessor{
private Vector2 velocity = new Vector2();

public Player(Sprite sprite, TiledMapTileLayer collision layer){
super(sprite);
this.collisionLayer=collisionLayer;
}

public void draw(SpriteBatch spriteBatch){
update(Gdx.graphics.getDeltaTime());
super.draw(spriteBatch);
}

public Vector2 getVelocity() {
        return velocity;
    }

    public void setVelocity(Vector2 velocity) {
        this.velocity = velocity;
    }

    public float getSpeed() {
        return speed;
    }

    public void setSpeed(float speed) {
        this.speed = speed;
    }

    public float getGravity() {
        return gravity;
    }

    public void setGravity(float gravity) {
        this.gravity = gravity;
    }

    public TiledMapTileLayer getCollisionLayer() {
        return collisionLayer;
    }

    public void setCollisionLayer(TiledMapTileLayer collisionLayer) {
        this.collisionLayer = collisionLayer;
    }


    public boolean keyDown(int keycode){
        switch(keycode){
        case Keys.W:

            setY(getY()+1*50);//velocity.x=speed;
            break;
        case Keys.A:
            setX(getX()-1*50);//velocity.x=-speed;
            break;
        case Keys.D:
            setX(getX()+1*50);//velocity.x=speed;
            break;
        case Keys.S:
            setY(getY()-1*50);//velocity.y=-speed;
            break;
        }
        System.out.println(getX()/50+", "+getY()/50);   
            return true;
    }

    public boolean keyUp(int keycode){
        switch(keycode){
        case Keys.W:
            velocity.y=0;
            break;
        case Keys.A:
            velocity.x=0;
            break;
        case Keys.D:
            velocity.x=0;
            break;
        case Keys.S:
            velocity.y=0;
            break;

        }return true;

    }

    @Override
    public boolean keyTyped(char character) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean touchUp(int screenX, int screenY, int pointer, int button) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean touchDragged(int screenX, int screenY, int pointer) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean mouseMoved(int screenX, int screenY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean scrolled(int amount) {
        // TODO Auto-generated method stub
        return false;
    }





}




}

我尝试了以下操作:将一个小组隐藏在Actor之外范围

这是我在Player类的draw方法中尝试过的方法:

This is what i tried in the Player class' draw method:

    public void draw(SpriteBatch spriteBatch){
        update(Gdx.graphics.getDeltaTime());
Rectangle scissors = new Rectangle();
Rectangle clipBounds = new Rectangle(getX(),getY(),4*width,4*height);
ScissorStack.calculateScissors(camera, spriteBatch.getTransformMatrix(), clipBounds, scissors);
ScissorStack.pushScissors(scissors);
spriteBatch.draw(...);
spriteBatch.flush();
ScissorStack.popScissors();

        super.draw(spriteBatch);
    }

我很困惑.在玩家实体类中使用ussnacktack的示例可能会有所帮助.谢谢

I am beyond confused. An example of usin scissorstack within the player entity class would be helpful. thanks

推荐答案

NathanSweet足以帮助我弄清楚如何使其工作(对于LibGdx 0.9.9): CalculateScissorss

NathanSweet was kind enough to help me out figuring out how to make it work (for LibGdx 0.9.9) a while back: CalculateScissors

因此,对于任何寻求示例的人来说,这段代码以前对我有用:

So for anyone looking for an example, this code has worked for me before:

Rectangle scissor = new Rectangle();
Rectangle clipBounds = new Rectangle(0, 0, worldW, worldH);

...

batch.begin();

...

ScissorStack.calculateScissors(camera, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), batch.getTransformMatrix(), clipBounds, scissor);
ScissorStack.pushScissors(scissor);

...

ScissorStack.popScissors();
batch.end();

您需要做的就是使用clipBounds的值,以产生所需的效果.

All you need is to play around with the clipBounds' values so the desired effect takes place.

这篇关于LIBGDX ScissorStack示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆