2016-12-17 1 views
0

나는 적의 거미를 만드는 데 사용할 수있는이 적 스파이더 클래스를 만들었습니다. 클래스는 거미를 만들지 만 움직이는 메서드를 호출하면 움직이지 않을 것입니다 ... 어떤 아이디어입니까? Map 클래스에서 move 메서드를 호출합니다. 본문과 스프라이트가 만들어졌지만 다시 어떤 이유로 이동하지 않습니다. 어떤 도움이라도 appretaited 것입니다.Box2d의 몸동기가 움직이지 않는다

public SpiderEnemy(World world, float xposition, float yposition) 
{ 
    bdef=new BodyDef(); 
    fdef=new FixtureDef(); 
    shape=new PolygonShape(); 

    xPosition=xposition; 
    yPosition=yposition; 
    texture=new Texture("spider.png"); 
    textureRegion=new TextureRegion[1]; 
    textureRegion[0]=new TextureRegion(texture,55,55,60,60); 
    HP=20; 
    HitDmg=10; 
    body=createBody(world); 
} 

public Body createBody(World world) 
{ 
    bdef.type=BodyDef.BodyType.KinematicBody; 
    bdef.position.set(xPosition+.5f,yPosition+.5f); 
    body=world.createBody(bdef); 
    shape.setAsBox(textureRegion[0].getRegionWidth()/Mango.PPM/10f,textureRegion[0].getRegionHeight()/Mango.PPM/10f); 
    fdef.shape=shape; 
    fdef.density=0; 
    body.createFixture(fdef); 
    fdef.filter.categoryBits=4; 
    circle=new CircleShape(); 
    fdef.shape=circle; 
    circle.setRadius(0.5f); 
    fdef.isSensor=true; 
    body.createFixture(fdef).setUserData("SpiderSensor"); 
    return body; 
} 

public void moveUp() 
{ 
    body.applyLinearImpulse(new Vector2(0,speed), body.getWorldCenter(), true); 
} 

public void moveDown() 
{ 
    System.out.println("MOVE"); 
    body.applyLinearImpulse(new Vector2(0,-speed), body.getWorldCenter(), true); 
} 

public void moveForward() 
{ 
    body.applyLinearImpulse(new Vector2(speed,0), body.getWorldCenter(), true); 
} 

public void moveBack() 
{ 
    body.applyLinearImpulse(new Vector2(-speed,0), body.getWorldCenter(), true); 
} 

public void stopMoving() 
{ 
    body.setLinearVelocity(0, 0); 
} 

public float GetHitDmg() 
{ 
    return HitDmg; 
} 

public void calculateHealth(float Dmg) 
{ 
    HP=HP-Dmg; 
} 

public float getHP() 
{ 
    return HP; 
} 

public void killed() 
{ 
    for(int i=0;i<textureRegion.length;i++) 
    { 
     textureRegion[i]=null; 
    } 
    fdef.isSensor=false; 
} 

public void killSpider(World world) 
{ 
    world.destroyBody(body); 
} 


public void draw(SpriteBatch batch) 
{ 
    if(textureRegion[0]!=null) 
    { 
     batch.draw(textureRegion[0], xPosition, yPosition,texture.getWidth()/Mango.PPM/2,texture.getHeight()/Mango.PPM/2); 
    } 
} 

답변

1

그나마 사용 body.applyLinearImpulse(new Vector2(-speed,0), body.getWorldCenter(), true);

사용 body.setLinearVelocity(0, -speed);

관련 문제