アニメーションをレンダリングするためにこのコードを作成しました。これは1つのアニメーションでうまくいくようです。しかし、オブジェクトの2つ以上のインスタンスを作成しようとすると、すべてが混ざり合って、何もレンダーされなくなります。JavaScriptで1つのオブジェクトのインスタンスを2つ作成できません
var animate = function(id,sprite){
var sprites = sprite;
var imageID = id;
var arize = document.getElementById(imageID);
var spriteID;
var animationSprites;
console.log("before switch: sprite: " + sprite + "imageID: " + imageID + "element: " + arize + "animationSprites: " + animationSprites)
switch(sprites) {
case "appear":
animationSprites = appear;
spriteID = "appear";
break;
case "die":
animationSprites = die;
spriteID = "die";
break;
case "slap":
animationSprites = slap;
spriteID = "slap";
break;
case "walk":
animationSprites = walk;
spriteID = "walk";
break;
default:
animationSprites = idle;
spriteID = "idle";
}
console.log(sprites.length)
console.log("after switch: sprite: " + sprite + "imageID: " + imageID + "element: " + arize + "animationSprites: " + animationSprites)
this.animateThis = function() {
arize.src = animationSprites[i];
i++;
setTimeout(function() {
if (i < animationSprites.length) {
console.log(i)
showings();
if (i== animationSprites.length -1) {
i=0;
}
}
},50);
}
function showings() {
var showZombieTwo = new animate("imgs", "slap");
showZombieTwo.animateThis();
//var showZombieOne = new animate("imgs1", "idle");
//showZombieOne.animateThis();
}
複数のアニメーションを同時にレンダリングするにはどうすればよいですか?
このI変数はそうのような機能上記で定義されているピクチャ –