开发者

ProcessingJS - loadImage() and loadStrings() path problem

I have a path problem when using loadImage() and loadStrings() in Processingjs. I would like to have my sketches and their associated files (images, text files) in one place and to be able to call them from another on my site.

For example, I am trying to run a Processingjs sketch located at www.example.com/sketches/mysketch.pde from the page www.example.com. This works fine when there are no external files.

Alas the problem starts when I need to use loadImage() and loadStrings() to look for images and texts to load. It defaults to www.example.com/image.jpg and not to the sketch location, www.example.com/sketches/image.jpg.

The need for @pjs preload makes matters worse.

Without moving the files and without hardcoding, is there a way to tell Processingjs to look for the files to load in the same folder as the 开发者_开发百科.pde and not the .html?

I hope this is clear. Any help would be appreciated!


Short answer: no.

Even native Processing won't behave the way you want in this sense, because you'll be executing your sketch from [...]/sketches/ and any resource call is local to that directory.

Similarly, with processing.js your resources are located relative to the "directory" you're in, which for www.example.com/ is just the base dir. What you can do, however, is place your .pde file in the same dir as your .html file, or vice versa.

@pjs preload is necessary to effect "immediate" file loading. If you don't preload it, your sketch will have to deal with asynchronous load instructions. Quite literally, loadImage without a preload directive behaves the same as requestImage (http://processing.org/reference/requestImage_.html)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜