How to move an object using X and Y coordinates in JavaScript

Posted by Geroy290 on Game Development See other posts from Game Development or by Geroy290
Published on 2014-05-31T02:14:17Z Indexed on 2014/05/31 3:56 UTC
Read the original article Hit count: 233

Filed under:
|
|
|
|

I am making a 2d game with JavaScript and HTML5 and am trying to move an image that I have drawn with JavaScript like so:

    //canvas
    var c = document.getElementById("gameCanvas");
    var ctx = c.getContext("2d");
    //baseball
    var baseball = new Image();
    baseball.onload = function() {
        ctx.drawImage(baseball, 400, 425);
    };
    baseball.src = "baseball2.png";

I'm not sure how I would move it though, I have seen many people seem to just type something like ballX and ballY but I don't understand where the actual x and y definition comes from. Here is my code so far:

http://jsfiddle.net/xRfua/

I have a different image source but it is a local source so I couldn't include it. Thanks in a dvance for any help!

© Game Development or respective owner

Related posts about 2d

Related posts about JavaScript