Integrating MapKit with Cocos2D - cocos2d-iphone

I'm a bit new with MapKit and have been trying to find the answer to this question:
Can I integrate, or to what extent can I integrate MapKit with Cocos2d?
In having this question answered, I hope that somebody could point me in the right direction on how to approach this scenario:
I am developing a Cocos2D app in which one part of the app would be the MapKit application, showing location and annotations (basically everything that comes with MapKit), and the user has the option to switch to the Cocos2D part. (Switching back and forth between the Map and the Game).
If the two were integrated, would there then be a way to overlay a Cocos2D Menu system over the MapKit and treat MapKit as simply a CCLayer or CCNode? or do I need to treat these two as separate entities altogether by only using UIKit buttons and menus with MapKit, and the only real mix between them is the passing of data from MapKit on to Cocos2D view on transition and vice versa?
Would it follow the same concept as integrating UIKit and Cocos2D in this answered question or this tutorial? Or do I have to use a special wrapper class such as CCUIViewWrapper? I read that CCUIViewWrapper is always drawn on top, so it could possibly not allow me to draw a Cocos2D Menu on top of the map, or even overlay a Cocos2D object once a UIKit button is pressed in the MapKit App.
Any help would be appreciated...Thanks!

I think using CCUIViewWrapper will be a good idea, about the question that CCUIViewWrapper always draw on the topmost layer of View I think that is kinda wrong(I am not sure) as CCUIViewWrapper returns the object in the format of CCNode so you can add it anywhere on the screen you would like to (If I was in your place I would have first tested this with adding a small sprite on top of a MapKit View in a cocos2d project just to be sure).
-Ankur

Related

Detect single/multi-finger gesture Swiftui

How to detect number of finger interaction with Gesture in SwiftUI Gesture. With UIKit we can find number of find it from
let numberOfTouches = panGestureRecognizer.numberOfTouches
Any thought?
I am able to find my solution using UIKit UIView. Actually made container view(UIVIewRepresentable) which implements the PanGesture. I have used this view to to hold SwiftUI view. I can easily find and able to handle Panning behaviour.

Understanding cocos2d scenes, how they works really?

I'm stuck on something about the scenes creation and replacement in cocos2d, so I'm going to ask precisely what seems to be misunderstood by me. I have a game (fully working except for scene swapping, sadly) with some little-games, now, if I had to do this starting with a cocos2d scene as menu I wouldn't have any problem, but since I did it starting with UIKit I truly need to know better how the scenes are working to fix it.
Firstly, is it required to start a scene in the appDelegate? since I'm starting with UIkit and the scene must be shown after you choice the game (say, out of 3 choices), which scene should I put in the appDelegate? and where exactly? I'm putting the scene in this method:
-(void) directorDidReshapeProjection:(CCDirector*)director
{
if(director.runningScene == nil)
//start scene
}
If I put the FIRST scene, the UIKit part works good and when I start the "game number TWO" as first choice (say we play this game for first) I got the Open GL 0x0506 error, then the scene start.
If I put the first scene, I choice the first game, and then quit and choice the second game, the scene is replaced properly without that error.
If I put the first scene, and I start the "game number 1" it works (obviously) because he has the scene loaded, but I cannot know which game will start as first the user.
I tried with an "intro scene" loaded at the appDelegate but I got the same problem. the problem basically is "how to start scene if you have more than one scene and don't know which will be called as first"...
The 'getting started with iOS' documentation will really clear up a lot of these questions. You can find it at developer.apple.com - https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007072
It explains just what an AppDelegate actually is, as well as how to use one properly. It is not immediately clear how to mix UIKit and cocos2d, but the above link cleared a lot up for me. Another very helpful resource is a tutorial by Ray Wenderlich -
http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit
From a bird's eye view, the CCDirector inherits from a UIWindow. Mixing UIKit and cocos2d is as simple as building your interface with UIKit, then at some point opening a UIWindow and allowing the CCDirector to start cocos2d. In a sense, the components act as almost two entirely separate entities.

Scrolling region in cocos2d version 2

I am trying to implement a help screen in my cocos2d game, using cocos2d version 2.0. My screen will have a title bar ("Help") at the top and then the rest of the screen below that is where I want to put a scrolling help section. Ideally I would be able to put both text and images into this help window.
The problem is that cocos2d does not have any functionality like UIScrollView, and from what I have seen doing Google searches, every custom solution I have found seems to have problems with various bugs popping up on various devices.
I have tried these solutions thus far:
CCScrollLayer: http://www.cocos2d-iphone.org/forum/topic/17118/page/3
Scrolling CCNode: http://tonyngo.net/2011/11/scrolling-ccnode-in-cocos2d/
CCScrollView: http://bitbattalion.com/2011/09/uikit-uiscrollview-and-cocos2d/
The closest thing I got to work was embedding a UITextView but that seemed to randomly crash after a few scrolls so it seems unreliable to me.
Does anyone know of a good simple robust solution to this problem? It seems like it should be straightforward but it isn't.
I recommend that you make new class say:(HelpViewClass) and implement it with an UIScrollView and add whatever you want to add on UIScrollView and then you can use this as a child to your layer.
Steps
Make a class - inherited with UIView
Add UIScrollView to the View.
Add Your components to it.
Add this UIView to the HelpLayer.
You can add any UIKit component to the cocos2d Layer by using this
[[[CCDirector sharedDirector] view] addSubView:scrollView];
Note : Remove all UI component when you go back from this HelpLayer.
I think this may help you !

Steps to add a cocos2d scene to a UIView

Can anyone say the steps to add cocos2d scene to a uikit project. I am new to cocos2d and not aware how to add the files related to cocos2d and also please explain where to add the eagl view in the ui files.
And also share a link for adding a cocos2d in a uiview and not the other way round.
Thanks
For my mind, it is not a good idea to mix uikit with cocos2d. Examples of creating eaglview you can find in any of cocos2d templates. Here you can read how to install cocos2d templates.
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:lesson_1._install_test

Cocoa application with cocos2d-iphone?

I'd like to do this:
Create a Cocoa application with a couple NSButtons in it. Also, a "cocos2d-iphone" view running in the same window.
If I trigger the NSButtons, a function is called in the cocos2d-iphone view (not sure where, maybe in the currently running scene?).
Well, I managed to create a new project from the cocos2d-iphone for Mac template, made the window bigger than the cocos2d view, moved the cocos2d view, and added my NSButtons. Now, I am not very sure about how to make the connection I need.. =/
I suggest reading an Interface Builder tutorial. This one is using Quartz, it's not Cocos2D but close enough. Simply assume the Quartz view to be Cocos2D view while you go through the tutorial.
Note that Cocos2D/EAGLView has some issues with NSView objects. In particular you can't add NSView objects as subviews to the Cocos2D OpenGL view, they will simply not be displayed. This is a general problem of the OpenGL view on Mac, and there are solutions/workarounds for this but they unfortunately do not work with Cocos2D. So if you're planning to have NSView objects overlapping the Cocos2D view … well, you can try and if you can make it work, PLEASE let me know how! :)