Aller au contenu

Understanding AYS Charts and Music Game Engines

Ce contenu n’est pas encore disponible dans votre langue.

💡 Building a rhythm game engine? Need help with music synchronization and chart systems? 🎵 Get Music Game Help

RD

RhythmGameDev

Posted on January 24, 2024 • Advanced

🎵 How do AYS Charts work in rhythm game engines?

Hey everyone! I’m fascinated by rhythm games and I want to create my own AYS/SSS engine from scratch. I’ve been studying existing engines but I’m completely lost when it comes to understanding chart data.

Specifically, I need help understanding:

  • What each value in a chart line represents
  • How timing and beat mapping works
  • Note types and their data structure
  • How to parse and interpret chart files
  • Synchronizing notes with music playback

I’ve looked at some AYS engines and found the Chart lists, but the data format is still a mystery to me. Any guidance on how these systems work would be amazing! 🎮

ME

MusicEngine_Expert

Replied 5 hours later • ⭐ Best Answer

Great question @RhythmGameDev! AYS charts are fascinating systems. Let me break down how they work and help you build your own engine:

🎼 AYS Chart Structure Overview

Here’s how a typical rhythm game engine processes charts:

flowchart TD A[🎵 Music File] --> B[📊 Chart Data] B --> C[⏱️ Timing Engine] C --> D[🎯 Note Spawner] D --> E{Note Type?} E -->|Tap| F[👆 Single Note] E -->|Hold| G[📏 Long Note] E -->|Slide| H[↗️ Directional Note] F --> I[🎮 Input Detection] G --> I H --> I I --> J[📈 Score Calculation] J --> K[✨ Visual Effects] C --> L[🔄 Beat Sync] L --> M[📱 Game Update] M --> N{Song End?} N -->|No| C N -->|Yes| O[🏆 Results] style A fill:#e1f5fe style B fill:#f3e5f5 style C fill:#e8f5e8 style J fill:#fff3e0 style O fill:#fce4ec

📋 Chart Data Format Explained

A typical AYS chart line contains these values:

    // Chart data format: [Time, Lane, Type, Duration, Extra]
// Example chart entries:
set [chart data v] to [
1000,1,1,0,0|    // Tap note at 1 second, lane 1
1500,2,1,0,0|    // Tap note at 1.5 seconds, lane 2
2000,3,2,500,0|  // Hold note at 2 seconds, lane 3, 500ms duration
2500,1,3,0,2|    // Slide note at 2.5 seconds, lane 1, direction 2
]

// Parse chart data
define parse chart line (chart line)
set [note data v] to (split (chart line) by [,])
set [note time v] to (item [1] of [note data v])     // When to spawn (milliseconds)
set [note lane v] to (item [2] of [note data v])     // Which lane (1-4 typically)
set [note type v] to (item [3] of [note data v])     // 1=tap, 2=hold, 3=slide
set [note duration v] to (item [4] of [note data v]) // For hold notes (milliseconds)
set [note extra v] to (item [5] of [note data v])    // Direction, color, etc.
  

⏰ Timing Engine Implementation

The core of any rhythm game is precise timing:

    // Main timing engine
when flag clicked
set [song start time v] to (timer)
set [current chart index v] to [1]
set [bpm v] to [120] // Beats per minute
set [beat duration v] to ((60 / (bpm)) * [1000]) // Milliseconds per beat

forever
set [current time v] to (((timer) - (song start time)) * [1000]) // Convert to milliseconds

// Check if it's time to spawn the next note
if <(current chart index) ≤ (length of [chart data v])> then
set [next note time v] to (item [1] of (split (item (current chart index) of [chart data v]) by [,]))

if <(current time) ≥ ((next note time) - [1000])> then // Spawn 1 second early
spawn note (item (current chart index) of [chart data v])
change [current chart index v] by [1]
end
end

// Update all active notes
update all notes
end
  

🎯 Note Spawning System

Create and manage different types of notes:

    // Note spawning and management
define spawn note (note data)
set [note info v] to (split (note data) by [,])
set [spawn time v] to (item [1] of [note info v])
set [lane v] to (item [2] of [note info v])
set [type v] to (item [3] of [note info v])
set [duration v] to (item [4] of [note info v])

// Create note sprite
create clone of [Note v]

// Set note properties
when I start as a clone
set [my spawn time v] to (spawn time)
set [my lane v] to (lane)
set [my type v] to (type)
set [my duration v] to (duration)

// Position note based on lane
if <(my lane) = [1]> then
set x to [-150]
else
if <(my lane) = [2]> then
set x to [-50]
else
if <(my lane) = [3]> then
set x to [50]
else
set x to [150]
end
end
end

// Start at top of screen
set y to [200]
show
  

📱 Note Movement and Timing

Make notes move down the screen with perfect timing:

    // Note movement system
when I start as a clone
forever
set [current game time v] to (((timer) - (song start time)) * [1000])

// Calculate how far the note should have traveled
set [time until hit v] to ((my spawn time) - (current game time))
set [travel distance v] to [400] // Total distance from spawn to hit line
set [fall speed v] to ((travel distance) / [1000]) // pixels per millisecond

// Position note based on timing
set y to ((time until hit) * (fall speed))

// Check if note has passed the hit line
if <(y) < [-200]> then
// Note missed
broadcast [note missed v]
delete this clone
end

// Handle different note types
if <(my type) = [2]> then // Hold note
set size to (100) %
set [ghost v] effect to [0]
// Draw hold trail
pen down
set pen color to [#00ff00]
set pen size to [20]
else
pen up
end
end
  

🎮 Input Detection and Scoring

Detect player input and calculate scores:

    // Input detection system
when [space v] key pressed // Lane 1
check hit (1)

when [d v] key pressed // Lane 2
check hit (2)

when [k v] key pressed // Lane 3
check hit (3)

when [right arrow v] key pressed // Lane 4
check hit (4)

define check hit (lane)
set [best hit v] to [none]
set [best timing v] to [999]

// Find the closest note in this lane
repeat (length of [active notes v])
set [note v] to (item (counter) of [active notes v])
set [note lane v] to (item [2] of (split (note) by [,]))

if <(note lane) = (lane)> then
set [note time v] to (item [1] of (split (note) by [,]))
set [timing difference v] to (abs ((current game time) - (note time)))

if <(timing difference) < (best timing)> then
set [best timing v] to (timing difference)
set [best hit v] to (note)
end
end
end

// Score the hit
if <(best timing) < [50]> then
say [Perfect!] for [0.5] seconds
change [score v] by [1000]
play sound [perfect hit v]
else
if <(best timing) < [100]> then
say [Great!] for [0.5] seconds
change [score v] by [500]
play sound [good hit v]
else
if <(best timing) < [150]> then
say [Good] for [0.5] seconds
change [score v] by [200]
play sound [ok hit v]
end
end
end

// Remove hit note
if <not <(best hit) = [none]>> then
delete (position of (best hit) in [active notes v]) of [active notes v]
end
  

🎨 Advanced Chart Features

Add more complex note types and effects:

    // Advanced note types
define handle special notes (note type) (extra data)
if <(note type) = [3]> then // Slide note
set [slide direction v] to (extra data)
if <(slide direction) = [1]> then // Slide left
glide [0.2] secs to x: ((x position) - [100]) y: (y position)
else
if <(slide direction) = [2]> then // Slide right
glide [0.2] secs to x: ((x position) + [100]) y: (y position)
end
end
else
if <(note type) = [4]> then // Flick note
set [flick v] effect to [100]
repeat [10]
change [flick v] effect by [-10]
wait [0.02] seconds
end
else
if <(note type) = [5]> then // Multi-tap
set [hits required v] to (extra data)
set [current hits v] to [0]
// Handle multiple hits on same note
end
end
end

// BPM changes and timing adjustments
define handle bpm change (new bpm) (change time)
if <(current game time) ≥ (change time)> then
set [bpm v] to (new bpm)
set [beat duration v] to ((60 / (bpm)) * [1000])
// Recalculate note timings
end
  

🔧 Chart Editor Tools

Create tools to make your own charts:

    // Simple chart editor
when flag clicked
set [editor mode v] to [true]
set [current beat v] to [0]
set [snap to beat v] to [true]

forever
if <(editor mode) = [true]> then
// Show beat grid
clear
pen up
repeat [20]
go to x: [-200] y: ((counter) * [20])
pen down
go to x: [200] y: ((counter) * [20])
pen up
end

// Place notes with mouse
if <mouse down?> then
set [click lane v] to (round (((mouse x) + [200]) / [100]))
set [click time v] to (((mouse y) + [200]) / [20])

if <(snap to beat) = [true]> then
set [click time v] to (round ((click time) / (beat duration)) * (beat duration))
end

// Add note to chart
set [new note v] to (join (join (join (join (click time) [,]) (click lane)) [,1,0,0]))
add (new note) to [chart data v]

wait [0.2] seconds // Prevent multiple placements
end
end
end
  

This should give you a solid foundation for understanding and building AYS-style rhythm game engines! The key is precise timing, good data structures, and smooth visual feedback. 🎵

RD

RhythmGameDev

Replied 2 hours later

@MusicEngine_Expert This is absolutely incredible! Thank you so much! 🎉

I finally understand how the chart data works. I got a basic engine running with tap notes. One question - how do I handle audio synchronization to make sure the notes line up perfectly with the music?

AS

AudioSync_Master

Replied 1 hour later

@RhythmGameDev Great question about audio sync! Here’s the key:

    // Audio synchronization
when flag clicked
// Calibrate audio delay
set [audio delay v] to [100] // Adjust based on testing

// Start music with timing reference
set [music start time v] to (timer)
play sound [song v] until done

// Adjust all note timings
define get adjusted time
set [raw time v] to (((timer) - (music start time)) * [1000])
set [adjusted time v] to ((raw time) - (audio delay))
return (adjusted time)
  

The key is calibrating the audio delay and testing with different devices! 🎧

VB

Vibelf_Community

Pinned Message • Moderator

🎵 Ready to Create Professional Music Games?

Fantastic discussion on rhythm game development! For those looking to build more advanced music games, our expert tutors can help you master:

  • 🎼 Advanced chart formats and parsing
  • 🎧 Professional audio synchronization
  • 🎨 Dynamic visual effects and shaders
  • 📊 Complex scoring and ranking systems
  • 🌐 Online leaderboards and multiplayer

📚 Related Music Game Topics

Transform your music game ideas into reality with expert guidance from our specialized instructors!