cocos2d-iphone

What is CCARRAY_FOREACH in coccos2d?

不问归期 提交于 2019-12-23 09:11:19
问题 I see a macro CCARRAY_FOREACH in coccos2d, actually what does it? can we do alternative solution instead of it?i am using following code for spriteBatchNode? CCARRAY_FOREACH([spriteBatch children], sprite) { ................... } 回答1: it is a macro for looping through each object inside a CCArray... an alternative would be objective-c's foreach for (object in array) that goes like this: for (CCSprite *sprite in [spriteBatch children]) { ... } this is for NSArray and NSMutableArray but i think

Features of use @property and @synthesize (cocos2d)

喜欢而已 提交于 2019-12-23 06:13:24
问题 I saw in the libraries for use cocos2d strange @property and @synthesize Standard in the examples is written as follows: in .h CGFloat minimumTouchLengthToSlide; } @property(readwrite, assign) CGFloat minimumTouchLengthToSlide; in .m @synthesize minimumTouchLengthToSlide But in lib https://github.com/cocos2d/cocos2d-iphone-extensions/tree/master/Extensions/CCScrollLayer and another libs\extensions in .h CGFloat minimumTouchLengthToSlide_; } @property(readwrite, assign) CGFloat

How to get Angle of velocity to rotate a bullet?

点点圈 提交于 2019-12-23 06:00:09
问题 I have this: CGPoint vel = hudLayer.rightJoystick.velocity; CCBullet* sp = [CCBullet spriteWithFile:@"green.png"]; sp.position = player.position; [self addChild:sp z:-10]; vel = ccpMult(ccpNormalize(vel), 300); sp.rotation = //how to get the rotation out of the velocity? Any help? 回答1: float angle = atan2f(vel.y, vel.x); 来源: https://stackoverflow.com/questions/5729221/how-to-get-angle-of-velocity-to-rotate-a-bullet

GlView causes OpenGL error

…衆ロ難τιáo~ 提交于 2019-12-23 05:30:23
问题 I am new in cocos2d.I am making a gaming with uiview with cocos2d(3.0 Beta) platform.I set a GLView in custom viewcontroller. Below is my code. - (void)setupCocos2D { CCGLView *glView = [CCGLView viewWithFrame:self.view.bounds pixelFormat:kEAGLColorFormatRGB565 depthFormat:0];** glView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self.view insertSubview:glView atIndex:0]; [[CCDirector sharedDirector] setView:glView];** } It's working fine.But when we

iOS and Cocos2d - Changing CCSprite's image AND new dimensions = FAIL

房东的猫 提交于 2019-12-23 05:27:59
问题 One of the powerups in my game is a decrease in size of the main sprite. So for memory sake, instead of looping a sprite.scale through each frame, I resaved the sprite at a percentage size lower than the original sprite, and just wish to replace it. Then once "death" occurs or timer runs out, the original sprite returns. So, I am using this code for making it small: [player setTexture:[[CCTextureCache sharedTextureCache] addImage:@"player-small.png"]]; and this code for resetting back to

Multiple screen resolution support in cocos2d v3?

左心房为你撑大大i 提交于 2019-12-23 05:01:35
问题 I am little confused with cocos2d v3's support for multiple screen resolutions. If I use CCSetupScreenMode: CCScreenModeFlexible , what should be the default resolution of the image that I provide? Currently, I have provided assets for all the iOS device resolutions along with suffixes and the correct images are loaded on iPhone "3.5inch" and iPad. However, the "-568h@2x" suffix for iPhone "4 inch" is not working fine. Am i using the wrong suffix? I would like to avoid the need to use macros

The new cocos2d has not got CCRibbon?

此生再无相见时 提交于 2019-12-23 04:24:23
问题 I recently downloaded the new cocos2d (I still have the older one) and I have been using a ribbon from CCRibbon to make a bullet move but it does not exist anymore and in a lot of my games it is a key object, can I somehow put it back in or use a similar "drawing" object? Thanks. 来源: https://stackoverflow.com/questions/12588470/the-new-cocos2d-has-not-got-ccribbon

Change Box2D Anchor Point?

拟墨画扇 提交于 2019-12-23 03:50:19
问题 In Cocos2D I am creating my CCSprites with anchor points of (0,1) which is similar to the way UIKit does it. Anyway, I am trying to change the anchor point in Box2D, is this possible? If so how would I do it with an anchor point of (0,1)? Thanks! 回答1: Box2D bodies don't have an anchor point. The anchorPoint is an offset of a node's texture relative to the node's position. Box2D bodies don't have a texture, hence no anchor point. Generally speaking you're going to make a lot of things more

CCRenderTexture size and position in Cocos2d-iphone

只愿长相守 提交于 2019-12-23 03:37:10
问题 I was trying to use CCRenderTexture for pixel perfect collision detection, as outlined in this forum posting: http://www.cocos2d-iphone.org/forum/topic/18522/page/2 The code "as is" works, and I have integrated it with my project But I am having trouble doing some of the other things discussed: If I create the renderTexture to be any size less than the screen size, the collision detection doesn't work properly - It seems to show collisions when the sprites are close (<15px) to each other but

How do you make a sprite rotate in cocos2D while using SpaceManager

拜拜、爱过 提交于 2019-12-23 03:22:38
问题 I just have a simple sprite - how can I get it to rotate? A good answer would show how to rotate both a dynamic sprite and a static_mass sprite 回答1: If the sprite is dynamic / non-static, just do like so: cpBodySetAngVel(ObjSmSprite.shape->body,0.25); For a static body, you can do something like this: [ObjSmStaticSprite.shape runAction:[CCRepeatForever actionWithAction: [CCSequence actions: [CCRotateTo actionWithDuration:2 angle:180], [CCRotateTo actionWithDuration:2 angle:360], nil] ]]; smgr