cocos2d-iphone

Cocos2d V3 iOS - How to access runningScene from App Delegate

故事扮演 提交于 2019-12-13 02:47:22
问题 I’m wanting to access my running scene in the App Delegate. The problem is, [[CCDirector sharedDirector] runningScene] returns a CCScene object, rather than the actual class of my scene MyMainScene . If I try to call any of my custom methods, I get: -[CCScene customMethod]: unrecognized selector sent to instance 0x156bedc0 I’ve tried casting like this CCScene *scene = [[CCDirector sharedDirector] runningScene]; MyMainScene *mainScene = (MyMainScene*)scene; [mainScene customMethod]; But this

Cocos 2d 2.0 shouldAutorotate not working?

帅比萌擦擦* 提交于 2019-12-13 02:25:12
问题 I'm having some issues. I have a cocos2d game I'm just about done developing. However I've run into a problem where I need to enable portrait orientation in my apps plist for game center sign in to work without throwing a SIGABRT error. So once I enable that from my app's build summary page (Or add it to the info.plist file as a supported orientation) it works fine. But then anytime in my game if you turn the iPhone it will flip to portrait mode if it senses you turned it that way. I've tried

cocos2d retina support not working anymore

假如想象 提交于 2019-12-13 02:12:00
问题 I am having a problem with my cocos2d game that supports retina display. Everything used to work fine but now i am working on an update. In this update i have only added 3 new images (also in hd). I am using texture atlases made with zwoptex. the png's generated are gameart.png and gameart-hd.png. I am loading the files using this code: CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache]; [frameCache addSpriteFramesWithFile:@"gameart.plist"]; when getting any sprite i

Question about Objective-C selectors; Can I use parameters and how?

丶灬走出姿态 提交于 2019-12-13 01:54:17
问题 I'm attempting to use a selector with arguments and failing while doing so. I'm coming from C/++ and selectors are a tad bit confusing. I have this code: playItem = [CCMenuItemLabel itemWithLabel:playLabel target:self selector:@selector(goToScene:)argumentHere]; How would I go about passing an argument to a method in this way? Thanks in advance:D 回答1: You can't. Selectors specify only method to be invoked, not parameters to be passed. What you can do, is to check sender parameter in your

Game object with composition and CCSpriteBatchNode

一个人想着一个人 提交于 2019-12-13 01:35:10
问题 I'm currently developing a game with cocos2d and box2d on iPhone. I read a lot of articles concerning game code organization, game objects structure etc. I first started developing my game objects by inheriting from a base class itself inheriting from CCSprite. I had a CCSpriteBatchNode to draw all the game items, which the player can interact with, in one draw call. This was easy because my Item class indirectly inherit from CCSprite so I could easily add my items to the CCSpriteBatchNode.

Is it normal that my cocos2d app increase real memory usage every second?

China☆狼群 提交于 2019-12-13 01:27:33
问题 I develop cocos2d iOS app for iPad. When I test memory leaks and object allocation my Live Bytes are stable, but when I run Activity Monitor I see that the Real Memory Usage of my app increase every second with 0.02MB. I want to ask is it normal and did someone have similar problems? 回答1: This is entirely plausible, because Cocos2d (at least the 0.9.x and 1.0 branches) tends to autorelease everything. This can lead to memory build up on situations where you're spawning a lot of sprites

Programmatically call textFieldShouldReturn

亡梦爱人 提交于 2019-12-13 00:47:59
问题 The current project runs under cocos2d v2. I have a simple UITextField added to a CCLayer. Whenever, the user touch the textField, a keyboard appears. Then when the user touch the "return" button, the keyboard disappear and clears the input. What I tried to do is to make the same thing when the user touches anywhere outside the UITextField. I did find a method and it works : - (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { UITouch* touch = [touches anyObject]; if(touch.view

cocos2d-x convert UIImage to CCSprite

女生的网名这么多〃 提交于 2019-12-13 00:41:44
问题 has anyone an idea how to convert a UIImage to cocos2d-x CCSprite. My latest attempt was was: 1. Store the UIImage as png on the phone 2. Load the png as a CCSprite [UIImagePNGRepresentation(photo) writeToFile:imagePath atomically:true]; CCSprite *sprite = CCSprite::spriteWithFile(imagePath); But this crashed in CCObject retain function void CCObject::retain(void) { CCAssert(m_uReference > 0, "reference count should greater than 0"); ++m_uReference; } And I do not understand how Walzer Wangs

Pinch to zoom with CCParallaxNode

心已入冬 提交于 2019-12-13 00:17:21
问题 How do I implement pinch to zoom to a parallax scrolling node ? 回答1: Here's the solution: - (void)handlePitchZoom:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* touch1 = [[[event allTouches] allObjects] objectAtIndex:0]; UITouch* touch2 = [[[event allTouches] allObjects] objectAtIndex:1]; // calculate scale value double prevDistance = ccpDistance([touch1 previousLocationInView:[touch1 view]], [touch2 previousLocationInView:[touch2 view]]); double newDistance = ccpDistance([touch1

Release all texture memory

家住魔仙堡 提交于 2019-12-13 00:13:18
问题 I load my animated character with a huge texture this way: [[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@"MyFile.plist"]; And later, when I am no longer using the character, I release memory using: [[CCSpriteFrameCache sharedSpriteFrameCache]removeSpriteFramesFromFile:@"MyFile.plist"]; And also: [[CCTextureCache sharedTextureCache]removeTextureForKey:@"MyFile.png"]; Just to be sure. I do that because the texture it uses consumes a lot of memory, so I make sure I dispose