2012-12-05 13 views
6

चल रहा है मेरे पास एक गेम चल रहा है, लेकिन यह यादृच्छिक रूप से stuttering रहा है। इससे मुझे लगता है कि जीसी चल रहा है। कोड देखने के बाद मुझे बहुत सारे GC_CONCURRENT संदेश दिखाई देते हैं, जैसे 4-5 सेकंड।LibGdx GC_Concurrent

12-04 22:14:22.018: D/dalvikvm(4757): GC_CONCURRENT freed 510K, 7% free 10139K/10823K, paused 4ms+6ms 
12-04 22:14:22.288: D/dalvikvm(4757): GC_CONCURRENT freed 497K, 7% free 10139K/10823K, paused 3ms+7ms 
12-04 22:14:22.558: D/dalvikvm(4757): GC_CONCURRENT freed 497K, 7% free 10139K/10823K, paused 3ms+6ms 
12-04 22:14:22.823: D/dalvikvm(4757): GC_CONCURRENT freed 497K, 7% free 10139K/10823K, paused 3ms+7ms 

Ive मेरी कक्षा रेंडर करने के लिए मेरी अपराधी संकुचित। मैं बस LibGdx सीख रहा हूं (यह मेरा पहला LibGdx ऐप है) और यह सोच रहा था कि कोई समस्या देख सकता है या नहीं।

public void render(){ 

    batch.begin(); 

    //Draw background 
    batch.draw(skin.getSprite("background_chapter"), 0+(SIDE_EDGE*scaleX), 0+(BOTTOM_EDGE*scaleY), CAMERA_WIDTH, CAMERA_HEIGHT); 

    //draw tiles 
    bIter = world.getBlocks().iterator(); 
    while(bIter.hasNext()){ 
     tile = bIter.next(); 

     switch(tile.getType()){ 
     case Values.ICE: 
      continue; 
     (many more cases...) 
     } 
     batch.draw(skin.getSprite(tr), tile.getPosition().x*scaleX, tile.getPosition().y*scaleY, tile.getBounds().width*scaleX, tile.getBounds().height*scaleY); 
    } 

    //put ice on top of other level elements, non mobile ice on bottom 
    bIter = world.getBlocks().iterator(); 
    while(bIter.hasNext()){ 
     tile = bIter.next(); 
     if(tile.getType() == Values.ICE && tile.getCollide() == false){ 
     batch.draw(skin.getSprite("ice"), tile.getPosition().x*scaleX, tile.getPosition().y*scaleY, tile.getBounds().width*scaleX, tile.getBounds().height*scaleY); 
     } 
    } 

      //mobile ice on top 
    bIter = world.getBlocks().iterator(); 
    while(bIter.hasNext()){ 
     tile = bIter.next(); 
     if(tile.getType() == Values.ICE && tile.getCollide() == true){ 
      batch.draw(skin.getSprite("ice"), tile.getPosition().x*scaleX, tile.getPosition().y*scaleY, tile.getBounds().width*scaleX, tile.getBounds().height*scaleY); 
     } 
    } 

    //pauly on top 
    batch.draw(skin.getSprite("pauly_moving"), pauly.getBounds().x*scaleX, pauly.getBounds().y*scaleY, pauly.getBounds().width*scaleX, pauly.getBounds().height*scaleY); 

    batch.draw(skin.getSprite("background_chapter"), 0+(SIDE_EDGE*scaleX), (9.6f*scaleY), CAMERA_WIDTH, 1*scaleY); 


    //draw UI elements 
    batch.draw(skin.getSprite("pause_menu_icon"), CAMERA_WIDTH-(SIDE_EDGE*scaleX), CAMERA_HEIGHT-(0.25f*scaleY), 1*scaleX, 1*scaleY); 
    batch.draw(skin.getSprite("restart_menu_icon"), SIDE_EDGE*scaleX, CAMERA_HEIGHT-(0.25f*scaleY), 1*scaleX, 1*scaleY); 

    font.draw(batch, "Moves: "+pauly.getCurrentMoves()+"/ "+world.getLevel().getMovesNeeded(), 2f*scaleX,10.1f*scaleY); 

    font.draw(batch, world.getLevel().getTitle(), 6f*scaleX,10.1f*scaleY); 
    //draws the FPS on screen 
    font.draw(batch, "FPS: "+(Gdx.graphics.getFramesPerSecond()), 12f*scaleX,10.1f*scaleY); 

    if(world.getState()==Values.PAUSED){ 
     batch.draw(skin.getSprite("pause_menu"), 0+(SIDE_EDGE*scaleX), 0+(BOTTOM_EDGE*scaleY), CAMERA_WIDTH, CAMERA_HEIGHT); 
     //Gdx.app.log("WorldRenderer", "Game Paused"); 
    } else if(world.getState()==Values.LOOSE){ 
     batch.draw(skin.getSprite("die_menu"), 0+(SIDE_EDGE*scaleX), 0+(BOTTOM_EDGE*scaleY), CAMERA_WIDTH, CAMERA_HEIGHT); 
     //Gdx.app.log("WorldRenderer", "Game Paused"); 
    } else if(world.getState()==Values.WIN){ 
     batch.draw(skin.getSprite("win_menu"), 0+(SIDE_EDGE*scaleX), 0+(BOTTOM_EDGE*scaleY), CAMERA_WIDTH, CAMERA_HEIGHT); 
     //Gdx.app.log("WorldRenderer", "Game Paused"); 
    } 

    batch.end(); 

} 

Ive ब्लॉक बंद टिप्पणी की कोशिश की और यह मैं जीसी कॉल कहीं भी प्राप्त है, हालांकि बीच में अधिक दिखाई देता है।

संपादित करें: उत्तर

जवाब नीचे मैं डी डी एम एस इस्तेमाल किया आवंटन को देखने के लिए का उपयोग करना। यह करीब 100 नई वस्तुओं एक दूसरे ... नाव [], बनावट क्षेत्र, स्प्राइट ... सभी

skin.getSprite("texture"); 

प्रत्येक कॉल एक नाव [], एक बनावट क्षेत्र बना रहा था के साथ जुड़े, और एक स्प्राइट बना रही थी । तो डीडीएमएस आवंटन के लिए धन्यवाद। समाधान यूल ने कन्स्ट्रक्टर फ़ंक्शन में स्प्राइट्स (फ़ील्ड्स) बनाकर कहा था, फिर उन्हें लाइन में कॉल करने का उपयोग करें।

तो यह ...

batch.draw(skin.getSprite("background_chapter"), 0+(SIDE_EDGE*scaleX), 0+(BOTTOM_EDGE*scaleY), CAMERA_WIDTH, CAMERA_HEIGHT); 

इस के लिए बदल दिया ...

//in constructor() 
background = skin.getSprite("background_chapter"); 

//in render() 
batch.draw(background, 0+(SIDE_EDGE*scaleX), 0+(BOTTOM_EDGE*scaleY), CAMERA_WIDTH, CAMERA_HEIGHT); 

अब कोई और अधिक जीसी कॉल, और खेल चिकनी चल रहा है।

धन्यवाद

+0

लूप के लिए अनुक्रमण के साथ इटरेटर्स को प्रतिस्थापित करने का प्रयास करें। –

+1

मुझे लगता है कि आपको उन 'skin.getSprite' को' create' पर ले जाना चाहिए। 'बनाएं' में स्प्राइट बनाएं और 'ऑनरेंडर' –

उत्तर

3

नीचे ट्रैक करने के लिए जहां विशिष्ट समस्याएं हैं डी डी एम एस आवंटन ट्रैकर उपकरण का उपयोग करें। (अपने एंड्रॉइड डिवाइस पर ऐप चलाएं, डीडीएमएस विंडो खोलें, आवंटन ट्रैकर टैब पर स्विच करें, "डिवाइस" टैब में अपनी प्रक्रिया का चयन करें, अपना गेम जायें, "ट्रैकिंग शुरू करें" पर क्लिक करें, दो सेकंड प्रतीक्षा करें, "आवंटन प्राप्त करें" पर क्लिक करें ", डेटा की तालिका को देखें। मुझे थ्रेड पर सॉर्टिंग मिलती है ID अन्य पृष्ठभूमि धागे से थ्रेड गतिविधि को अलग करने का एक अच्छा तरीका है।)

इटरेटर्स अस्थायी ऑब्जेक्ट्स बनाते हैं, इसलिए विशेष रूप से रेंडर लूप में, आपको स्पष्ट अनुक्रमण का उपयोग करना चाहिए ।

स्ट्रिंग concatenation भी अस्थायी वस्तुओं बनाता है।

शायद अन्य सूक्ष्म स्थानों की एक गुच्छा स्मृति आवंटित की जा रही है, लेकिन इसे समझने का सही तरीका सही उपकरण का उपयोग करना है।

+0

में ड्रा करें ऊपर दिए गए उत्तरों का उपयोग करके मैंने आवंटन देखने के लिए डीडीएमएस का उपयोग किया। यह लगभग 100 नई वस्तुओं को एक सेकंड बना रहा था ... फ्लोट [], बनावट क्षेत्र, sprite ... सभी के साथ जुड़े हुए हैं – user835692