Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Problema para para a nave

Não está pegando quando eu solto o "a". Fiz quase tudo igual, mas quando a nave começa a andar ela não para mais. o console diz que o problema é que a tecla "a" não está definida, mas já não sei mais o que fazer. Alguém poderia apontar o problema no meu código? (CC V2.0.2)

// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        _acelerando:false
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.teclaPressionada, this);
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.teclaSolta, this);
    },

    teclaPressionada(event){
        if(event.keyCode ==  cc.macro.KEY.a){
            this._acelerando = true;
        }
    },
    teclaSolta(event){
        if(event.keyCode == cc.macro.Key.a){
            this._acelerando = false;
        }
    },
    start () {

    },

    update (dt) {
        if(this._acelerando){
            this.node.x += -1;
        }
    },
});
1 resposta
solução!

Já descobri o problema. Era o "key" que escrevi em minúsculo

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software