I have a strange problem with javascript at the moment. I'm so much used to Java so I get very frustated when it doesn't work out in the same way. I have a function Jet that is a plane which I try to move. Then I have the x += dx; in my move-function as usual.
dx is 0 at the beginning. When I change it to 1 or 2 or something it works fine and my Jet moves, but I want to start with 0 and then I want to change dx to 1 when pressing the keyboard. That is no problem at all in Java, but this I don't understand. Nothing happens...
At the top I have
var jet1 = Jet();
function Jet()
{
var x = 200;
var y = 300;
var dx = 0;
var dy = 0;
var Jet = function()
{
}
Jet.prototype.draw = function(){
jet1.update();
ctxJet.drawImage(plane, x, y);
}
Jet.prototype.setDX = function(speed)
{
dx = speed;
}
Jet.prototype.getX = function()
{
return x;
}
Jet.prototype.getY = function()
{
return y;
}
Jet.prototype.update = function(){
ctxJet.clearRect(0, 0, 800, 600);
}
Jet.prototype.move = function()
{
x += dx;
y += dy;
return this;
}
return new Jet();
}
// And here is the keyboard which doesn't work (the keyboard input works, but not the variable change)
function checkKeyDown(e) {
var keyID = e.keyCode || e.which;
if (keyID === 38 ) { //up arrow
jet1.setDX = 1;
jet1.dx = 1;
}
}
How am I supposed to solve this? I can't reach and change the variable.
Edited by Patriarch K, 25 February 2013 - 04:21 PM.






