Paint a sprite into a sprite with a viewport? #2967
-
Hi -- Let's say I want to paint a small sprite into bigger sprite at x,y in the big sprite's coordinate system, but I want to clip the small sprite at the boundary pixels of the bigger sprite. I have been doing this, and it works:
...my question is about the -1,-1 coordinates that seem necessary: is it normal/expected that the setViewport() changes the 0,0 location when calling pushToSprite? I would have expected to be able to do pushToSprite(&bigsprite, x, y) but that seems to draw offset by one pixel (or however many pixels I used in the coordinates passed to setViewport). I just wanted to make sure that I'm not doing something that will cause a crash later by passing e.g. -1, -1 when the desired x,y is 0,0. :-) Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
It won't crash the processor, but it looks like a bug in the datum handling. I will push this into an Issue report until resolved. |
Beta Was this translation helpful? Give feedback.
-
I've created a simple sketch to test this:
It works fine on my setup. It should draw a white rectangle with a a 2x2 white pixel block at top left. This block should have a 1 pixel black margin at top and left. Can you provide a simple sketch that demonstrates the problem you have noticed? |
Beta Was this translation helpful? Give feedback.
-
Thanks! So, if that's the intended behavior, this may just be a misunderstanding on my part. You call spr1.setViewport(1,1,48,48) and then spr2.pushToSprite(&spr1,0,0) -- for that pushToSprite call it appears that the coordinate system is now such that 0,0 is the top-left of the viewport, not the top-left of spr2, which is what surprised me (but perhaps should not have, I'm not experienced in these things.) In other words, I interpreted setViewport to be setting a clipping mask, but that the coordinate system would still be 0,0 pointing to the top-left of the sprite, not the top-left of the viewport, which would make the small 2x2 block appear all the way in the corner, i.e. not with a 1-pixel black border around it. So if your demo is showing the expected behavior (1-pixel black border around the 2x2 block) I will just keep doing the equivalent of -1,-1 to compensate for the viewport offset, since you said it will be harmless to do so? |
Beta Was this translation helpful? Give feedback.
Yes, the 0,0 datum by default moves to the corner of the viewport. This is demonstrated here. Also you can optionally keep the datum at the top left corner of the screen or destination sprite. See command parameters here. So either keep using -1,-1 if you like, that is no problem, or add the extra true/false as needed to the function.