이미 텍스처 영역 그리기가 완료되었지만 텍스처 영역을 뒤집으려고 할 때 작동하지 않고 여러 프레임을 그릴 때도 작동하지 않습니다. 내가 가져 오기 프레임 방법 내 몸의 속도를 확인하려하지만이 코드를 사용할 때 나에게 공을 준다 :Libgdx 텍스처 영역이 바뀌지 않습니다
Gdx.app.log(String.valueOf(b2body.getLinearVelocity().x),"hi");
이 사람이 나를 도울 수 있습니다.
public class Collector extends Sprite {
public enum State{STANDING,RUNNING,DEAD};
public State currentState;
public State previousState;
public World world;
public Body b2body;
private TextureRegion collectorStand;
private Animation collectorRun;
private float stateTimer;
private boolean runningRight;
public Collector(World world,PlayScreen screen)
{
super(screen.getAtlas().findRegion("myboy1"));
this.world=world;
currentState=State.STANDING;
previousState=State.STANDING;
stateTimer=0;
runningRight=true;
Array<TextureRegion> frames=new Array<TextureRegion>();
for(int i=0;i<3;i++)
frames.add(new TextureRegion(getTexture(),i*90,122,90,300));
//frames.add(new TextureRegion(getTexture(),90,122,110,300));
//frames.add(new TextureRegion(getTexture(),200,122,110,300));
collectorRun=new Animation(0.1f,frames);
frames.clear();
collectorStand=new TextureRegion(getTexture(), 0, 122, 89, 300);
//collectorStand=new TextureRegion(getTexture(),90,122,110,300);
//collectorStand=new TextureRegion(getTexture(),200,122,110,300);
defineCollector();
setBounds(0,0,50/Fruits.PPM,100/Fruits.PPM);//here we can change the size of our Animation
setRegion(collectorStand);
}
public TextureRegion myregion(float dt)
{
TextureRegion region;
region=collectorStand;
Gdx.app.log(String.valueOf(b2body.getLinearVelocity().x),"hi");
if(b2body.getLinearVelocity().x<0)
{
region.flip(true,false);
}
return region;
}
public void update(float dt)
{
setPosition(b2body.getPosition().x - getWidth()/2, b2body.getPosition().y - getHeight()/2.8f);
//setRegion(myregion(dt));
setRegion(getFrame(dt));
}
public TextureRegion getFrame(float dt)// return the appropriate frames for the sprite to be drawn
{
currentState=getState();
TextureRegion region;
switch (currentState)
{
case RUNNING:
region=collectorRun.getKeyFrame(stateTimer,true);
break;
case STANDING:
default:
region=collectorStand;
break;
}
Gdx.app.log(String.valueOf(b2body.getLinearVelocity().x),"hi");
if((b2body.getLinearVelocity().x<0 || !runningRight)&& !region.isFlipX())
{
region.flip(true,false);
runningRight=false;
}
else if((b2body.getLinearVelocity().x>0 || runningRight)&& region.isFlipX())
{
region.flip(true,false);
runningRight=true;
}
stateTimer=currentState==previousState?stateTimer+dt:0;
previousState=currentState;
return region;
}
public State getState()
{
if(b2body.getLinearVelocity().x!=0)
return State.RUNNING;
else
return State.STANDING;
}
public void defineCollector()
{
BodyDef bdef=new BodyDef();
bdef.position.set(72/Fruits.PPM,32/Fruits.PPM);
bdef.type=BodyDef.BodyType.DynamicBody;
b2body=world.createBody(bdef);
FixtureDef fdef=new FixtureDef();
//PolygonShape shape=new PolygonShape();
CircleShape shape=new CircleShape();
shape.setRadius(20/Fruits.PPM);
fdef.shape=shape;
b2body.createFixture(fdef);
}
}
정말 한 번만 넘겨 씁니까? 텍스처 영역은 해당 영역을 사용하고있는 모든 오브젝트에서 잃어버린 텍스처의 영역입니다. – Madmenyo