javascript - CraftyJS - viewport.centerOn() not working -
I am trying to create a 2D javascript game with the CraftyJS framework. But I'm stuck with the "center-on" feature
Here's the code:
Crafty.init (500, 350, document.getElementById ('game')). Background ('# eee'); Crafty.e ('earth, 2d, dome, canvas, color') .attr ({x: 0, y: 100, w: 480, h: 400}). Color ('# 6C3108'); Var hero = crafty.e ('Hero, 2D, Dome, Canvas, Color, Gravity, Crossing') .attr ({x: 60, y: 90, w: 10, h: 20}). Color ('# 338'). Seriousness ('Earth'). Fireway (4); Cunning Follow (Nayak, -60, 0); // Crafty.viewport.centerOn (Hero, 10); When you cancel the previous JavaScript line, then the method will not work:
- Hero is not at the center of the screen (on top screen is ).
- Hero's movement is broken (at least in my Chrome and Firefox)
Any ideas what I'm doing wrong?
Thanks for the reply
-
centering works properly Because, by default, by default, you can disable it from Crafty.viewport.clampToEntities = false in the visible set of clever clamps viewport organizations. (It often comes in sufficiently I doubt that it should be disabled by default!) -
Rendering is broken because you provide both DOM and Canvas components both to organizations - You should only use one of them.
-
Just like you know, like calling a viewport animation like centerOn to follow . (Or any other current animation.) is the working version of your code.
Comments
Post a Comment