Question
I'm developing a basic game application that works in the simulator, but fails when running on an actual device. The error I'm getting is:
TypeError: 'undefined' is not a function (evaluating 'window.requestAnimationFrame(...)')
It seems Chrome supports this animation function, but I'm encountering issues with Tizen. Could this be due to version differences? Please advise on how to properly use requestAnimationFrame in Tizen.
Answer
Problem Understanding
The issue occurs because window.requestAnimationFrame isn't natively supported in some Tizen versions. While modern browsers like Chrome implement this feature, certain Tizen platforms might require alternative approaches.
Solution Methods
- Use vendor-prefixed version: Try using
window.webkitRequestAnimationFrameas a fallback - Implement a polyfill: Create a compatibility layer for unsupported platforms
- Use setTimeout alternative: As a last resort, fall back to setTimeout with 60fps timing
Code Examples
// Solution 1: Vendor-prefixed version
var requestAnimFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame;
// Solution 2: Polyfill implementation
if (!requestAnimFrame) {
requestAnimFrame = function(callback) {
return window.setTimeout(callback, 1000/60);
};
}
// Usage example
function animate() {
// Your animation code here
requestAnimFrame(animate);
}
animate();
Additional Tips
- Test your application on different Tizen versions to ensure compatibility
- Consider using Tizen's native animation APIs for better performance
- Monitor frame rate to ensure smooth animation performance