2013-05-17 29 views
0

我有一個精靈(圖片),當它與另一個分數碰撞時應該增加10,相關的代碼在更新方法中給出,但代之以增加隨機。 這是我的代碼。如何增加cocos2d android中的分數當兩個精靈被刪除

public void update(float dt) 
{ 
    LinkedList<CCSprite> projectilesToDelete = new LinkedList<CCSprite>(); 
    for (CCSprite projectile : _projectiles) 
    { 
     CGRect projectileRect = CGRect.make(projectile.getPosition().x - (projectile.getContentSize().width/2.0f), 
              projectile.getPosition().y - (projectile.getContentSize().height/2.0f), 
              projectile.getContentSize().width, 
              projectile.getContentSize().height); 



     LinkedList<CCSprite> targetsToDelete = new LinkedList<CCSprite>(); 
     for (CCSprite target : _targets) 
     { 
      CGRect targetRect = CGRect.make(target.getPosition().x - (target.getContentSize().width), 
              target.getPosition().y - (target.getContentSize().height), 
              target.getContentSize().width, 
              target.getContentSize().height); 

      if (CGRect.intersects(projectileRect, targetRect)) 
       targetsToDelete.add(target); 
      myscore += 10; 
      showLabel(myscore); 


     } 

回答

3

,你需要這樣的

myscore += 10; 
updateTable(myscore); 
showLabel(myscore); 
addTarget(); 
1

你的分數增長應該是內部的,如果:

for (CCSprite target : _targets) 
{ 
    CGRect targetRect = CGRect.make(target.getPosition().x - (target.getContentSize().width), 
            target.getPosition().y - (target.getContentSize().height), 
            target.getContentSize().width, 
            target.getContentSize().height); 

    if (CGRect.intersects(projectileRect, targetRect)){ 
     targetsToDelete.add(target); 
     myscore += 10; 
     showLabel(myscore); 
    } 
} 
+0

感謝您的回覆,我已經把更新它由10增加myScore的後僅在「if」語句中使用它的代碼。 @頭髮 – samm

相關問題