Advertisement
NoneyaBiznazz

Untitled

May 1st, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1.  void Perimeter(int width, int height, Box2D box2d){
  2.  
  3.         halfwidth = width/2;
  4.         halfheight = height/2;
  5.        
  6.         final Vector2[] perimeter = {
  7.    
  8.                
  9.                 new Vector2(t(-0.2255f,width),t( +0.0920f,height)),
  10.                 new Vector2(t(-0.0005f,width),t( -0.0097f,height)),
  11.                 new Vector2(t(+0.2244f,width),t( +0.0940f,height)),
  12.                 new Vector2(t(+0.2224f,width),t( +0.1200f,height)),
  13.                 new Vector2(t(+0.0016f,width),t( +0.2195f,height)),
  14.                 new Vector2(t(-0.2255f,width),t( +0.1158f,height))
  15.         }; 
  16.        
  17.        
  18.        
  19.        
  20.        
  21.         ChainShape perimeterChain = new ChainShape();
  22.         Vector2[] myV2 = new Vector2[perimeter.length];
  23.         for(int i=0; i < perimeter.length; i++){   
  24.             myV2[i] = new   Vector2(perimeter[i].x/PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT, perimeter[i].y/PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT);
  25.         }
  26.         perimeterChain.createChain(myV2);
  27.         FixtureDef perimeterFixtureDef = new FixtureDef();
  28.         Body perimeterChainBody;
  29.         BodyDef mBodyDef = new BodyDef();
  30.         mBodyDef.type = BodyType.StaticBody;
  31.         perimeterChainBody = BOX2D.physicsWorld.createBody(mBodyDef);
  32.  
  33. //problem is here... I can't seem to pull this string from contactListener
  34.         perimeterChainBody.setUserData("perimeter");
  35.  
  36.  
  37.  
  38.         perimeterFixtureDef.shape = perimeterChain;
  39.        
  40.         perimeterChainBody.createFixture(perimeterFixtureDef);
  41.         perimeterChain.dispose();
  42.    
  43.    
  44.    
  45.    
  46.    
  47.    
  48.     }
  49.  
  50.  
  51.  
  52. //This is how I'm trying to retrieve the string, this is called by the contact listener to identify my objects colliding
  53.  
  54.      
  55.      String getRole(Fixture object)
  56.      {
  57.          State state;
  58.          String role;
  59.          
  60.          
  61.          if(object.getUserData() instanceof String)
  62.          {
  63.              return (String)object.getUserData();
  64.          }
  65.          
  66.          
  67.          if(object.getBody()==null)
  68.          {
  69.              role = "fixture without body";
  70.          }
  71.          
  72.          
  73.          if(object.getBody().getUserData() instanceof String)
  74.          {
  75.              
  76.              role = (String)object.getUserData();
  77.          }
  78.          
  79.          if(object.getBody().getUserData() instanceof State)
  80.          {
  81.              
  82.             state = (State) object.getBody().getUserData();
  83.             role = state.role;
  84.          }
  85.          else
  86.          {
  87.              role = "undefined";
  88.          }
  89.          
  90.          
  91.              
  92.          return role;
  93.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement