Box2D

2009-05-19 11 views
8

में एक रैपिंग दुनिया कैसे बनाएं I Box2D के साथ एक अंतहीन रैपिंग दुनिया बनाने की आवश्यकता है (जहां सभी ऑब्जेक्ट्स का एक्स समन्वय 0 < एक्स < 1000 (कहें) है। मैंने टेलीपोर्टिंग ऑब्जेक्ट्स के साथ कुछ और गेम खेले हैं लेकिन ऐसा लगता है कि एक बेहतर तरीका हो सकता है - कोई विचार? कोई ऑब्जेक्ट (या लिंक्ड ऑब्जेक्ट्स की श्रृंखला) में लगभग 50 से अधिक की एक्स अवधि होगी, उदाहरण के लिए स्क्रीन की चौड़ाई से कम।Box2D

कैमरा एक समय में दुनिया का केवल एक छोटा सा हिस्सा देख सकता है (लगभग 5% चौड़ाई, 100% ऊंचाई - दुनिया 1000 चौड़ाई से लगभग 30 ऊंची है)।

चीयर्स।

+1

क्या हम यहां फ्लैश में हैं? कृपया उपयुक्त भाषा टैग जोड़ें ताकि लोग प्रश्न आसानी से पा सकें। –

+0

बॉक्स 2 डी 2 डी गेम या सिमुलेशन के विकास के लिए ओपनजीएल बैकएंड के साथ एक सी ++ लाइब्रेरी है। –

+0

मैं वास्तव में सी # पोर्ट का उपयोग कर रहा हूं लेकिन मुझे नहीं लगता कि समाधान भाषा विशिष्ट होगा –

उत्तर

0

मैंने निम्नलिखित को लागू किया है, जो कि मेरे उद्देश्य के लिए आदर्श नहीं है बल्कि आदर्श है। इसमें कई सीमाएं शामिल हैं और यह सच लपेटने वाली दुनिया नहीं है लेकिन यह काफी अच्छी है।

public void Wrap() 
    { 
     float tp = 0; 

     float sx = ship.GetPosition().X;   // the player controls this ship object with the joypad 

     if (sx >= Landscape.LandscapeWidth())  // Landscape has overhang so camera can go beyond the end of the world a bit 
     { 
      tp = -Landscape.LandscapeWidth(); 
     } 
     else if (sx < 0) 
     { 
      tp = Landscape.LandscapeWidth(); 
     } 

     if (tp != 0) 
     { 
      ship.Teleport(tp, 0);     // telport the ship 

      foreach (Enemy e in enemies)   // Teleport everything else which is onscreen 
      { 
       if (!IsOffScreen(e.bodyAABB))  // using old AABB 
       { 
        e.Teleport(tp, 0); 
       } 
      } 
     } 

     foreach(Enemy e in enemies) 
     { 
      e.UpdateAABB();       // calc new AABB for this body 

      if (IsOffScreen(g.bodyAABB))   // camera has not been teleported yet, it's still looking at where the ship was 
      { 
       float x = e.GetPosition().X; 

       // everything which will come onto the screen next frame gets teleported closer to where the camera will be when it catches up with the ship 

       if (e.bodyAABB.UpperBound.X < 0 || e.bodyAABB.LowerBound.X + Landscape.LandscapeWidth() <= cameraPos.X + screenWidth) 
       { 
        e.Teleport(Landscape.LandscapeWidth(), 0); 
       } 
       else if (e.bodyAABB.LowerBound.X > Landscape.LandscapeWidth() || e.bodyAABB.UpperBound.X - Landscape.LandscapeWidth() >= cameraPos.X - screenWidth) 
       { 
        e.Teleport(-Landscape.LandscapeWidth(), 0); 
       } 
      } 
     } 
    } 
संबंधित मुद्दे