Scusate se disturbo ancora, ma sto provando a gestire le immagini tramite oggetti, ma non riesco a visualizzarle. Non è che qualcuno di molto gentile potrebbe darmi una mano?
codice html
Codice HTML:
<html>
<head>
<title>Avoid Them!</title>
<style>
#container {width:950px; height:400px; background-image:url(route1.png); margin-bottom:20px; border:1px solid black}
</style>
<script type="text/javascript" src="Objectz.js"></script>
<script>
var z,w;
var i=1;
var v=100;
var minh=235;
var maxh=75;
var car= new Macchina('car');
var zom = new Zombie('zom');
function changeimg(){
w=document.getElementById('container');
i=i+1;
if (i>2) {
i=1;
}
w.style.backgroundImage="url(route"+i+".png)";
}
function bground() {
z=setInterval(changeimg,v);
}
function up(){
car.goup();
}
function down(){
car.godown();
}
function findkey(e) {
key=e.keyCode;
if (key==38) {
var x=setTimeout(up,v);
}
if (key==40) {
var x=setTimeout(down,v);
}
}
</script>
</head>
<body onLoad="bground(),movezom()" onKeyPress="findkey(event)">
<div id='container'></div>
</body>
</html>
libreria objectz
Codice HTML:
function Macchina(id){
this.imgsrc='car.png';
this.img=document.createElement("img");
this.id=id;
this.img.style.position='absolute';
this.img.style.top='155px';
this.img.style.left='30px';
this.img.style.bottom='0';
this.img.src=this.imgsrc;
document.body.appendChild(this.img);
this.godown=function() {
var y=parseInt(this.img.style.top);
if (y<=minh) {
this.img.style.top=((y+40)+'px');
}
this.goup=function() {
var y=parseInt(this.img.style.top);
if (y>=maxh) {
this.img.style.top=((y-40)+'px');
}
}
function Zombie(id){
this.imgsrc='zombie.png';
this.img=document.createElement("img");
this.id=id;
this.img.style.position='absolute';
this.img.style.left='1400px';
this.img.style.bottom='0';
document.body.appendChild(this.img);
}