万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

CoffeScriptでcocos2d-JSの3.xのマウス対応

cocos2d-js v2.2.x -> v3.0beta アップグレードログ - Qiita

このようにonEnter()メソッド内に記載する。

EventManager Mechanism | Documents | Cocos2d-x の方が詳しい。

    onEnter:() ->
        this._super(
        # マウス系
            cc.EventListener.create(
                event: cc.EventListener.MOUSE
                onMouseMove: (event) ->
                    str = "MousePosition X: " + event.getLocationX() + "  Y:" + event.getLocationY()
                    # do something...
                onMouseUp: (event) ->
                    str = "Mouse Up detected, Key: " + event.getButton()
                    # do something...
                onMouseDown: (event) ->
                    str = "Mouse Down detected, Key: " + event.getButton()
                    # do something...
                onMouseScroll: (event) ->
                    str = "Mouse Scroll detected, X: " + event.getLocationX() + "  Y:" + event.getLocationY()
                    # do something...
                ), this)
        # キーボード系
        cc.eventManager.addListener(
            cc.EventListener.create(
                event: cc.EventListener.KEYBOARD
                onKeyPressed:  (keyCode, event) ->
                    label = event.getCurrentTarget()
                    label.setString("Key " + keyCode.toString() + " was pressed!")
                onKeyReleased: (keyCode, event) ->
                    label = event.getCurrentTarget()
                    label.setString("Key " + keyCode.toString() + " was released!")
            ), this)

つくって覚えるCoffeeScript入門

つくって覚えるCoffeeScript入門

Cocos2d-x Game Development Essentials

Cocos2d-x Game Development Essentials