Flipping tiles

by KleMiX 24. October 2011 01:08

Flipping tiles is one of the new features available in iTileMaps v2.0.

Tags: , , , , , , , , , ,

iTileMaps

iTileMaps Compact

by KleMiX 9. July 2011 05:18

First update for iTileMaps is out now. New features include fill bucket tool, universal application (get it to your phone also) and some small tweaks and bugfixes.

If you want to try iTileMaps or you dont own an iPad and 10$ seem expensive, go grab new iTileMaps Compact edition! It's free to use but you can't save or export edited map. For a small fee of 3$ you can access full feature set on your iPhone or iPod Touch just hit Export button to make In App Purchase.

Miss some feature, know a bug or know how to improve iTileMaps? Feel free to contact me.

Tags:

iTileMaps

Import & Export options

by KleMiX 5. May 2011 01:48

Some screenshots that show options how you can import or export maps to iTileMaps

Tags: , , , , , , , , ,

iTileMaps

Preparing your game for importing from iTileMaps using cocos2d-iphone

by KleMiX 4. May 2011 21:23

In this tutorial we will add ability to import tmx maps directly from iTileMaps. All the code in this tutorial is based on cocos2d-iphone. There is also prerequisite, tutorial is based on Ray Wenderlich's 2 part series tutorials, you can just download the result from hes site or you can complete first part and second part of hes tutorials.

You can get complete source code of this tutorial at github or download it here

Preparing the code

I'm assuming you have opened completed tutorial of creating base tile based games so lets begin.

In HelloWorldScene.h just after +(id)scene add:

 

+(id) sceneWithMap:(NSString*)fileName;
-(id) initWithMap:(NSString*)fileName;

We are just defining our new functions to support loading maps from another sources not just hardcoded.

In HelloWorldScene.m

// Change
-(id) init
// to:
-(id) initWithMap:(NSString*)fileName

// Inside this function find and replace
self.tileMap = [CCTMXTiledMap tiledMapWithTMXFile:@"TileMap.tmx"];
// to
self.tileMap = [CCTMXTiledMap tiledMapWithTMXFile:fileName];

This code changes how map is loaded we are not using standard map but any map that we want.

Now the same with scene initialization:

// Change
+(id) scene
// to:
+(id) sceneWithMap:(NSString*)fileName

// inside this function find and replace
HelloWorld *layer = [HelloWorld node];
// to
HelloWorld *layer = [[[HelloWorld alloc] initWithMap:fileName] autorelease];

Just the same thing with scene loading which will load layer with the map we want.

To not break standard behavior add this somewhere near sceneWithMap:

+(id) scene
{
    return [HelloWorld sceneWithMap:@"TileMap.tmx"];
}

This addition gives standard behavior of the tutorial just with the ability to load maps from any source. When you compile and run nothing should change but with this functionality we are ready to import some maps.

Importing some maps

Open your info.plist with some text editor and add this code at the end before </dict>

<key>UIFileSharingEnabled</key>
<true/>
<key>CFBundleDocumentTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeRole</key>
			<string>Viewer</string>
			<key>LSItemContentTypes</key>
			<array>
				<string>com.klemix.tmx</string>
			</array>
			<key>CFBundleTypeExtensions</key>
			<array>
				<string>tmx</string>
			</array>
			<key>CFBundleTypeName</key>
			<string>TMX Map</string>
			<key>LSHandlerRank</key>
			<string>Alternate</string>
		</dict>
	</array>

This is one of the key parts to be able to import maps. First of all we are saying that users are able to access applciation's document directory from iTunes. Then we are telling iOS that we are capable to load some files with extension .tmx and content type com.klemix.tmx. This part of functionality isn't well documented by Apple so it might be wrong or hard to understand. More info about this you will get at the end of tutorial.

Note: you will need to copy all tileset images you are using to your application's documents directory via iTunes File Sharing before you can open map otherwise it will crash.

Now open TileGameAppDelegate.m and rename applicationDidFinishLaunching to

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

This is done to upgrade your code so it can load files from another sources, it isn't well documented also, but if you are writing iOS 3.0+ code it is recommended to use this kind of function to start your application.

After add some code in this function

// at the very beginning of the function
if ([launchOptions valueForKey:@"UIApplicationLaunchOptionsURLKey"]) {
        return [self application:application 
                         openURL:[launchOptions valueForKey:@"UIApplicationLaunchOptionsURLKey"] 
               sourceApplication:[launchOptions valueForKey:@"UIApplicationLaunchOptionsSourceApplicationKey"] 
                      annotation:nil];
}
if ([launchOptions valueForKey:@"UIApplicationLaunchOptionsSourceApplicationKey"]) {
	return YES;
}

// at the end of the function replace
[[CCDirector sharedDirector] runWithScene: [HelloWorld scene]];

// with
NSString *mapName = @"TileMap.tmx";
if ([launchOptions valueForKey:@"OpenMap"]) {
     mapName = [launchOptions valueForKey:@"OpenMap"];
}
[[CCDirector sharedDirector] runWithScene: [HelloWorld sceneWithMap:mapName]];
    
return YES;

At the very beggining we are telling application to load map calling function that we will add later, it is also due to some iOS version differnces. After that we are checking some newer functionality of iOS, it is asking if we want launch our application if it is called by supplied application bundle id, we are going to launch from any application so we are returning YES always.

In the end we are just searching if theres a key for supplied map filename, which we will create later. If it's not we are just launching default map from our bundle.

After this one add new function

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *newFilePath = [documentsDirectory stringByAppendingPathComponent:[url lastPathComponent]];
	
	[[NSFileManager defaultManager] copyItemAtURL:url toURL:[NSURL fileURLWithPath:newFilePath] error:nil];
	
	if (!window) {
		NSDictionary *dict = [NSDictionary dictionaryWithObject:newFilePath forKey:@"OpenMap"];
		[self application:application didFinishLaunchingWithOptions:dict];
	}
    else
    {
        [[CCDirector sharedDirector] replaceScene: [HelloWorld sceneWithMap:newFilePath]];
    }
	
	return YES;
}

This function gets called if our application is running on some supported iOS version and our application accepted source application's bundle id in previous function. The main idea is doing here we are copying supplied map to our application's documents directory, which is bad to be honest but another way is to edit cocos2d itself, this is caused by that we can add our tileset images only to documents directory using iTunes File Sharing feature. Then we are just loading new map by initializing application or just replacing scene if application is already running.

But to support multi tasking we should add two new functions also:

-(void) applicationDidEnterBackground:(UIApplication*)application {
	[[CCDirector sharedDirector] stopAnimation];
}

-(void) applicationWillEnterForeground:(UIApplication*)application {
	[[CCDirector sharedDirector] startAnimation];
}

This will not generate crash under iPad or 4th gen devices because you can't render something in background so we are just stopping all drawing made by cocos.

The results

That's all. Now you are able to compile and run this code to load maps directly from iTileMaps. Ofcourse you can do much more with the map or functionality given just turn on your imagination and read some Apple documentation about working with files.

All the code we wrote is available at github or direct download.

Further reading

To better understand how you can interact with documents in your applications follow up some Apple documentation, though it's really not documented so good.

Registering the File Types Your App Supports

Opening Supported File Types

If you know something more on these topics feel free to share information with me, it was really hard to get information on this and make it working.

Tags: , , , , , , , ,

iTileMaps

iTileMaps - tile map editor for iPad

by KleMiX 3. May 2011 09:13

Available on AppStore. Help available here.

First ever game development tool for iPad!

iTileMaps is powerfull tile map creation tool. Works with any 2D game genre, whether it's RPG or sidescroller or anything else. Specifically designed for iPad it allows creating maps very fast wherever you are. No need to change anything in your game because it uses popular tmx file format and works well with Tiled.

Best works with cocos2d because it's built on top of it. But any other game engine that supports tmx file format will work aswell.

Screenshots

   

Video

 

Features:

  • Simple and popular xml-based format - tmx
  • Orthogonal maps
  • Custom objects for per pixel precision placement
  • Custom properties for tiles, layers, objects or map
  • Time saving editing tools like clone and recent tiles
  • Can automatically manage high and standart definition maps (for iPhone 4 Retina)
  • Ability to export created map directly to your game
  • Send created maps by e-mail
  • Import maps from internet, e-mail or another application
  • Draws slower when in idle state, means higher battery life

Limitations (for advanced users):

  • Isometric and hexagonal maps are not supported
  • Only 1 tileset can be used per layer
  • Tileset info is saved in single file with map, no external tileset info supported
  • Images cannot be saved in map file, only externally
  • Layer data must be in gzip/zlib compression encoded with base64
Upcoming features:
Something that might be included in next updates
  • Fill bucket tool
  • Isometric maps
  • External tilesets
  • File manager
  • Action history with undo-redo
  • Dropbox, WebDAV, iDisk importing options

Tags: , , , , , , ,

iTileMaps

Facebook