I'm a graphic artist and totally new to coding. I'm trying to make a simple HTML5 based game mock-up. What I want to do is to swap one sprite animation to the other sprite animation onclick. Each sprite animation's got different size and number of frames.
Animation on the first image is already on, when click on the image, that animation will get replaced by the another animation. When that switch was made, the score animation (another sprite animation) shows up.
I've tried many different Javascript but no good outcome so far. I could only come up with one script and it just doesn't work. (two images overlap each other) I'm sure i'm doing something totally wrong but I really need you guys help.
function change(){
var image = document.getElementById('pupwag01');
image.src = "images/pup01-win-sprite.png";
}
#null01{
position: absolute;
top: 700px;
left: 100px;
}
#pupwag01 {
background-image: url('../images/puppy01sprite.png');
width: 173px;
height: 221px;
position: relative;
animation: pupwag01 1s steps(6) infinite;
}
@keyframes pupwag01 {
0% {background-position: 0px;}
100% {background-position: -1038px;}
}
#null01a{
position: absolute;
top: 680px;
left: 50px;
}
#pupwin01 {
background-image: url('../images/pup01-win-sprite.png');
width: 308px;
height: 191px;
position: relative;
animation: pupwin01 .5s steps(3) infinite;
background-repeat: no-repeat;
}
@keyframes pupwin01 {
0% {background-position: 0px;}
100% {background-position: -924px;}
}
#nullscore01{
position: absolute;;
top: 600px;
left: 110px;
}
#score01{
background-image: url('../images/score-sprite01.png');
width: 150px;
height: 200px;
position: relative;
animation: score01 1s steps(24) 1;
}
@keyframes score01 {
0% {background-position: 0px;}
100% {background-position: -3600px;}
}
<body>
<header>
</header>
<div class="p-box">
<img src="images/pup-logo.png" id="logo">
<div id= "null01"><img src="images/puppy01sprite.png" id="pupwag01"></div></div>
<div id= "null01a"><div id="pupwin01"></div></div>
<div id= "null02"><div id="pupwag02"></div></div>
<div id= "null02a"><div id="maddog"></div></div>
<div id= "null03"><div id="pupwag03"></div></div>
<div id= "null03a"><div id="pupwin03"></div></div>
<div id= "null04"><div id="pupwag04"></div></div>
<div id= "null04a"><div id="pupwin04"></div></div>
<div id= "null05"><div id="pupwag05"></div></div>
<div id= "null05a"><div id="pupwin05"></div></div>
<div id="nullscore01"><div id="score01"></div></div>
<div id="nullscore03"><div id="score03"></div></div>
<div id="nullscore04"><div id="score04"></div></div>
<div id="nullscore05"><div id="score05"></div></div>
<div id="blink_text">Pick a Puppy!</div>
<div id="nullgo"><div id="gameover"></div></div>
</div>
<script src = "js/main.js" type="text/javascript"></script>
</body>
</html>