cocos2d-iphone

Cocos2d How to Switch Scenes

十年热恋 提交于 2019-12-19 10:16:38
问题 How do i switch scenes in cocos2d? I have my main class, "HellowWorldLayer.h/.m" , but i can't seem to switch scenes correctly. I have tried : [[CCDirector sharedDirector] replaceScene:[Race node]]; //And [[CCDirector sharedDirector] replaceScene:[Race Scene]]; I put a break point in and i can see it is going to the new scene but the Button i added to the new scene isn't showing up. I am creating the button correctly. Then i am adding it to the screen in the new scene like this: [self

cocos2d-x game crashes when entered background

徘徊边缘 提交于 2019-12-19 07:20:13
问题 my cocos2d-x game crashes when entering background. here is some code from AppDelegate: // This function will be called when the app is inactive. When comes a phone call,it's be invoked too void AppDelegate::applicationDidEnterBackground() { CCDirector::sharedDirector()->pause(); CCUserDefault::sharedUserDefault()->flush(); CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); } // this function will be called when the app is active again void AppDelegate:

iPhone: Get warning when battery power is very low

笑着哭i 提交于 2019-12-19 04:14:32
问题 I want to know how can i get warning in my app delegate when the device battery power is very low. So that i can pause the running game. Any idea? 回答1: You could use the battery level property from UIDevice . If the battery level is less than 5% show an alert for example. You could poll periodically for the battery level in your app delegate for example. UIDevice *myDevice = [UIDevice currentDevice]; [myDevice setBatteryMonitoringEnabled:YES]; float batteryLevel = [myDevice batteryLevel];

Overlaying a UIView onto a Cocos layer?

核能气质少年 提交于 2019-12-18 18:28:34
问题 I'm new to iOS and Cocos development. I currently have a basic app going on in my HelloWorldLayer class. It contains my sprites and touch interaction methods and all is well. I'm trying to add another "panel" (UIView?) over top of what is currently seen. Eventually this panel will have buttons or other things that will interact with the main canvas. How can I include another UIView onto the canvas screen? Through my appDelegate, or my HelloWorldLayer? Thanks 回答1: Here is one way to do it. I

cocos2d:Convert iPhone App to Universal App

半城伤御伤魂 提交于 2019-12-18 12:38:24
问题 I have developed an App app in cocos2d 99.4 using cocos2d box2d project template.It works well in iPhone 4,iPod.....but i need it to convert to universal...i mean iPad version also ......i already upgraded it to iPad version....so that it runs in iPad...but in small size like iPhone... can any one help?? Thanks 回答1: To convert your project to a universal app, see "Creating a Universal Application" in the iPad Programming Guide: Configuring Your Xcode Project The first step to creating a

water effect in cocos2d

*爱你&永不变心* 提交于 2019-12-18 11:37:01
问题 I'd like to have a water effect on a background layer in my app. The effect doesn't need to react to touch or anything - it just needs to wave an image a little bit. CCWaves3D seem ok, but leave have nasty black artifacts around the edges when I run it. Similarly CCShaky3D. CCLiquid brings my app down from 20fps to 5fps.. Is there any other effect I might want to try out? Or perhaps I'm using the current effects in a wrong way? id shaky = [CCShaky3D actionWithRange:4 shakeZ:NO grid:ccg(15,10)

Compile error in empty cocos2d 2.0 (iPhone)

陌路散爱 提交于 2019-12-18 11:35:40
问题 When I try to compile new cocos2d+box2d project in xcode4. I got error message like: /Users/bla-bla/Cocos2d testing/Cocos2d testing/libs/cocos2d/CCDirector.h:32:9: fatal error: 'kazmath/mat4.h' file not found [2] /Users/bla-bla/Cocos2d testing/Cocos2d testing/libs/cocos2d/CCNode.h:37:9: fatal error: 'kazmath/kazmath.h' file not found [2] File I checked, what is wrong? 回答1: This is caused by having a space in the path name to your project. To work around this, you'll need to add the following

Cocos2d 2.0 - 3 numbers on the bottom left

梦想的初衷 提交于 2019-12-18 11:09:48
问题 I have 3 numbers on the bottom left part of the screen on my Cocos2D 2.0 project: 82 0.016 60.0 60 is probably FPS and what about the other two? As I remember, previous versions of Cocos had just the FPS number. Any clues? thanks 回答1: 82 <-- number of draw calls 0.016 <-- time it took to render the frame, here: 1.0/60.0 = 60 fps 60.0 <-- frames per second The first number (82) is the number of draw calls (which is fairly high). Typically each node that renders something on the screen (sprites

Should I subclass CCSprite, CCNode, or NSObject?

心已入冬 提交于 2019-12-18 10:51:29
问题 I see that certain texts always seem to subclass CCSprite. I read somewhere that it is not good to do that and that it is better to start with something basic. I wanted to find out what the pro game developers do in terms of game structure. That is subclass CCSprite or add CCSprite in a NSObject class ETC. I hope my question makes sense. 回答1: Your question definitely makes sense. It's fundamentaly an architecture question. If your game is mainly based on "animation", I'd go for subclassing

drawing cocos2d v3 no longer has ccDraw* functions, how do I draw without making nodes?

夙愿已清 提交于 2019-12-18 09:35:15
问题 I followed the instructions on http://www.cocos2d-swift.org/get-started and made a new Project through Sprite Builder. searching for ccDraw doesn't show anything. I found this example on a forum, and implemented, but it doesn't look right. I don't want a drawNode that taxes resources. I want low level GL drawing line how ccDrawLine used to work. When I do a drawNode like this -- it doesn't reset the old drawing -- so all lines I draw stay on the screen. How do I draw like in v2.x? (ccDrawLine