Implementing the use of the touchscreen as camera movement
Basically, this changes allows a user to use keys (or an analog joystick) to move the camera by using the touchscreen.
This method, ofc, is only useful for games which allow you to use the touchscreen to move the camera, such as Kingdom Hearts 358/2 Days.
There is still room for improvement. The movement could be smoother, and, when using an analog stick, the camera movement could move more or less depending on how tilted is the analog stick. Still, this implementation is already useful as it is.
why does this touch the core at all, looks to me like something which could be implemented on the frontend side only?
why does this touch the core at all, looks to me like something which could be implemented on the frontend side only?
Because the input only allow me to update an existing coordinate within the touchscreen, requiring me to know the previous value, while TouchX and TouchY are protected values.
So I either needed to add a function to SPI which updates TouchX and TouchY based on the movement (which was my approach), or I would need to make TouchX and TouchY public (so I could extract that logic to NDS.cpp).
EDIT: It's also worth noting that, based in the DSi SPI class, TouchX and TouchY have different possible values for the DS and the DSi (the DSi ones also include the touch/release states). With that, obtaining TouchX and TouchY would actually be a problem, so I would need to maintain two new variables at NDS.h/NDS.cpp, or main.cpp, instead.
I can update the pull request to achieve that approach if you want. But like I told Jesse before, this may take a little while.
With that, obtaining TouchX and TouchY would actually be a problem, so I would need to maintain two new variables at NDS.h/NDS.cpp, or main.cpp, instead.
It wouldn't really be that hard to just mask out stuff you don't need, a simple & ~0x8000 and checking if the value is 0x700 (and probably checking if y == 0xFFF for DS mode) would work (or maybe a getter would do most of that for you)
or I would need to make TouchX and TouchY public (so I could extract that logic to NDS.cpp).
Is there a reason you can't add GetTouchX() and GetTouchY() to expose these members without letting them be modified arbitrarily?
or I would need to make TouchX and TouchY public (so I could extract that logic to NDS.cpp).
Is there a reason you can't add
GetTouchX()andGetTouchY()to expose these members without letting them be modified arbitrarily?
I will try to do that, following @CasualPokePlayer 's suggestion. Seems to be an approach that will fit all the needs we talked about.
I will leave a comment here once I have time to code, and test, the needed changes.
Alright, just finished implementing the changes.
The SPIs now were only changed to add the getters, and the logic that converts inputs into touchscreen movements is now contained within NDS::SetTouchKeyMask.
Also now it can also detect every scenario when the coordinates becomes out of bounds, which is then considered as the touchscreen being released, so the movement can restart on the next frame starting from the middle of the touchscreen.
I just realized there was a conflict. Fixed it