I'm having trouble understanding the clip function. When I use it with a stationary camera it works as I would expect it to but when the camera follows the player it hides everything I'm trying to clip. I'm probably missing something obvious here. Any help would be greatly appreciated!

 function _init() p={ sp=16, x=63, y=63 } end function _update() if btn(⬅️) then p.x-=1 elseif btn(➡️) then p.x+=1 elseif btn(⬆️) then p.y-=1 elseif btn(⬇️) then p.y+=1 end --i comment out the camera --for stationary movement --in this example camera(p.x-63,p.y-63) end function _draw() cls() map() if p.x>72 and p.x<90 and p.y>32 and p.y<64 then clip(p.x,p.y,8,4,true) spr(p.sp,p.x,p.y) clip() else spr(p.sp,p.x,p.y) end end
P#145147 2024-03-30 18:03

Clip parameters are in screen pixels , it’s not influenced by the current camera offset

P#145243 2024-03-31 14:02
1

@rupees,
Do you have further questions about clip ?
When the camera follows the player, the clip is straightforward as you know exactly where the player is on the screen :
clip(63,63,8,4)
No need to set the last parameter as true, it is used to define a sub-clip from the current one that is the full screen, so an absolute clip makes more sense, even if the result is the same in this case.
When not scrolling, clip(p.x,p.y,8,4) was OK because the camera offets were zero.
There's no built in function to read the current camera offsets, but they are memory mapped in the draw state (2 bytes each) at 0x5f28 for x and 0x5f2a for y.
To clip around the player sprite while having a variable camera (you may want to not show out of map or not show outside a building for example) you can do
clip(p.x-peek2(0x5f28),p.y-peek2(0x5f2a),8,4)
It's usually simpler to have the camera offsets stored in variables when you are dealing with your own code, but is a convenient shortcut when modding other people's code with complex camera handling you don't want to figure out.

Another point, you could also have used sspr instead of clip+spr to draw your half player :
sspr(8*(p.sp%16),8*(p.sp\16),8,4,p.x,p.y)
Like spr, sspr is affected by the camera offest.
You could also shift it down two pixels to make the depth more felt :
sspr(8*(p.sp%16),8*(p.sp\16),8,4,p.x,p.y+2)

P#145452 2024-04-02 10:06 ( Edited 2024-04-02 10:08)