2011-05-23 72 views
-2

總而言之參數2 ....不兼容的類型爲「CGRectContainsPoint」

我得到不兼容的類型爲「CGRectContainsPoint」參數2上的網格的[X] [Y] .frame部分([rubin1 frame],grid [x] [y] .frame),([rubin2 frame],grid [x] [y] .frame)和([rubin3 frame],grid [x] [y ]。幀)。我嘗試了[grid [x] [y] frame],但得到了同樣的錯誤。

我想能到我釋放他們在磚上來回走動魯賓1,對電網rubin2和rubin3。當我釋放他們的磚,然後我想這塊磚消失以及任何其他相同類型的磚是,魯賓的地方在左邊(無論身在何處,他們都在網格)

for (int y = 0; y < BRICKHEIGHT; y++) 
{ 
    for (int x = 0; x < BRICKWIDTH; x++) 
    { 


     if (CGRectContainsPoint([rubin1 frame], grid[x][y].frame)) { 

      if(grid[x][y].tag == 1){ 

       ruby--; 
       rubin1.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 2){ 

       ruby--; 
       rubin1.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 3){ 

       ruby--; 
       rubin1.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 4){ 

       ruby--; 
       rubin1.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 5){ 

       ruby--; 
       rubin1.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 6){ 

       ruby--; 
       rubin1.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 


     } 
     if (CGRectContainsPoint([rubin2 frame], grid[x][y].frame)) { 

      if(grid[x][y].tag == 1){ 

       ruby--; 
       rubin2.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 2){ 

       ruby--; 
       rubin2.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 3){ 

       ruby--; 
       rubin2.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 4){ 

       ruby--; 
       rubin2.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 5){ 

       ruby--; 
       rubin2.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 6){ 

       ruby--; 
       rubin2.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 

     } 
     if (CGRectContainsPoint([rubin3 frame], grid[x][y].frame)) { 

      if(grid[x][y].tag == 1){ 

       ruby--; 
       rubin3.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 2){ 

       ruby--; 
       rubin3.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 3){ 

       ruby--; 
       rubin3.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 4){ 

       ruby--; 
       rubin3.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 5){ 

       ruby--; 
       rubin3.alpha = 0; 
       grid[x][y].alpha = 0; 
       [self PlayerScore: x y: y]; 

      } 
      else if(grid[x][y].tag == 6){ 

       ruby--; 
       rubin3.alpha = 0; 
       grid[x][y].alpha = 0; 





      } 
     } 
    } 
} 

回答

0

它期望一個點作爲第二個參數而不是CGRect框架。嘗試grid [x] [y] .frame.origin。原點爲您提供了框架CGRect的右上角,並且調整了CGRect的寬度/高度。

+0

感謝您的意見:) – iphonedevonthemake 2011-05-23 06:28:02

+0

再次嘿!我意識到我做錯了方式..這就是爲什麼它不工作...我用CGRectContainsPoint而不是使用CGRectIntersectsRect。它現在工作正常。感謝所有幫助 – iphonedevonthemake 2011-05-25 04:01:02

0

你必須這樣使用。例如:

UITouch *touch = [touches anyObject]; 
CGPoint location = [touch locationInView:touch.view]; 

if(CGRectContainsPoint(myimage.frame, location) == 0){ 
//always end up here 
} 
+0

這是一個很好的觀點,除了確保引用CGPoint而不是CGRect之外 - 還需要確保該點位於正確的座標空間中。我實際上會推薦使用[touch locationInView:[grid [x] [y] superview]];這將比較觸點與網格物品容器的座標空間。 – 2011-05-23 05:24:43

+0

我明白了......感謝您的建議。我今晚會試一試,並告訴你結果如何:)順便問一下,我怎樣才能得到剩下的代碼來移除網格上所有與我放置的類型相同的磚塊rubin或者你展示給我的例子是否也在做這件事? – iphonedevonthemake 2011-05-23 06:27:39

+0

再次嘿!我意識到我做錯了方式..這就是爲什麼它不工作...我用CGRectContainsPoint而不是使用CGRectIntersectsRect。它現在工作正常。感謝所有的幫助 – iphonedevonthemake 2011-05-25 04:00:54