{"__v":1,"_id":"550d840f11e8d00d00b80383","category":{"__v":14,"_id":"54890d71c178b40b00aa3086","project":"543b9b0065bf840e00b473d5","version":"543b9b0065bf840e00b473d8","pages":["548a63d41bd6c40b00f77728","548a6fbab77bb70b00ac8bf2","548adcb7b77bb70b00ac8c9d","548add501bd6c40b00f777d2","548ae445b77bb70b00ac8cad","548aef1bb77bb70b00ac8ccb","548af4b41bd6c40b00f777fc","548eb9d5e52d2b0b001b9a28","5508449ba42e812500b711f3","550a8eed42fff40d00ae60e3","550ce8fd6c0b4c0d00fd42fb","550ce9026c0b4c0d00fd42fd","550d840f11e8d00d00b80383","550e7e7f8387ac0d00ed9e1a"],"reference":false,"createdAt":"2014-12-11T03:20:17.529Z","from_sync":false,"order":5,"slug":"game-settings","title":"Game Settings"},"project":"543b9b0065bf840e00b473d5","user":"543b9aa865bf840e00b473d1","version":{"__v":11,"_id":"543b9b0065bf840e00b473d8","project":"543b9b0065bf840e00b473d5","createdAt":"2014-10-13T09:27:28.467Z","releaseDate":"2014-10-13T09:27:28.467Z","categories":["543b9b0065bf840e00b473d9","543b9ef065bf840e00b473e0","54890012f291f61400c02d36","54890902f291f61400c02d3e","54890c43f291f61400c02d44","54890d71c178b40b00aa3086","5508125c0c4d8c19008a5f83","55094050961f17170070abbd","550945111c38c50d006118ad","550a4c2e42fff40d00ae6049","55221c074801a40d00a77610"],"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"createdAt":"2015-03-21T14:45:35.731Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"order":7,"body":"[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Improved Camera Scripting in the Complete Kit\",\n  \"body\": \"For game studios who need a polished gameplay experience, the Complete Kit includes mouse and gesture scroll with **velocity drag** like top-grossing such as Hayday or Simpson's Tapped Out. ([Kit details](https://www.citybuildingkit.com/#pricing))\"\n}\n[/block]\nOur camera controller is simple, and development-oriented. As a rule, we do not modify any components in the NGUI/Toolkit2D frameworks, since they get updated frequently, and any new functionality would be lost quickly in the next update. \n\nTherefore, our camera is, in fact, provided and updated by the frameworks, for both game and UI and therefore fully compatible with new releases of both these assets.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Updating Cam Settings\"\n}\n[/block]\nThe following section only applies to the Complete Kit.\n\nIn the Game scene and Map01 scene, select tk2dCamera in the Hierarchy and edit the Camera Controller variables in the Inspector.\n\nBy default, we've setup the panning speed and fade variables to perform quickly, though for modern iOS devices you might want to slow the panning speed in half to make the touch controls less responsive and the map seemly bigger.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://www.filepicker.io/api/file/kFutQQMSVKVj5ilWESdM\",\n        \"cam_settings.png\",\n        \"1920\",\n        \"1053\",\n        \"#6cb44d\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"CameraController.cs\"\n}\n[/block]\nThe script that adds the map edge constraints/touch and button controls is CameraController.cs\n\nSince our map and tiles are pretty big, we've adjusted the the speed of our camera for the area. If you want to make a smaller game, you'll need to adjust the speed; if the transitions are not smooth, you might want to look for some other performance bottlenecks - check stats/fps/draw calls.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Bounding Edges of the Camera\"\n}\n[/block]\nEven now, the latest 2D Toolkit components/demos do not have any built-in feature to constrain the 2D Toolkit camera scroll or zoom. When we first created the camera, it was pretty obvious that those features were not constrained in any way - you could zoom in/out until the map became a dot/disappeared entirely. \n\nTherefore, the camera zoom and position are the only visible variables, and constraining the values is very simple. There is a clipping dual camera feature, which is used for other purposes (menus), but almost all our menus/buttons are handled by NGUI (with only one exception-the buttons that allow you to select the buildings). \n\nBy the looks of it, this feature could be used to display a clipped/moving area from a camera that sees the entire map, but we don't see the advantage - you would have 2 cameras instead of one (Unikron assures us that the performance impact would be insignificant),\nplus the NGUI camera, and the values would have to be carefully calculated as well. \n\nBecause of this, the kit operates directly with the main 2DTK camera - we never even had to change the script to match new framework versions so it's highly compatible with new asset releases.","excerpt":"Brief notes about the 2D camera","slug":"camera","type":"basic","title":"Camera"}

Camera

Brief notes about the 2D camera

[block:callout] { "type": "success", "title": "Improved Camera Scripting in the Complete Kit", "body": "For game studios who need a polished gameplay experience, the Complete Kit includes mouse and gesture scroll with **velocity drag** like top-grossing such as Hayday or Simpson's Tapped Out. ([Kit details](https://www.citybuildingkit.com/#pricing))" } [/block] Our camera controller is simple, and development-oriented. As a rule, we do not modify any components in the NGUI/Toolkit2D frameworks, since they get updated frequently, and any new functionality would be lost quickly in the next update. Therefore, our camera is, in fact, provided and updated by the frameworks, for both game and UI and therefore fully compatible with new releases of both these assets. [block:api-header] { "type": "basic", "title": "Updating Cam Settings" } [/block] The following section only applies to the Complete Kit. In the Game scene and Map01 scene, select tk2dCamera in the Hierarchy and edit the Camera Controller variables in the Inspector. By default, we've setup the panning speed and fade variables to perform quickly, though for modern iOS devices you might want to slow the panning speed in half to make the touch controls less responsive and the map seemly bigger. [block:image] { "images": [ { "image": [ "https://www.filepicker.io/api/file/kFutQQMSVKVj5ilWESdM", "cam_settings.png", "1920", "1053", "#6cb44d", "" ] } ] } [/block] [block:api-header] { "type": "basic", "title": "CameraController.cs" } [/block] The script that adds the map edge constraints/touch and button controls is CameraController.cs Since our map and tiles are pretty big, we've adjusted the the speed of our camera for the area. If you want to make a smaller game, you'll need to adjust the speed; if the transitions are not smooth, you might want to look for some other performance bottlenecks - check stats/fps/draw calls. [block:api-header] { "type": "basic", "title": "Bounding Edges of the Camera" } [/block] Even now, the latest 2D Toolkit components/demos do not have any built-in feature to constrain the 2D Toolkit camera scroll or zoom. When we first created the camera, it was pretty obvious that those features were not constrained in any way - you could zoom in/out until the map became a dot/disappeared entirely. Therefore, the camera zoom and position are the only visible variables, and constraining the values is very simple. There is a clipping dual camera feature, which is used for other purposes (menus), but almost all our menus/buttons are handled by NGUI (with only one exception-the buttons that allow you to select the buildings). By the looks of it, this feature could be used to display a clipped/moving area from a camera that sees the entire map, but we don't see the advantage - you would have 2 cameras instead of one (Unikron assures us that the performance impact would be insignificant), plus the NGUI camera, and the values would have to be carefully calculated as well. Because of this, the kit operates directly with the main 2DTK camera - we never even had to change the script to match new framework versions so it's highly compatible with new asset releases.