cocos2d-iphone

Check if drawn path/CGPath intersects itself in an iPhone game

爷,独闯天下 提交于 2020-01-02 05:34:10
问题 I have a path drawn in OpenGL ES. I can convert it to a CGPath if needed. How would I check if it intersects itself (If the user created a complete loop)? 回答1: Graham Cox has some very interesting thoughts on how to detect the intersection of a CGPathRef and a CGRect, which is similar to your problem and may be educational. The underlying problem is difficult, and most practical solutions are going to be approximations. You may also want to look at this SO article on CGPathRef intersection,

How to make a dynamic body static in Cocos2d v3.0 with Chipmunk

左心房为你撑大大i 提交于 2020-01-02 00:18:13
问题 I’m using Cocos2d v3 and want to change a body from dynamic to static after colliding with another body. At the moment I’ve got: -(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair static:(CCNode *)nodeA wildcard:(CCNode *)nodeB { _player.physicsBody.type = CCPhysicsBodyTypeStatic; } or -(BOOL)ccPhysicsCollisionPreSolve:(CCPhysicsCollisionPair *)pair static:(CCNode *)nodeA wildcard:(CCNode *)nodeB { _player.physicsBody.type = CCPhysicsBodyTypeStatic; return YES; } but neither

Hardware Volume buttons change in app volume

谁说胖子不能爱 提交于 2020-01-01 19:21:13
问题 So in my app i would like to change the in app volume leves for an alarm by the use of the hardware buttons but whenever i use the buttons to turn up or down the volume it ONLY changes the "ringer" volume wich does NOT effect my in app volume. Under Settings -> Sounds the "change with buttons" switch is ON and everything works fine if i turn it off but most users will want to have it on as well. So when im in my app i want the volume buttons to change the app volume not the ringer volume.

Distinguish between collision surface orientations in box2d

孤街浪徒 提交于 2020-01-01 19:16:25
问题 I've been working on an iOS project, using Cocos2D 1.0 and Box2D, and I've run into a bit of a problem. What I need to be able to do is determine the orientation of a surface my player has hit. For example, if we have a rectangular platform, and the player collides with it, I need to know whether the player has hit the left, right, top, or bottom face of it. ALL the objects in the game are square, and the ONLY one moving is the player. I'm currently using a b2ContactListener in Box2D (well,

[CALayer retain]: message sent to deallocated instance?

旧巷老猫 提交于 2020-01-01 14:26:00
问题 In my app when I am switching views, after about the 4th time I switch views I get a crash that says: *** -[CALayer retain]: message sent to deallocated instance 0x6c4ba0 I have NSZombieEnabled in Xcode and it points me to this line whenever it switches views: [self.view removeFromSuperview]; Also if I do a backtrace of the (gdb) it gives me this: #0 0x37dd68a0 in ___forwarding___ () #1 0x37d31680 in __forwarding_prep_0___ () #2 0x37d1d026 in CFRetain () #3 0x37d26bb2 in +[__NSArrayI __new::]

How can I test sprite collision in cocos2d?

瘦欲@ 提交于 2020-01-01 12:25:08
问题 How do I start to implement a class for sprite collision? 回答1: As Eric pointed out, CGRectIntersectsRect is the method to test two bounding rects for overlapping. Use the boundingBox method of the CCNode classes to get the correct bounding box for each sprite (or other node). See my answer here: Collision Detection in Cocos2d game? 回答2: I would look into b2ContactListener You can do some searches on that, and you'll easily get some results 回答3: You can also perform very simple collision

How do I properly use CCSpriteFrameCache and CCSpriteBatchNode?

谁说胖子不能爱 提交于 2020-01-01 09:06:07
问题 I do not understand what I do exactly when I add a CCSpriteFrameCache or CCSpriteBatchNode to my cocos2d application. Can somebody please explain the following points (it would be helpful if you could explain a few; please write the corresponding letter in front of your answer according to which question you are answering): [all questions imply the achievement of best performance and lowest memory-use] a) Is it crucial to create spritesheets for every single layer ? (For example: Menu - own

cocos2d dynamically changing animation speed with CCSpeed

风流意气都作罢 提交于 2020-01-01 06:56:18
问题 In a simple game, a character has a walking animation of around 15 frames. Based on the accelerometer is speed in either direction changes. I wanted the animation to speed up or slow down accordingly. I realize that once the animation is initialized, you can't change the delay speed, and instead you need to create a new animation. But since the speed changes almost constantly, if I kept reseting the animation, it would always be stuck on the same frame. Is there a way to find which frame an

Multiple Gestures for UIGestureRecognizers (iPhone, Cocos2d)

你离开我真会死。 提交于 2020-01-01 05:24:10
问题 I'm using Cocos2d to render a sprite, and UIGestureRecognizers to allow the user to Pan, Rotate and Scale the sprite. I've got each working in isolation using code like the following: UIPinchGestureRecognizer *pinchRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:layer action:@selector(handlePinchFrom:)] autorelease]; [viewController.view addGestureRecognizer:pinchRecognizer]; UIRotationGestureRecognizer *rotationRecognizer = [[[UIRotationGestureRecognizer alloc] initWithTarget

Color Changing Sprites Cocos2d

折月煮酒 提交于 2020-01-01 03:43:07
问题 I need my sprite to transition to one color to another and on and on... like blue tint then green then purple, but i cannot find any good actions for that and am wondering, should i use animations? or is there an incorporated action for this? 回答1: you can use CCTintTo action to change the color of the sprite [sprite runAction:[CCTintTo actionWithDuration:2 red:255 green:0 blue:0]]; 回答2: since i saw several questions about replacing pixel colours in sprites, and i did'nt see any good solution