2012-02-03 32 views
-2

原諒我的無知,但我很難記住我在代碼中訪問的內容。我在我的代碼中究竟訪問了什麼?

if (pos.x < leftBorderLimit) 
{ 
pos.x = leftBorderLimit; 
playerVelocity = CGPointZero; 
} 

else if (pos.x > rightBorderLimit) 
{ 
pos.x = rightBorderLimit; 
playerVelocity = CGPointZero; 
} 

這就是我所知道的。我知道,當我做'playerVariable.x'(這是一個CGPoint變量),我正在訪問這個變量X軸,我可以做任何我想要的東西..但究竟發生了什麼,當我只是做'playerVelocity = ..... '和什麼時,我分配CGPointZero到它?

回答

1

playerVelocity必須是CGPoint,以便您可以表示速度的x和y分量。將CGPointZero指定爲playerVelocity將使x和y分量均爲0.

+0

好吧,有道理。如果我做了'playerVelocity.x = CGPointZero;' 那麼會只將X設置爲零,但是將Y留在任何位置..? – 2012-02-03 06:34:11

+0

不,'playerVelocity.x'只是CGPoint的x分量,它是一個CGFloat值(即浮點數)。如果你想把x分量設置爲0,你可以'playerVelocity.x = 0.0' – UIAdam 2012-02-03 06:35:58

+0

非常感謝。這就是我一直在尋找的。 – 2012-02-03 06:41:17

1

playerVelocity = CGPointZero;表示playerVelocity = CGPointMake(0,0);