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:

  1. Hero is not at the center of the screen (on top screen is ).
  2. Hero's movement is broken (at least in my Chrome and Firefox)

    Any ideas what I'm doing wrong?

    Thanks for the reply

    1. 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!)

    2. Rendering is broken because you provide both DOM and Canvas components both to organizations - You should only use one of them.

    3. 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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -