{"id":29873744,"url":"https://github.com/reo7sp/kaniku","last_synced_at":"2026-04-16T18:32:59.667Z","repository":{"id":57288240,"uuid":"67528918","full_name":"reo7sp/kaniku","owner":"reo7sp","description":"MVC microframework for cocos2d-x javascript games","archived":false,"fork":false,"pushed_at":"2017-05-10T20:37:13.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-29T11:15:41.525Z","etag":null,"topics":["cocos2d","cocos2d-x","coffeescript","javascript","mvc"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/kaniku","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reo7sp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-06T17:00:22.000Z","updated_at":"2016-10-22T13:16:55.000Z","dependencies_parsed_at":"2022-08-24T22:00:12.779Z","dependency_job_id":null,"html_url":"https://github.com/reo7sp/kaniku","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/reo7sp/kaniku","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reo7sp%2Fkaniku","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reo7sp%2Fkaniku/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reo7sp%2Fkaniku/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reo7sp%2Fkaniku/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reo7sp","download_url":"https://codeload.github.com/reo7sp/kaniku/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reo7sp%2Fkaniku/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267724628,"owners_count":24134408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocos2d","cocos2d-x","coffeescript","javascript","mvc"],"created_at":"2025-07-30T23:19:12.255Z","updated_at":"2026-04-16T18:32:59.615Z","avatar_url":"https://github.com/reo7sp.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kaniku\nMVC microframework for cocos2d-x javascript games.\n\nKaniku (Japanese: かにく) means flesh of a coconut.\n\nWe recommend to use [cocos-starter-kit](https://github.com/reo7sp/cocos-starter-kit) for your games with kaniku.\n\n## Model\nModel is the main source of information about game objects. All data flow must come through models.\n\nModels are able to emit events. Views, other models, etc. are allowed to emit events on behalf of the model too.\n\nMethod to emit event:\n```coffeescript\nemit: (listenKey, eventDataForListeners...)\n```\n```coffeescript\nplayer.emit('died', killer: 'red pacman ghost', killerLevel: 10)\n```\n\nMethod to subscribe to events:\n```coffeescript\non: (listenKeys..., func)\n```\n```coffeescript\nplayer.on('win', (score) -\u003e postScoreToTheSocialNetwork(score))\n```\n\nExample of model:\n```coffeescript\nclass PlayerModel extends kaniku.Model\n  @defaults(\n    x: 0 # the view will update this variable\n    y: 0\n    timeAlive: 0\n    timeAliveScoreFactor: 100\n  )\n\n  @useUpdates()\n\n  update: (dt) -\u003e\n    @timeAlive += dt\n\n  @computed 'score', depends: ['x', 'timeAlive', 'timeAliveScoreFactor']\n  getScore: -\u003e\n    @x + @timeAlive * @timeAliveScoreFactor\n```\n```coffeescript\nplayer = new PlayerModel(timeAliveScoreFactor: 25) # you can override initial values\n\nplayer.on 'change:score', -\u003e\n  sayPlayerThatHeIsGood()\n  \nplayer.setX(10)\n```\n\n`defaults` static method sets initial values of a model and also generates getters and setters for all listed variables. So it's important to list variables even with null initial values to let getters and setters to be automatically generated.\n\nGetters and setters are available both method-style (`m.getX()`, `m.setX(1)`) and property-style (`m.x`, `m.x = 1`). We recommend using property-style internally in a model and method-style when accessing model.\n\nGenerated setters emit event `change:VARIABLE_NAME`.\n\nYou can define computed variables via `computed` static method. This method makes change event of this computed variable to be emited on depending variables change. Also it creates property alias for getter.\n\n`useUpdates` method requests controller to call model's `update` method on every frame. The first argument of model's `update` method is time between frames in seconds.\n\nTo get defaults of model use method `getDefaults` which is available both for class and for instances. To get all variables of model (including computed) use method `getData`.\n\n\n## View\nView provides interface between model and real world. Views are usually cocos2d-x Node objects, which render game objects on the user's screen.\n\nThere are no Kaniku class to extend from.\n\nViews don't communicate with each other. They communicate through models.\n\n## Controller\nController is something like glue between all components of the game. It creates models and views and links them with each other.\n\nControllers are derived from cocos2d-x Scene class.\n\nUpdaters do some global work which may affect multiple views and models. Updaters are called each frame.\n\nUpdater can be any object which has `update` method (for example, `kaniku.Updater`) or it can be just a function.\n\nExample:\n```coffeescript\nclass FirstLevelController extends kaniku.Controller\n  createModels: -\u003e\n    @playerModel = new PlayerModel(x: 0, y: 100)\n    @addModel(@playerModel)\n\n    @npcModel = new FirstLevelNPCModel()\n    @npcModel.setPlayer(@playerModel)\n    @addModel(@npcModel)\n\n  createViews: -\u003e\n    uiLayer = new cc.Layer()\n\n    scoreView = new ScoreLabelView() # suppose it extends from cc.Label\n    scoreView.setPlayer(@playerModel)\n    uiLayer.addChild(scoreView)\n\n    @addChild(uiLayer, 2) # cc.Scene method\n\n    gameWorldLayer = new GameWorldLayer()\n\n    playerView = new PlayerView()\n    # Suppose this object call physics engine internally and then\n    # update player model with new coodinates.\n    #\n    # Score view will receive event that something was changed in the model,\n    # model will compute new score and then\n    # score view will finally update the label on screen using model data.\n    playerView.setPlayer(@playerModel)\n    gameWorldLayer.addChild(playerView)\n\n    @addChild(gameWorldLayer, 1)\n\n  createUpdaters: -\u003e\n    @addUpdater (dt) =\u003e\n      @player.on 'change:x', (x) -\u003e\n        generateGameWorldAfter(x)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freo7sp%2Fkaniku","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freo7sp%2Fkaniku","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freo7sp%2Fkaniku/lists"}