0

I'm working on a project that requires me to control paper via javascript rather than using the normal paperscript route. I'm currently stuck because of a weird behavior that I can't seem to figure out. Here's a simplified version of the code I'm running

paper.install(window);
$(document).ready(function() { 
    paper.setup("canvas");
    Game.ship = new Ship(view.center, 1) // Essentially calls new Raster("imgid"); and positions it
    view.draw(); 
});

For some reason, this code is resulting in a blank canvas. What's weird is that if I call new Ship(...) in my dev console after a few seconds, the raster renders just fine on the canvas, as it should. I've also noticed that when I look at the value of Game.ship.elem.__canvas, I see a canvas element with a size of 32, 32, even though no such canvas exists in the DOM.

I'm assuming this has something to do with timing, but I can't seem to figure out what I have to do to make it work, other than the incredibly messy approach of using a setTimeout to create the raster a few seconds after $(document).ready() is called.

Anyone have any ideas as to what's going on here, or something that could lead me in the right direction?

1 Answer 1

2

Actually I managed to figure it out on my own. For anyone who's running into this, the problem was actually because the ready() function was being called before the image had finished loading.

Because of this, the new Raster() call was loading a nonexistant image into the canvas, causing a blank result!

Sign up to request clarification or add additional context in comments.

1 Comment

I ran into the same thing when working with paper rasters. I ended up using imagesloaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.