Map Editor in Cocoa - Beginner

Apprentice
Posts: 5
Joined: 2011.12
Post: #1
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?
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #2
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).
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2011.12
Post: #3
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.
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #4
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.
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2011.12
Post: #5
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?
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #6
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.
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2011.12
Post: #7
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.
Quote this message in a reply
⌘-R in Chief
Posts: 1,254
Joined: 2002.05
Post: #8
You won't be able to. You'll need to do the scrolling in OpenGL.
Quote this message in a reply
Member
Posts: 283
Joined: 2006.05
Post: #9
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:

http://www.maximile.net/stuff/Scroll.zip
Quote this message in a reply
Apprentice
Posts: 5
Joined: 2011.12
Post: #10
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cocoa level editor reubert 2 2,998 Oct 3, 2004 01:49 AM
Last Post: reubert