npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kaniku

v1.1.4

Published

MVC microframework for cocos2d-x javascript games

Downloads

48

Readme

kaniku

MVC microframework for cocos2d-x javascript games.

Kaniku (Japanese: かにく) means flesh of a coconut.

Model

Model is the main source of information about game objects. All data flow must come through models.

Models are able to emit events. Views, other models, etc. are allowed to emit events on behalf of the model.

Method to emit event:

emit: (listenKey, eventDataForListeners...)
player.emit('died', killer: 'red pacman ghost', killerLevel: 10)

Method to subscribe to events:

on: (listenKeys..., func)
player.on('win', (score) -> postScoreToTheSocialNetwork(score))

Example of model:

class PlayerModel extends kaniku.Model
  @defaults
    x: 0 # the view will update this variable
    y: 0
    timeAlive: 0
    timeAliveScoreFactor: 100

  @useUpdates()

  update: (dt) ->
    @setTimeAlive(@getTimeAlive() + dt)

  @computed 'score', depends: ['x', 'timeAlive', 'timeAliveScoreFactor']
  getScore: ->
    @getX() + @getTimeAlive() * @getTimeAliveScoreFactor()

defaults static method sets initial values of 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.

Getters and setters are available both method-style (m.getX(), m.setX(1)) and property-style (m.x, m.x = 1).

Generated setters emit event change:VARIABLE_NAME.

You can define computed variables via computed static method. This method makes change event of this computed variable to be emited on depending variable change. Also it creates property alias for getter.

useUpdates method requests controller to call model's update method on every frame. The first argument of update method is time between frames in seconds.

To get defaults of model you can use method getDefaults which is available both for class and for instances. To get all variables of model (including computed) you can use method getData.

View

View provides interface between model and real world. Usually views are cocos2d-x Node objects which render game objects on the user's screen.

There are no kaniku class to extend from.

Views don't communicate with each other. They communicate through models.

Controller

Controller is something like glue between all components of the game. It creates models and views and links them with each other.

Controllers are derived from cocos2d-x Scene class.

Updaters do some global work which may affect multiple views and models. Updaters are called each frame.

Updater can be any object which has update method (for example, kaniku.Updater) or it can be just a function.

Example:

class FirstLevelController extends kaniku.Controller
  createModels: ->
    @playerModel = new PlayerModel(x: 0, y: 100) # you can override initial values
    @addModel(@playerModel)

    @npcModel = new FirstLevelNPCModel()
    @npcModel.setPlayer(@playerModel)
    @addModel(@npcModel)

  createViews: ->
    uiLayer = new cc.Layer()

    scoreView = new ScoreLabelView() # suppose it extends from cc.Label
    scoreView.setPlayer(@playerModel)
    uiLayer.addChild(scoreView)

    @addChild(uiLayer, 2) # cc.Scene method

    gameWorldLayer = new GameWorldLayer()

    playerView = new PlayerView()
    # Suppose this object call physics engine internally and then
    # update player model with new coodinates.
    #
    # Score view will receive event that something was changed,
    # model will compute new score and then
    # score view will finally update the label on screen using model data.
    playerView.setPlayer(@playerModel)
    gameWorldLayer.addChild(playerView)

    @addChild(gameWorldLayer, 1)

  createUpdaters: ->
    @addUpdater (dt) =>
      @player.on 'change:x', (x) ->
        generateGameWorldAfter(x)