0
A
回答
0
要檢查精靈相交另一個可以使用
CCSprite *sprite1, *sprite2;
if (CGRectIntersectRect(sprite1.boundingBox, sprite2.boundingBox)) {
// sprites are overlapping
}
這並沒有考慮到作爲旋轉計算將變得更加複雜。
如果要部署不重疊精靈的量我不明白,在這種情況下,一個公平的瑣碎方法如下:
CCNode *parent;
for (int i = 0; i < AMOUNT; ++i) {
CCSprite *sprite = [CCSprite spriteWith..];
bool isOk = false;
while (!isOk) {
sprite.position = ccp(...);
isOk = true;
for (CCSprite *sprite2 in parent) {
if (CGRectIntersectRect(sprite.boundingBox, sprite2.boundingBox)) {
isOk = false;
break;
}
}
}
0
您可以使用ArrayList來保存先前的精靈(太陽)位置,並可以申請檢查時要添加新的太陽
ArrayList<CGRect> sunArrayList=new ArrayList<CGRect>();
立即申請退房,當你產生屏幕上的新精靈(太陽)
boolean exist;// variable to check position already exist
do{
exist=false; //set at every loop starting new no generated not exist we have to check this below. if exist change it to true
//generate no
int xRandom=3;//apply your logic for random location x
int yRandom=5;//apply your logic for random location y
for(int i=0;i<sunArrayList.size();i++)
{
if(sunArrayList.get(i).contains(xRandom,yRandom))
{
exist=true;
}
}
if(exist==false)// means your generated location not exist
{
// add sun to screen with position xRandom,yRandom
//write code here to add sprite on screen (xRandom,yRandom)
///
CGSize sunSize=CGSize.make(width, height);
//CGSizeSunSize=sprite(sun) slicing size
CGPoint sunPos=new CGPoint();
sunPos.set(xRandom, yRandom);
CGRect randomLocationGeneratedSun=new CGRect(sunPos,sunSize);
sunArrayList.add(randomLocationGeneratedSun);
}
}while(exist)
相關問題
- 1. cocos2d精靈碰撞檢測包圍盒
- 2. cocos2d旋轉精靈碰撞檢測
- 3. 的cocos2d精靈碰撞
- 4. Android碰撞檢測精度
- 5. Cocos2D簡單碰撞檢測一個精靈,另一個精靈的子女
- 6. Cocos2D碰撞檢測
- 7. Cocos2D - 檢測碰撞
- 8. 如何檢測cocos2d中精靈的碰撞
- 9. cocos2d與父Sprite的兒童精靈碰撞檢測
- 10. XNA劍精靈碰撞檢測
- 11. 閱讀精靈,檢測碰撞
- 12. 碰撞檢測後顯示精靈
- 13. 檢測精靈之間的碰撞
- 14. Cocos2d,旋轉(透明)精靈碰撞
- 15. 精靈碰撞Andengine(Android)
- 16. 如何檢測精靈表的精靈幀的碰撞
- 17. 與精靈碰撞
- 18. cocos2d碰撞檢測問題
- 19. cocos2d中的碰撞檢測
- 20. 碰撞檢測Objective-C(cocos2d)
- 21. cocos2d sprite碰撞檢測
- 22. Cocos2d/Box2d CCRibbon碰撞檢測
- 23. cocos2d像素碰撞檢測
- 24. Box2d碰撞檢測(cocos2d)
- 25. cocos2d v3碰撞檢測
- 26. Box2d Cocos2d ContactListener檢測碰撞
- 27. Phaser P2碰撞殺死碰撞精靈
- 28. Swift遊戲碰撞檢測和物理 - 精靈和背景
- 29. Cocos2d:測試碰撞,說這兩個精靈總是相交
- 30. 碰撞檢測 - 地精XNA
我只有1個精靈,當我觸摸屏幕時,這個精靈會再次出現,但是具有不同的位置(例如,屏幕上會顯示2個「微笑的太陽」),所以我只想比較1個精靈只有1個精靈創造出來,但又一次又一次地用不同的姿勢加入。 – user1997570
然後它比這更簡單,因爲你不需要外部循環。 – Jack