I’m trying to apply an effect to a series of balls dropping down the screen. I’ve created a snapshot the same size as the screen. I just can’t get anything useful out of it. Using a mac.
Ok first off you’ll have to accept snapshots are a bit buggy for now.
But essentially the idea is that it works like a group or container, but it only updates when you want.
The docs point out that some things don’t quite work how they would with groups (the example is with transparency) but there is a super simple way around this: stick a group inside the snapshot and place all your bits within said group instead of directly in the snapshot.
One thing to remember is that snapshots center around 0, 0 so if you specify a width and height of (say) 200 and then place things more than 100 pixels to the right or down, they won’t show.
Also, if you create a snapshot equal in size to the screen but fail to move it to display.contentWidth / 2, display.contentWidth / 2 it will only show things in the top left corner (and likely from your point of view, offset incorrectly).
Also, obviously don’t forget to :invalidate() to update (although this is not necessary for the first time if you create it andthen immediately place objects into it).
Now, if you still don’t see anything after factoring in all of the abovem you might be encountering the bug that has been plaguing me with my tests - that often times snapshots just plain don’t work correctly. It manifests itself in one of 2 ways - you never see anything in the snapshot after the first time (way to test - never invalidate the snapshot to see if it shows something initially), or it updates but flickers (way to test - dramatically lower the time intervals of your invalidates - less than once a second will normally ‘fix’ in this case just to test).
Now what to do in these cases. Simplify your snapshot in the sense that it should not be nested in a container (this seems to be a major cause of bugs, including crashing the simulator if you removeself() it and later create more snapshots / containers.
If you see your snapshot flickering, then you can either live with it in the simulator (this does not happen on ipad) or you can attemot to restart it repeatedly until it does works properly. Trust me, this gets real old real quickly (in my dungeon game I now just use 1 player for testing in the simulator, and I swap my snapshot for a normal display group so it doesnt have this bug. I lose the filters, but it beats spending 20-30 seconds hoping it works every single time you run the bloody thing. in the simulator and hammering control+R like a crazy person). Again, on device, it runs fine.
Som what if it is none of the above?
Well, you could post a short code snippet. I’ve already got a small but self contained bit of snapshot code floating around here on the forums that actually uses 2 nested snapshot objects to enable a painting like program (and now I think aout it, the darned thing should work properly on ipad as I now realise my complaints about it are due to ine of the aove bugs). I’ll find a link.
Now why is it that returns in an original post from the ipad dont show yet if I edit the post they do? Grrrrr…
Anyway here is thecthread with some hopefully working snapshot code: http://forums.coronalabs.com/topic/39133-dp20-how-about-invalidation-of-children-without-clearing-cashed-image/
Ok first off you’ll have to accept snapshots are a bit buggy for now.
But essentially the idea is that it works like a group or container, but it only updates when you want.
The docs point out that some things don’t quite work how they would with groups (the example is with transparency) but there is a super simple way around this: stick a group inside the snapshot and place all your bits within said group instead of directly in the snapshot.
One thing to remember is that snapshots center around 0, 0 so if you specify a width and height of (say) 200 and then place things more than 100 pixels to the right or down, they won’t show.
Also, if you create a snapshot equal in size to the screen but fail to move it to display.contentWidth / 2, display.contentWidth / 2 it will only show things in the top left corner (and likely from your point of view, offset incorrectly).
Also, obviously don’t forget to :invalidate() to update (although this is not necessary for the first time if you create it andthen immediately place objects into it).
Now, if you still don’t see anything after factoring in all of the abovem you might be encountering the bug that has been plaguing me with my tests - that often times snapshots just plain don’t work correctly. It manifests itself in one of 2 ways - you never see anything in the snapshot after the first time (way to test - never invalidate the snapshot to see if it shows something initially), or it updates but flickers (way to test - dramatically lower the time intervals of your invalidates - less than once a second will normally ‘fix’ in this case just to test).
Now what to do in these cases. Simplify your snapshot in the sense that it should not be nested in a container (this seems to be a major cause of bugs, including crashing the simulator if you removeself() it and later create more snapshots / containers.
If you see your snapshot flickering, then you can either live with it in the simulator (this does not happen on ipad) or you can attemot to restart it repeatedly until it does works properly. Trust me, this gets real old real quickly (in my dungeon game I now just use 1 player for testing in the simulator, and I swap my snapshot for a normal display group so it doesnt have this bug. I lose the filters, but it beats spending 20-30 seconds hoping it works every single time you run the bloody thing. in the simulator and hammering control+R like a crazy person). Again, on device, it runs fine.
Som what if it is none of the above?
Well, you could post a short code snippet. I’ve already got a small but self contained bit of snapshot code floating around here on the forums that actually uses 2 nested snapshot objects to enable a painting like program (and now I think aout it, the darned thing should work properly on ipad as I now realise my complaints about it are due to ine of the aove bugs). I’ll find a link.
Now why is it that returns in an original post from the ipad dont show yet if I edit the post they do? Grrrrr…
Anyway here is thecthread with some hopefully working snapshot code: http://forums.coronalabs.com/topic/39133-dp20-how-about-invalidation-of-children-without-clearing-cashed-image/