Closed jorisvddonk closed 11 years ago
Demo for bug 2: Original: http://mooses.nl/misc/jaws/bug2/orig/ (also demonstrates bug#1) Fixed version: http://mooses.nl/misc/jaws/bug2/fixed/ (also fixes bug#1)
(see the console for the number of draw() calls)
Hi Joris, nice find and fix! Do you think you could add proper support for repeat_x etc and make a pull-request? I would be happy to merge it. A bonus would be some test-cases as well :).
Supporting repeat_x and repeat_y should be possible, yeah. I'll see what I can do and when I can do it.
Not sure about QUnit test-cases, though. Although I've done some QUnit tests before, I can't say I'm very familiar with it. Besides, properly testing bug#2 may mean that I have to temporarily replace the Sprite.draw method with something else that logs the number of calls. I'm not sure if that's acceptable behaviour in a test-case.
Hmm. I've started writing tests, but for some reason my test parallaxLayer's width and height aren't being set correctly, which breaks my test. Is there some timing thing I need to keep in mind when writing tests? I'm using assets/rect.png for my layer.
Oddly enough, when I console.log(parallax.layer[0].width) I get Undefined as a result, but if I console.log(parallax.layer[0]) and later on inspect the parallax layer in Chrome, I do see a width variable set.
EDIT: Fixed it. Had to use jaws.assets.getOrLoad
Done. Repeat_y and repeat_x support added, and pull-request sent.
How about marking this as closed?
good call.
The Parallax drawing code contains two bugs:
1) It doesn't work correctly with a vertically scrolling parallax (http://mooses.nl/misc/jaws/bug1/orig/) 2) It draws way too many sprites when the camera X and/or Y coordinates have a high value. (in fact, all sprites between the top-left corner of the game world and the current camera position are drawn!)
I've squashed both bugs in my fork of jaws (see https://github.com/jorisvddonk/jaws/blob/master/src/parallax.js) Unfortunately, I didn't get around to adding in proper support for options.repeat_x, options.repeat_y and options.scale.