我做了一些Google搜索和堆棧溢出,但仍然存在問題該怎麼辦。 我有一個大的基於導航的項目,iOS5.1,爲iPhone。 在幾個VC中,我需要包含一些或多或少複雜的動畫,比如男孩角色的咀嚼動畫。 我已經與cocos2d合作過,我知道用cocos2d完成我的目標很容易。但是是否有可能將coco2sd的場景和圖層包含到所需的VC中?或者以某種方式將視圖與S場景重疊? 任何提示將不勝感激。在非cocos2d項目中包含cocos2d
1
A
回答
1
首先,你需要在你的AppDelegate創建一個導演:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ...
// Create Cocos2D Director
//
// Try to use CADisplayLink director
// if it fails (SDK < 3.1) use the default director
if(! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink])
[CCDirector setDirectorType:kCCDirectorTypeDefault];
CCDirector *director = [CCDirector sharedDirector];
}
而在你-viewDidLoad
方法,它是由Cocos2D中創建的視圖添加到self.view
作爲一個子視圖:
- (void)viewDidLoad {
[super viewDidLoad];
// configre subviews
// ...
// Add your Cocos2D view
EAGLView * glView = [EAGLView viewWithFrame:self.view.bounds
pixelFormat:kEAGLColorFormatRGB565
depthFormat:0];
[glView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[CCDirector sharedDirector] setOpenGLView:glView];
[self.view addSubview:glView];
// Run a blank scene for testing
CCScene * blankScene = [CCScene node];
[[CCDirector sharedDirector] runWithScene:blankScene];
}
然後您可以創建自己的場景來替換blankScene
。
我強烈建議你在這個技術上的帖子:"How To Integrate Cocos2D and UIKit"。我通過閱讀@ Ray的帖子成功實現了這一點! ;)
2
我這樣做的方式只是在初始化ViewController時創建CCDirector,CCDirector使用OpenGL視圖來製作ViewController的子視圖。使用CCDirector,您可以完成您通常在Cocos2D中執行的所有操作。
if(! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink])
[CCDirector setDirectorType:kCCDirectorTypeMainLoop];
CCDirector *director = [CCDirector sharedDirector];
EAGLView *glview = [EAGLView viewWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
[self.view insertSubview:glview atIndex:1];
[director setOpenGLView:glview];
相關問題
- 1. sneakyjoystick替代非cocos2d項目?
- 2. UINavigationController中的Cocos2d項目
- 3. 將粒子從cocos 2d項目導入非cocos2d項目
- 4. 在Cocos2d Box2d項目中啓用ARC?
- 5. 在故事板項目中嵌入cocos2d
- 6. 在Cocos2d項目中使用CCSchedulers/CCTimers
- 7. 在Cocos2d 3項目中呈現GKGameCenterViewController
- 8. 的cocos2d-JS更新項目
- 9. 多平臺Cocos2d-x項目
- 10. 如何將SimpleAudioEngine包含到cocos2d-x v3.3項目中的Linux版本中?
- 11. 在Cocos2d中添加子項
- 12. 在VS項目中包含非代碼
- 13. 在非VS項目中包含VS DLL
- 14. 在Maven項目中包含非Java源
- 15. 升級項目中的cocos2d框架
- 16. Cocos2d項目中的得分系統
- 17. 顯示在cocos2d 2.x的項目
- 18. C++/Cocos2d-x:如何在Cocos2d-x Android項目中添加inapp billing(inapp購買)?
- 19. 建立與Android是Cocos2d-X的項目:「包org.apache.http不存在」
- 20. OpenFeint在Cocos2D中
- 21. EXC_BAD_ACCESS在cocos2d中
- 22. 在android項目(lib或classpath)中包含非android項目
- 23. 拍攝目標 - Cocos2D
- 24. 在cocos2d
- 25. 在cocos2d
- 26. 在cocos2d
- 27. 在cocos2d
- 28. 在cocos2d
- 29. Cocos2d/box2d項目無法在項目清理後編譯
- 30. 在OpenGL ES 2.0中包含Cocos2d粒子系統
好評,謝謝! – Dumoko