I am trying to make 2D JavaScript game with CraftyJS framework. But I am stuck with "centerOn" feature.
Here is the code: http://jsfiddle.net/R8ND7/17/
Crafty.init(500, 350, document.getElementById('game'))
.background('#eee');
Crafty.e('Earth, 2D, DOM, Canvas, Color')
.attr({x: 0, y: 100, w: 480, h: 400})
.color('#6C3108');
var hero = Crafty.e('Hero, 2D, DOM, Canvas, Color, Gravity, Fourway')
.attr({x: 60, y: 90, w: 10, h: 20})
.color('#338')
.gravity('Earth')
.fourway(4);
Crafty.viewport.follow(hero, -60, 0);
// Crafty.viewport.centerOn(hero, 10);
When you uncomment last JavaScript line, you will see the method not working:
- Hero is not in center of the screen (he is on top screen).
- Hero's movement rendering is broken (at least in my Chrome and Firefox).
Any ideas what am I doing wrong?
Thanks for answers.