1 2 3 4 5 6 7 8 9 10 11 12 13 | var BACKGROUND_VELOCITY = 42, // pixels / second bgVelocity = BACKGROUND_VELOCITY; function setBackgroundOffset() { var offset = backgroundOffset + bgVelocity/fps; // Time-based motion if (offset > 0 && offset < background.width) { backgroundOffset = offset; } else { backgroundOffset = 0; } } |
1 2 3 4 5 6 7 8 9 10 | var PLATFORM_VELOCITY_MULTIPLIER = 4.35; function setPlatformVelocity() { // Platforms move 4.35 times as fast as the background platformVelocity = bgVelocity * PLATFORM_VELOCITY_MULTIPLIER; } function setPlatformOffset() { platformOffset += platformVelocity/fps; // Time-based motion } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function setOffsets() { setBackgroundOffset(); setPlatformOffset(); } function draw() { setPlatformVelocity(); setOffsets(); drawBackground(); drawRunner(); drawPlatforms(); } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |