开发者

iOS Programming Best Practices - Help for Puzzle

I am creating a simple drag and drop puzzle for the iPad/iOS. Basically you can drag a sprite to a location and if it matches up then bingo, it matches. Like the kids animal puzzle games. Drag a chicken to the chicken but not a chicken to a cow.

Now, I set up the level and I h开发者_Python百科ave collision detection working on the puzzle pieces. I also have boundaries set up and accelerometer working to clear the game pieces.

My question is what route do I go for the empty slots? I was thinking of just adding them as sprites in set locations and then check if chicken piece collides with the chicken slot then bingo. But that seems inefficient since I will have to create a bunch of them.

Then I started thinking looping and using an 'empty piece' object. But then I still have to 'hard code' the locations of the empty slots.

I am using cocos2d and box2d right now and really just need to be pointed in the right direction. Is there a vertices editor that I should be using instead? Do I set up the sprites as sensors?

Thanks


If you create three empty slots, give an incremented z value to each.

int index = 0;

[self addChild:emptyPiece1 z:++index]
[self addChild:emptyPiece2 z:++index]
[self addChild:emptyPiece3 z:++index]

And then for your actual pieces, give an incremented z value to each.

[self addChild:puzzlePiece1 z:++index]
[self addChild:puzzlePiece2 z:++index]
[self addChild:puzzlePiece3 z:++index]

You can compare the z values at collision to see if the difference between the two is the correct difference (in this case 3).

Something like:

if (abs(obj1.z - obj2.z) == (index/2)) {}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜