같은 배우 (Box2D의) 많은 시간을, 그래서 저를 도와주세요 :(Libgdx : 나는이 libgdx와 초보자 그리고 난 배우와 몸을 연결하는 방법을 답을 찾고 몸
을 내가 코드를 다음 있습니다 :
/// CLASS ACTOR
public class MyActor extends Actor
{
Texture texture;
float actorX = 0, actorY = 0;
public boolean clicked = false;
public String id;
public MyActor(float x, float y, String id, String tekstura)
{
this.texture = new Texture(Gdx.files.internal(tekstura));
this.id = id;
actorX = x;
actorY = y;
setBounds(actorX, actorY, texture.getWidth(), texture.getHeight());
addListener(new InputListener()
{
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button)
{
MyActor co = ((MyActor) event.getTarget());
co.clicked = true;
System.out.println(co.id);
co.remove();
return true;
}
});
}
@Override
public void draw(SpriteBatch batch, float alpha)
{
batch.draw(texture, actorX, actorY);
}
}
/*....................
.......................
........................
..........................*/
//CREATING SIMPLE OBJECT
MyActor samolot1 = new MyActor(100, 300, "samolot1", "data/jet.png");
samolot1.setTouchable(Touchable.enabled);
stage.addActor(samolot1);
// //////////////// WORLD /////////////////////////////////////////////
// 1
BodyDef bodydef_mojapostac = new BodyDef();
bodydef_mojapostac.type = BodyType.DynamicBody;
bodydef_mojapostac.position.set(400, 100);
CircleShape shape_mojapostac = new CircleShape();
shape_mojapostac.setRadius(30);
FixtureDef fixturedef_mojapostac = new FixtureDef();
fixturedef_mojapostac.density = 0.1f;
fixturedef_mojapostac.friction = 0.8f;
fixturedef_mojapostac.restitution = 0.7f;
fixturedef_mojapostac.shape = shape_mojapostac;
Body BodyMojaPostac = world.createBody(bodydef_mojapostac);
BodyMojaPostac.createFixture(fixturedef_mojapostac);
BodyMojaPostac.setUserData(samolot1);
및
......
batch.begin();
world.getBodies(tmpBodies);
for (Body body : tmpBodies)
if (body.getUserData() != null)
{
System.out.println(body.getUserData());
MyActor dupa = (MyActor) body.getUserData();
batch.draw(dupa.texture, dupa.actorX, dupa.actorY);
}
batch.end();
.....
나는 스프라이트와 함께 몸을 연결할 수 있습니다하지만 난 방법을 배우 :(
다음 페이지를보고 싶을 수도 있습니다. https://gist.github.com/nooone/8363982 – noone