Skip to content

Instantly share code, notes, and snippets.

@mohiji
Created December 7, 2012 18:57
Show Gist options
  • Save mohiji/4235524 to your computer and use it in GitHub Desktop.
Save mohiji/4235524 to your computer and use it in GitHub Desktop.
Rebuilding a scene
/* This method gets called with the absolute root object for the whole scene. I then
add a few container objects to it.
_freeSceneRoot is a bog standard sprite that I just add child sprites to; I just move
it around in relation to where the current viewpoint is. Anything that's placed in the
game world is added to this (including the _sortedContainer below)
_sortedContainer is a customized sprite that sorts its children by their y-coordinate,
so things draw in the right order. (Things lower on the screen draw over things higher on
the screen)
Then I add a couple of screen space things: dialog is added after the _freeSceneRoot
so that it draws on top and isn't affected by the viewpoint in the world, and the _fadeNode
does things like fading to white/black
*/
- (void)buildFreeMotionScene:(SPDisplayObjectContainer *)sceneRoot
{
_tilemap.drawOffset = _camera.viewpoint;
_freeSceneRoot.pivotX = _camera.viewpoint.x;
_freeSceneRoot.pivotY = _camera.viewpoint.y;
[_tilemap fillTilesheet:_baseTilesheet withLayer:BaseLayer];
[_tilemap fillTilesheet:_detailTilesheet1 withLayer:DetailLayer1];
[_tilemap fillTilesheet:_detailTilesheet2 withLayer:DetailLayer2];
[_sortedContainer removeAllChildren];
[_sortedContainer addChild:_jackie.displayObject];
[_bees addBeesToScene:_sortedContainer];
if (_jon.active) {
[_sortedContainer addChild:_jon.displayObject];
}
if (_kayla.active) {
[_sortedContainer addChild:_kayla.displayObject];
}
if (_colin.active) {
[_sortedContainer addChild:_colin.displayObject];
}
if (_kefka.active) {
[_sortedContainer addChild:_kefka.displayObject];
}
[_freeSceneRoot addChild:_baseTilesheet];
[_freeSceneRoot addChild:_detailTilesheet1];
[_freeSceneRoot addChild:_sortedContainer];
[_freeSceneRoot addChild:_detailTilesheet2];
if (_touchIndicator.visible || _touchIndicator.fadingOut) {
[_freeSceneRoot addChild:_touchIndicator.displayObject];
}
[sceneRoot addChild:_freeSceneRoot];
if (!_dialogNode.done) {
[sceneRoot addChild:_dialogNode];
}
if (!_fadeNode.done) {
[sceneRoot addChild:_fadeNode];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment