iDevGames Forums
Map Editor in Cocoa - Beginner - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Map Editor in Cocoa - Beginner (/thread-9592.html)

Map Editor in Cocoa - Beginner - dev_tallen - Dec 2, 2011 09:46 AM

Hey guys!

I am currently experimenting on making a 2D tile map editor using Cocoa. My basic setup of the UI is the following:

One window with a left side panel, to the right of that is a NSScrollView with a CustomView inside (which will draw the maps).

To draw the tiles initially I have a 'Map' class that the custom view contains an object of and calls the map's initializeCells: method using Cocoa calls. Works fine until I try to scroll at which point scrolling is as fast as a snail. Am I overlooking an important piece to this puzzle? Right now the map does not redraw beyond the initialization.

Thoughts? Comments?

RE: Map Editor in Cocoa - Beginner - backslash - Dec 3, 2011 04:10 AM

An NSScrollView containing a vast number of image cells will always be horribly slow.
Are you making maps for your own game or someone else's (or just making maps?).
Generally, the best way to display maps is to use the same code that draws them in the game, if possible - i.e. if it is for your own game or for an open source game (and licensing isn't an issue). That would tend to mean an NSOpenGLView subclass and tiles mapping to polygons.
If you want to stick with your NSImagesCells (which is what I'm assuming you have in your scroll view), I'd suggest that you drop the NSScrollView and have a fixed size NSMatrix. You can change which images are drawn in which cells to simulate scrolling (controlling it using buttons or the arrow keys). That should be quite easy to implement and avoids having quite so many NSImageCells trying to redraw at the same time (at the cost of the scrolling being jumpy rather than smooth).

RE: Map Editor in Cocoa - Beginner - dev_tallen - Dec 3, 2011 11:47 AM

Pure cocoa isn't the way to go then? Yeah it is for a game I'm working on which uses c++ so was hoping to be able to write a cocoa native app. Doesn't sound like it can be done at least with a smooth experience.

RE: Map Editor in Cocoa - Beginner - backslash - Dec 3, 2011 12:18 PM

When I said scrolling would be jumpy, I meant it would jump tile by tile, rather than referring to any slowness. That said, there's nothing to stop you from using an NSOpenGLView (which is a Cocoa class!) along with all the NSButtons, NSTextfields and whatever else you might want. I don't know if you can get NSOpenGLView to provide Cocoa scrollbars though.

RE: Map Editor in Cocoa - Beginner - dev_tallen - Dec 5, 2011 04:47 PM

Oh ok. I suppose I could just use OGL and feed the view information from the map class.

If I knew more I would use the game code itself but with my current understanding I don't think the underlying code fits well... Then again we use a "renderer" for all drawing so if I replaced that with the NSOpenGLView then we might be onto something. Would that be a workable scenario?

RE: Map Editor in Cocoa - Beginner - backslash - Dec 6, 2011 05:42 AM

That sounds reasonable. It obviously depends how your renderer works, but it is probably possible to get an NSOpenGLView subclass to imitate it closely enough to work fine.
My preferred approach is to keep data in my editor in the same format as data in the game, and use the exactly same rendering code. In theory, all you need to do is replace your game world simulation code with the editor control code and change any HUD elements accordingly.

RE: Map Editor in Cocoa - Beginner - dev_tallen - Mar 29, 2012 08:08 PM

Revisiting this issue. I am now going with an NSScrollView with an embedded NSOpenGLView. I can't seem to get scrolling to work at all this way.

In IB the OGL view is set as the same size as the scrollview, I would however like the OGL view to be the entire map (example: 50rowx50columns at 32x32pixels) and have the scrollview let me scroll around that size since it should be smaller.

I can't seem to get this to work.

RE: Map Editor in Cocoa - Beginner - SethWillits - Mar 31, 2012 10:43 AM

You won't be able to. You'll need to do the scrolling in OpenGL.

RE: Map Editor in Cocoa - Beginner - maximile - Mar 31, 2012 01:07 PM

You can use the functionality of NSScrollView to make it easier though. Here's some old, uncommented code I wrote a while ago but maybe it'll be helpful to you:

RE: Map Editor in Cocoa - Beginner - dev_tallen - Mar 31, 2012 02:19 PM

I got it working. The only part missing was resetting the OpenGL viewport each time :reshape() was called. Smile

Rest was handled automatically via NSScrollview.