Log In  

Hey. I'm currently trying to make a basic RTS inside of pico 8 but my knowledge of how the mouse input works is a bit lacking. The first thing I tried doing was making it so that when you put the mouse close to the edge of the screen, the camera would pan that direction on the map. The only issue is that the mouse x and y coordinates aren't relative to the camera, and so the boundaries would get left behind as the camera pans away. Another thing I'm stuck on is figuring out how to tell if the mouse is over or clicking on a certain sprite.

Cart included

Cart #hdsotiji-0 | 2021-04-13 | Code ▽ | Embed ▽ | No License

P#90441 2021-04-13 01:51

1

You need to add the Camera-Position to the Draw-Position, like:

spr(0, mx-1+cx, my-1+cy)
P#90450 2021-04-13 06:25
1

I’m not sure that’s correct. What 'camera(x,y)' does is exactly to add offsets to drawing functions. To draw something at absolute screen coordinates (UI or HUD), we have to reset the offsets by calling 'camera()'.

For the second question: you can get the map tile that’s at a certain screen position with 'mget'. For sprites drawn by 'spr', you’ll have to iterate through all entities drawn and compare coordinates (search for guides about collision).

P#90468 2021-04-13 14:27

The code snipit works, thanks!

P#90505 2021-04-14 00:17

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-19 21:20:10 | 0.013s | Q:19