Same code does not work on another project
fgb01

Good morning people,
Does anyone know why the same code from one project does not work on another project?
The part of my code that does not work is the onkeyUp part.
When I copy and paste this part into another project it does not work.
Does anyone know why?
Thank you very much

var controles=
{
    esquerda: "left",
    direita: "right",
};
var veljogador = 100;

if(wade.isKeyDown(controles.esquerda)&&!wade.isKeyDown(controles.direita))
{
    this.setVelocity(-veljogador,0);    
}else if(wade.isKeyDown(controles.direita) &&!wade.isKeyDown(controles.esquerda))
{
    this.setVelocity(veljogador,0);    
}else{
    this.setVelocity(0,0);
}

//This part that does not work

this.onKeyUp = function(data){
    if(data.keyName==="space"){
        var tiro = wade.getSceneObject("Tiro").clone();
        tiro.setPosition(this.getPosition().x,this.getPosition().y-50);
        wade.addSceneObject(tiro);
        tiro.moveTo(this.getPosition().x,this.getPosition().y,-300);
    }
}

 

All 4 Comments
Gio

My guess is that the "this" keyword may have a different meaning, depending on where you are using it. Are you sure you are using "this" correctly there?

Just my guess though. If you can tell us the exact error message that you get, and also where you are pasting this code into, I might be able to be a bit more specific.

fgb01

I am using it in Update ...
Use this function to shoot with the spacebar ...

Gio

I would recommend splitting this into 2 parts. Keep the first part in onUpdate

var controles=
{
    esquerda: "left",
    direita: "right",
};
var veljogador = 100;

if(wade.isKeyDown(controles.esquerda)&&!wade.isKeyDown(controles.direita))
{
    this.setVelocity(-veljogador,0);    
}else if(wade.isKeyDown(controles.direita) &&!wade.isKeyDown(controles.esquerda))
{
    this.setVelocity(veljogador,0);    
}else{
    this.setVelocity(0,0);
}

Then edit the onKeyUp function of the object and paste this bit into it

    if(data.keyName==="space"){
        var tiro = wade.getSceneObject("Tiro").clone();
        tiro.setPosition(this.getPosition().x,this.getPosition().y-50);
        wade.addSceneObject(tiro);
        tiro.moveTo(this.getPosition().x,this.getPosition().y,-300);
    }
fgb01

thank you !

Post a reply
Add Attachment
Submit Reply
Login to Reply