.center-container {
height: 100vh;
/* Utilize the entire viewport height */
display: flex;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
/* Optional: modify the background color */
}
.pikaqiu_run {
width: 80px;
/* Width of a single frame */
height: 71px;
/* Height of each frame */
background: url('https://game.gtimg.cn/images/nishiki/web202310/pkq_ani.png') 0 0 no-repeat;
animation: run-animation 0.5s steps(8, end) infinite;
}
@keyframes run-animation {
from {
background-position: 0 0;
}
to {
background-position: -640px 0;
}
/* Adjust this based on total width of all frames */
}
<!DOCTYPE html>
<html lang="en">
<body>
<div class="center-container">
<div class="pikaqiu_run"></div>
</div>
</body>
</html>
Implements an animation as defined by @keyframes
. This animation has a duration of 0.5 seconds with 8 steps (assuming there are 8 frames in a row), and it repeats infinitely.
@keyframes
run-animation specifies how the background position transitions from the initial frame to the final one. The value -640px
needs adjustment according to the combined width of all frames in your sprite sheet (e.g., if each frame is 80px wide and there are 8 frames, then 80px × 8 = 640px).