Here's a CSS style for a small, pop-out text icon that displays feedback like "Great!", "Good", or "Bad" in your rhythm game. The design includes a subtle animation to make it feel like it's popping out when triggered.
HTML (for reference):
<div class="hit-feedback" id="hitFeedback"></div>
CSS:
.hit-feedback {
position: fixed; /* or absolute, depending on your layout */
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-family: 'Arial', sans-serif;
font-weight: bold;
font-size: 2rem;
color: white;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
padding: 0.5rem 1rem;
border-radius: 10px;
opacity: 0;
pointer-events: none; /* ensures it doesn't interfere with clicks */
z-index: 1000; /* ensures it's above other elements */
animation: popOut 0.5s ease-out;
}
/* Different styles for different feedback types */
.hit-feedback.great {
background-color: rgba(76, 175, 80, 0.8); /* Green */
color: white;
}
.hit-feedback.good {
background-color: rgba(33, 150, 243, 0.8); /* Blue */
color: white;
}
.hit-feedback.bad {
background-color: rgba(244, 67, 54, 0.8); /* Red */
color: white;
}
/* Animation for the pop-out effect */
@keyframes popOut {
0% {
opacity: 0;
transform: translate(-50%, -50%) scale(0.5);
}
50% {
opacity: 1;
transform: translate(-50%, -50%) scale(1.2);
}
100% {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
}
/* Optional: Fade out after appearing */
.hit-feedback.fade-out {
animation: fadeOut 0.5s ease-out forwards;
}
@keyframes fadeOut {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
JavaScript (to trigger the feedback):
function showHitFeedback(type) {
const feedback = document.getElementById('hitFeedback');
feedback.textContent = type === 'great' ? 'Great!' : type === 'good' ? 'Good' : 'Bad';
feedback.className = 'hit-feedback ' + type;
// Reset animation by re-adding the class
void feedback.offsetWidth; // Trigger reflow
feedback.classList.add('popOut');
// Remove the feedback after a delay
setTimeout(() => {
feedback.classList.add('fade-out');
}, 500);
}
// Example usage:
showHitFeedback('great'); // or 'good', 'bad'
Explanation:
- Positioning: The feedback is centered on the screen using
position: fixed and transform: translate(-50%, -50%).
- Styling: Different colors and text are used for "Great", "Good", and "Bad" feedback.
- Animation: The
popOut animation scales the element up quickly to create a "pop" effect.
- Fade-out: After appearing, the feedback fades out smoothly.
You can adjust the colors, sizes, and timings to match your game's aesthetic.