melonJS icon indicating copy to clipboard operation
melonJS copied to clipboard

Problem with Renderables

Open aaschmitz opened this issue 13 years ago • 2 comments

Hi

Some issues I have detected with lastest 0.9.9 version (25/08):

  1. When running the code (in entity update) this.renderable.angle += 0.01; if the entity is in contact with some collision map (for example, one tile with type "solid" in Tiled), the entity is not rotated. If the same code is run without the entity is in contact with some collision, the same works.

  2. In the code:

init: this.renderable = game.texture.createAnimationFromName([ "texture1.png", "texture2.png", "texture3.png"]); this.renderable.addAnimation ("walk", [0, 1]); this.renderable.addAnimation ("crouch", [2]);

update: if (me.input.isKeyPressed("crouch")) this.renderable.setCurrentAnimation("crouch"); else if (me.input.isKeyPressed("left")) { this.renderable.setCurrentAnimation("walk"); this.flipX(true); this.vel.x = -this.accel.x * me.timer.tick; } else if (me.input.isKeyPressed("right")) { this.renderable.setCurrentAnimation("walk"); this.flipX(false); this.vel.x = this.accel.x * me.timer.tick; } else this.vel.x = 0;

If I press an arrow key and then the "crouch" key, the crouch animation is displayed. if I am stopped and press straight down the crouch key, the animation is not executed.

  1. The message is shown in the browser console (Google Chrome): "Uncaught TypeError: Cannot call method 'getEntityByProp' of null melonJS-0.9.9.js: 1264"

Very Important: the issues above not exist with version 0.9.9 of the day 24/07 I was using. If I return to the other version, they disappear.

Thanks!

aaschmitz avatar Aug 25 '13 20:08 aaschmitz

Hi!

  1. Sounds like you may not be returning the proper value in your ObjectEntity's update() method. It should always be returning true if you want to redraw the object. For example, you may be returning false when the velocity is zero, or something.
  2. Again, you have to return true in your update() method if you want the redraw to happen. After setting the animation to "crouch", you could return true to display that animation frame.
  3. That one is odd; a full stack trace would help determine the cause of it.

The big thing that changed after 24/07 was the addition of ObjectContainer (#59). But it doesn't really explain why that would break code that seems to work before.

Could you share the "broken" source? I can have a look to see which code is at fault. Thanks!

parasyte avatar Aug 25 '13 20:08 parasyte

Hi Jay

About the itens 1 and 2, the code below is in the end of update() method:

if ((this.vel.x !== 0) || (this.vel.y !== 0)) { this.parent(); return true; } return false;

And now it's:

this.parent(); return true;

And works! The big question is because that coming back to version 0.9.9 of 24/07 the problems disappear? I did not change anything in the code, only the version of the engine.

About the item 3, I have used the last 0.9.9 version of 25/08, including the last version of debugPanel plugin and the error is gone!

Anyway thanks again and sorry for the inconvenience :(

aaschmitz avatar Aug 26 '13 02:08 aaschmitz