Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Perimeter(int width, int height, Box2D box2d){
- halfwidth = width/2;
- halfheight = height/2;
- final Vector2[] perimeter = {
- new Vector2(t(-0.2255f,width),t( +0.0920f,height)),
- new Vector2(t(-0.0005f,width),t( -0.0097f,height)),
- new Vector2(t(+0.2244f,width),t( +0.0940f,height)),
- new Vector2(t(+0.2224f,width),t( +0.1200f,height)),
- new Vector2(t(+0.0016f,width),t( +0.2195f,height)),
- new Vector2(t(-0.2255f,width),t( +0.1158f,height))
- };
- ChainShape perimeterChain = new ChainShape();
- Vector2[] myV2 = new Vector2[perimeter.length];
- for(int i=0; i < perimeter.length; i++){
- myV2[i] = new Vector2(perimeter[i].x/PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT, perimeter[i].y/PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT);
- }
- perimeterChain.createChain(myV2);
- FixtureDef perimeterFixtureDef = new FixtureDef();
- Body perimeterChainBody;
- BodyDef mBodyDef = new BodyDef();
- mBodyDef.type = BodyType.StaticBody;
- perimeterChainBody = BOX2D.physicsWorld.createBody(mBodyDef);
- //problem is here... I can't seem to pull this string from contactListener
- perimeterChainBody.setUserData("perimeter");
- perimeterFixtureDef.shape = perimeterChain;
- perimeterChainBody.createFixture(perimeterFixtureDef);
- perimeterChain.dispose();
- }
- //This is how I'm trying to retrieve the string, this is called by the contact listener to identify my objects colliding
- String getRole(Fixture object)
- {
- State state;
- String role;
- if(object.getUserData() instanceof String)
- {
- return (String)object.getUserData();
- }
- if(object.getBody()==null)
- {
- role = "fixture without body";
- }
- if(object.getBody().getUserData() instanceof String)
- {
- role = (String)object.getUserData();
- }
- if(object.getBody().getUserData() instanceof State)
- {
- state = (State) object.getBody().getUserData();
- role = state.role;
- }
- else
- {
- role = "undefined";
- }
- return role;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement