Problem positioning CCSprite on top of other CCSprites when animating a screen?

In my application, I have a character who has legs, and I want to make it look like in my application that he is standing on top of another CCSprite when he moves around the screen (animation). Everything works perfectly. EXCLUDES that there is a slight positioning problem that I just can't understand! Let me explain the problem a little more, when the character is on top of CCSprite, it seems that the character moves up / down about 10 points at very fast intervals.

Does anyone know why this is happening?

Thank!

FINAL EDIT: I would like to thank you again for helping me with this. Firstly, I deleted all my other changes, as the message was too long, and if you need to reference the old changes for any reason, just look at my change history!

So, after about an hour of testing, I narrowed it down to one problem that you mentioned earlier, if instructions that check if a character and a piece of flooring collide, NOT , every iteration in the game loop is called when they SHOULD (how much they look in the user interface).

My cocosGameLoop log is outside and in front of all the collision detection code, but is still in loop.f

I also noticed a pattern in my NSLogs, as you can see below:

2012-05-27 17:00:54.791 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.811 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.825 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.841 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.858 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.874 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.891 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.908 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.924 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.928 App[2769:707] collisiontwo
2012-05-27 17:00:54.929 App[2769:707] two
2012-05-27 17:00:54.941 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.944 App[2769:707] collisiontwo
2012-05-27 17:00:54.945 App[2769:707] two
2012-05-27 17:00:54.958 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.974 App[2769:707] cocosGameLoop
2012-05-27 17:00:54.991 App[2769:707] cocosGameLoop
2012-05-27 17:00:55.008 App[2769:707] cocosGameLoop
2012-05-27 17:00:55.025 App[2769:707] cocosGameLoop
2012-05-27 17:00:55.043 App[2769:707] cocosGameLoop
2012-05-27 17:00:55.058 App[2769:707] cocosGameLoop
2012-05-27 17:00:55.076 App[2769:707] cocosGameLoop
2012-05-27 17:00:55.078 App[2769:707] collisiontwo
2012-05-27 17:00:55.078 App[2769:707] two
2012-05-27 17:00:55.091 App[2769:707] cocosGameLoop
2012-05-27 17:00:55.094 App[2769:707] collisiontwo

, , NSLog Y, , ( , cocosGameLoop NSLog ) , (), 14 Y . , 14 /.

, , , 14 ? , .. , ? , Box2D , Cocos2D.

, , , - , , , , 100% .

, , , , ! , :)

!

+5
1

, , - Some other tag collision checking before. :

else if ((spriteA.tag == 1 && spriteB.tag == 5) || (spriteB.tag == 1 && spriteA.tag == 5))
...
else if ((spriteA.tag == 6 && spriteB.tag == 1) || (spriteB.tag == 6 && spriteA.tag == 1))
...

. , , , - . , , , , A B, A B. , . , else if , ?

, , ( , , , - ..), . , CCSprite Cocos2d Box2D? ( , )? , Cocos2d, , , . CCSprite , , - (, , , ). , , , , . , , , , , , , . , / .

, . . , , , , . .

, , CCSprite, . , , , , , , , , , .

CCSprite , , , , . , , - ? , , . , , . , , . - , , , . , Cocos2D/Box2D , , , / .

, , - :

if (spriteA.position.x - spriteA.boundingBox.size.height*.5 <= spriteB.position.x + spriteB.boundingBox.size.height*.5)

if (spriteB.position.x - spriteB.boundingBox.size.height*.5 <= spriteA.position.x + spriteA.boundingBox.size.height*.5)

, , , ? , , , , . , 10 30, , 30 , , , .

, , , , , . - , /, , - :)

1

, - . , , , , Box2D.

, for, , , , , BOOL characterOnPlatform - YES . for ( - , , , ), , characterOnPlatfom == YES, , for. for loop - , .

. , , NO, , , , , .

2

, . , resetgravity? hasCollided (.. , )? , , ?

, - , , - , , , , - (, , , ..).

, , , , :

  • ​​ .
  • , , .
  • - (, , ).
  • ...

, , , , (, , , Box2D, , .

3

, , ! , , . , , , ( Cocos2D, ). , , , /. , , , . + - 1 , . , .

+3
source

All Articles