question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sprites don't work when created in onInitialize

See original GitHub issue

Steps to Reproduce

I believe this is due to an issue with the backing canvas for sprites when created, the draw method (at least in firefox) does not allow for width/height drawings. I believe this is the fix https://github.com/excaliburjs/Excalibur/commit/bf4d8852925b3ecb5878baefe71e97dc6cf6b91b

https://codepen.io/eonarheim/pen/qYNeYM?editors=0011

let game = new ex.Engine({
  width: 600,
  height: 400
});

let tex = new ex.Texture('https://cdn.rawgit.com/excaliburjs/Excalibur/7dd48128/assets/sword.png');

let loader = new ex.Loader([tex]);

let actor = new ex.Actor(100, 100, 50, 50, ex.Color.Red);
actor.onInitialize = () => {
  let sprite = new ex.Sprite({
    image: tex,
    x: 0,
    y: 0,
    width: 100,
    height: 100
  });
  actor.add(sprite);
}
game.add(actor);
game.start(loader);

Expected Result

Textures have been loaded by initialize time, this style of sprite creation should work

Actual Result

A DOM exception results

Environment

excalibur@0.16.0

Current Workaround

None

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alanag13commented, Jul 14, 2018

@eonarheim FYI I think there’s a mistake in your codepen (actor.add should be actor.addDrawing). I was going to see if I could get this one taken care of, just thought you’d want to know.

1reaction
eonarheimcommented, Jun 19, 2018

@AimedNuu We will do our best to release this in 0.18.0, unfortunately we could not fit this into 0.17.0. We make bugs our top priority.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changing sprites on initialize doesn't work properly without ...
Hi guys! We have entities with sprites components and we load the assets on a custom load screen. We put the sprites on...
Read more >
angularjs - Dynamic instantiation of Components? - Stack Overflow
I can hard-code that a reference to that template into my "Level" ("app-sprite" tags) and it works but my attempts to generate "Sprites"...
Read more >
Can't create physics bodies inside… | Apple Developer Forums
I know the node is initialized as my custom class because the child sprite node does get created (I can see it), but...
Read more >
Mob Avail with Sprite Job It is not walking. · Issue #4505 - GitHub
Description of Issue: The monster created with class sprite doesn't walk, it just stands still and spinning, but when I use the command...
Read more >
PowerSprite Animator - Edit your sprite animations in style
Is it possible to set the list of sprites/frames of an animation uses through ... if i create a new animation and then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found