From here, are the "graphic.js" and the "object.js" files below. In this section is the graphics.js file. This graphics.js part below is linked to the: script src="graphics.js"> html script section that I wrote above. Basically, below is a seperate file that I used for Graphics, and to run the code above, make this graphics.js code that I post below here, a separate filed called: graphics.js
function Graphics(w,h,c) {
document.body.innerHTML += "<table style='position:absolute;font-
size:0;top:0;left:0;border-spacing:0;border-
width:0;width:"+w+";height:"+h+";background-color:"+c+";' border=1><tr><td>
</table>\n";
this.drawRectangle = function(x,y,w,h,c,n) {
document.body.innerHTML += "<div style='position:absolute;font-size:0;left:" + x +
";top:" + y + ";width:" + w + ";height:" + h + ";background-color:" + c + ";' id='"
+ n + "'></div>\n";
}
this.drawTexture = function(x,y,w,h,t,n) {
document.body.innerHTML += "<img style='position:absolute;font-size:0;left:" + x +
";top:" + y + ";width:" + w + ";height:" + h + ";' id='" + n + "' src='" + t + "'>
</img>\n";
}
this.drawObject = function(o) {
document.body.innerHTML += "<img style='position:absolute;font-size:0;left:" +
o.X + ";top:" + o.Y + ";width:" + o.Width + ";height:" + o.Height + ";' id='" +
o.Name + "' src='" + o.Sprite + "'></img>\n";
}
this.moveGraphic = function(x,y,n) {
document.getElementById(n).style.left = x;
document.getElementById(n).style.top = y;
}
this.removeGraphic = function(n){
document.getElementById(n).parentNode.removeChild(document.getElementById(n));
}
}
Finally, is the object.js file linked to the script src="object.js">" in the html game file above the graphics.js part I just wrote. Basically, this is a separate file too, so thus, in order to run or test the html game code in the very first section I wrote, a person has to also make this code below a separate file called: object.js
I hope this helps:
function Object(x,y,w,h,t,n) {
this.X = x;
this.Y = y;
this.Velocity_X = 0;
this.Velocity_Y = 0;
this.Previous_X = 0;
this.Previous_Y = 0;
this.Width = w;
this.Height = h;
this.Sprite = t;
this.Name = n;
this.Exists = true;
}
In all, this game is made based on a tutorial on youtube at: http://www.youtube.com/watch?v=t2kUzgFM4lY&feature=relmfu
I'm just trying to learn how to add animations with it now. I hope the above helps. If not, let me know. Thanks