javascript - How to make object move in js? -
i'm trying learn object oriented programming in javascript try make simple game. make character moves. there code in js: function move(event) { var k=event.keycode; var chr = { updown : function (){ var y=0; if (k==38) {--y; }else if (k==40) {++y;} return y; }, leftright : function (){ var x=0; if (k==37) {--x; }else if (k==39) {++x;} return x; } }; chrid.style.top = (chr.updown())+"px"; chrid.style.left = (chr.leftright())+"px"; } html: <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href="jumpopp.css"> <script src="jumpopp.js"></script> </head> <body onkeydown="move(event)"> <img id="chrid" src="trackingdot.png"...