Sprites don't work when created in onInitialize
See original GitHub issueSteps 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:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@eonarheim FYI I think there’s a mistake in your codepen (
actor.add
should beactor.addDrawing
). I was going to see if I could get this one taken care of, just thought you’d want to know.@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.