This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
extensions:tiledbox [2013/02/06 04:00] – [Data entry] matt62king | extensions:tiledbox [2015/09/14 11:14] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~NOTOC~~ | ||
+ | ====== Tiledbox ====== | ||
+ | |||
+ | ---- dataentry extension ---- | ||
+ | type : extension #or ' | ||
+ | author_mail | ||
+ | description | ||
+ | lastupdate_dt : #the date you created the extension | ||
+ | compatible | ||
+ | depends | ||
+ | tags : TileMap, Tiled, Box2d, Physics #enter a few tags, separated by commas | ||
+ | homepage_url | ||
+ | download_url | ||
+ | ---- | ||
+ | ===== Usage ===== | ||
+ | |||
+ | TiledBox is an interface between Tiled, Box2D, and Sparrow. It is capable of rendering graphics and Box2D world based on a TMX file. | ||
+ | |||
+ | TiledBox is pretty young right now. A lot of box2d functions are not yet support. The design of it is being based around a platform game. | ||
+ | |||
+ | Graphics rendering, body placement, collisions and movement are currently supported. | ||
+ | |||
+ | Implementation is very simple. | ||
+ | |||
+ | <code objc> | ||
+ | mBXWorld = [BXWorld sharedWorldWithGravity: | ||
+ | mBXWorld.autoAnimate = YES; | ||
+ | mBXWorld.contactDelegate = self; | ||
+ | | ||
+ | SXTileMap *tileMap = [self tileMapForWorld: | ||
+ | // | ||
+ | | ||
+ | SXTileViewport *viewport = [[SXTileViewport alloc] initWithLayer: | ||
+ | [self addChild: | ||
+ | | ||
+ | mViewport = viewport; | ||
+ | |||
+ | TATom *tom = [[TATom alloc] initWithPosition: | ||
+ | tom.canJump = NO; | ||
+ | tom.canMove = YES; | ||
+ | | ||
+ | SXTileViewport *levelViewport = [[SXTileViewport alloc] initWithLayer: | ||
+ | levelViewport.automaticallyDrawObjects = YES; | ||
+ | levelViewport.delegate = self; | ||
+ | levelViewport.actor = tom; | ||
+ | [self addChild: | ||
+ | | ||
+ | mLevelViewport = levelViewport; | ||
+ | |||
+ | #if BX_DRAW_WORLD | ||
+ | |||
+ | SXDebugDraw *debugDraw = [[SXDebugDraw alloc] initWithWorld: | ||
+ | [self addChild: | ||
+ | | ||
+ | #endif | ||
+ | |||
+ | </ | ||
+ | |||
+ | From there you just have to handle movement and collisions on your own. | ||
+ | |||
+ | TiledBox supports the drawing of interactive tile objects through call backs via a delegate: | ||
+ | |||
+ | <code objc> | ||
+ | |||
+ | |||
+ | - (SPDisplayObject *)displayObjectForObject: | ||
+ | if ([object.name hasPrefix: | ||
+ | CGPoint location = [mLevelViewport locationInViewport: | ||
+ | | ||
+ | TACoin *coin = [[TACoin alloc] initWithPosition: | ||
+ | coin.x = location.x; | ||
+ | coin.y = location.y; | ||
+ | | ||
+ | return coin; | ||
+ | } | ||
+ | | ||
+ | return nil; | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | The limitation is that the custom object must be placed in Tiled in a specific format under one of two distinct object groups. | ||
+ | |||
+ | DisplayObjects - Custom objects for display that will not interact with the player. (Currently only " | ||
+ | |||
+ | b2Objects - Custom objects that can interact with the player. (Currently only " | ||
+ | |||
+ | When you layout your object group ensure you label the object group name and object types correctly. It is also important to make sure all your objects have a different name. | ||
+ | |||
+ | Here is an example of what the object output should look like: | ||
+ | |||
+ | <code objc> | ||
+ | |||
+ | < | ||
+ | <object name=" | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | </ | ||
+ | < | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | <object name=" | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | Here is the end result: | ||
+ | |||
+ | Note: The below screen shot is with box2d debug draw enabled. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | * // | ||
+ | |||
+ | ===== Source Code ===== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | Source includes the box2d source as well | ||
+ | ===== Discussion ===== | ||
+ | |||
+ | //No comments so far. Feel free to edit this part of the page.// |