TKDemoScene Class Reference

Inherits from TKScene
Declared in TKDemoScene.h

Overview

Demo scene base class. Used in the demo project to present the TMX menu and to scan for existing TMX files using a certain naming scheme. Displays a bundle’s TMX files via menu and loads them when a label is tapped.

The purpose of this class is mainly to centralize common code into the same class for all engines/platforms while keeping the actual demo project’s code simple and to the point (just map loading).

Warning: This class is provided “as is”. Its purpose is for internal testing of TilemapKit. Nevertheless, its code may still be instructive.

You can review the TKDemoScene source code in its entirety:

Working with Map Nodes

– addMapNode:

Override this method in your subclass. Called when a map’s label is “pressed”. You should load and add the map from the path.

- (void)addMapNode:(nonnull NSString *)path

Parameters

path

A path to a TMX file in the bundle. Typically just the TMX filename.

Declared In

TKDemoScene.h

  orthoMaps

Contains NSString* with the names of all orthogonal TMX files in the bundle. The array is updated when showMapTypesMenu is called.

@property (readonly, nonnull) NSMutableArray<NSString*> *orthoMaps

Declared In

TKDemoScene.h

  isoMaps

Contains NSString* with the names of all isometric TMX files in the bundle. The array is updated when showMapTypesMenu is called.

@property (readonly, nonnull) NSMutableArray<NSString*> *isoMaps

Declared In

TKDemoScene.h

  hexMaps

Contains NSString* with the names of all hexagonal TMX files in the bundle. The array is updated when showMapTypesMenu is called.

@property (readonly, nonnull) NSMutableArray<NSString*> *hexMaps

Declared In

TKDemoScene.h

  activeMapNode

The currently presented TKMapNode.

@property (weak, nullable) TKMapNode *activeMapNode

Declared In

TKDemoScene.h

  mapContainerNode

The node that contains the currently active TKMapNode. The container node runs a continuous animation to move the tilemap node about on the screen.

@property (weak, nullable) TKNode *mapContainerNode

Declared In

TKDemoScene.h

Showing the Menu

– showMapTypesMenu

Adds the Ortho/Iso/Hex menu labels at the bottom of the screen. Scans the bundle for all .tmx files that begin with Ortho, Iso or Hex and adds submenu labels for each .tmx file found to the corresponding category.

- (void)showMapTypesMenu

Declared In

TKDemoScene.h

Detect Button Presses

– testLabelPressedWithEvent:

Check if the event’s location was on a menu label and if so, executes the label’s function (open menu or load map).

- (void)testLabelPressedWithEvent:(nonnull TKEvent *)event

Parameters

event

The NSEvent/UIEvent that holds the event’s location.

Declared In

TKDemoScene.h

– testLabelPressedWithEvent:onlyMainLabels:

Check if the event’s location was on a menu label and if so, executes the label’s function (open menu or load map).

- (void)testLabelPressedWithEvent:(nonnull TKEvent *)event onlyMainLabels:(BOOL)onlyMainLabels

Parameters

event

The NSEvent/UIEvent that holds the event’s location.

onlyMainLabels

If YES, only executes function when the event’s location was on one of the category labels (Ortho, Iso, Hex).

Declared In

TKDemoScene.h

– testLabelPressedAtPosition:onlyMainLabels:

Check if the position is on a menu label and if so, executes the label’s function (open menu or load map).

- (void)testLabelPressedAtPosition:(CGPoint)position onlyMainLabels:(BOOL)onlyMainLabels

Parameters

position

The position to test for, in scene/view/world coordinate space.

onlyMainLabels

If YES, only executes function when the event’s location was on one of the category labels (Ortho, Iso, Hex).

Declared In

TKDemoScene.h

Show Simulator Performance Warning Label

– addPerformanceWarningLabel

Displayed by simulator builds due to Simulator’s terrible rendering performance.

- (void)addPerformanceWarningLabel

Declared In

TKDemoScene.h

Misc / Convenience

  viewSize

The size of the view.

@property CGSize viewSize

Declared In

TKDemoScene.h