how do I make scrollable map in game?

Hi


I would like to make a game similar to Clash of Clans in which the user can use thier fingers to scroll around a world map, zoom in, and zoom out. Yes, this is a beginner question, but I don't know where to start learning how to write Swift code for this idea.

Please let me know if there are any good online video tutorials that teach how to build this concept.


Thank you in advance!


-David

Replies

I'd say go with a Pinch Gesture Recognizer (for scaling) and Pan Gesture Recognizer (for moving the map). I would probably have them scale and move the camera though, not the actual map itself.


I teach a lot of Sprite Kit and Swift tutorials, you can figure out the domain for that pretty easily. Just taught a lengthy series on Role Playing Games, that could help a lot down the road. Clash of Clans is a pretty grandiose app to recreate, you'll need to learn quite a bit. Be worth it though.

1) Apple provides SKTileMapNode which is designed to display a 2 dimmensional array of tiles. In this case, the terrains and map are defined in Xcode. Use this if you're okay with supporting iOS 10 and above.


2) the DemoBots sample code also displays a scrollable map (though it does not use SKTileMapNode to do so).


3) JSTileMap roughly does what you describe. It's a SpriteKit loader of TMX file format maps you create in the Tiled map editor. JSTileMap is an Objective-C project, however there are Swift ports in the wild, e.g., search for "TMX Swift"