LoginLogin

Issue with zooming in on a specific area

Root / Programming Questions / [.]

spaceturtlesCreated:
ACLS
OPTION STRICT

'Vars...

SPSET 0,0
SPHOME 0,8,8
SPSCALE 0,100,100

WHILE 1
 STICK OUT CX,CY
 
 INC X%,CX*5
 DEC Y%,CY*5
 
 SPOFS 0,-X%,-Y%
 SPSCALE 0,SCALE%,SCALE%
 
 IF #R AND BUTTON(0) THEN
  INC SCALE%
  IF SCALE%>100 THEN SCALE%=100
  ENDIF
 
 IF #L AND BUTTON(0) THEN
  DEC SCALE%
  IF SCALE%<1 THEN SCALE%=1
  ENDIF
 
 VSYNC
 WEND
old postKey: BRV3S3H4 When I zoom out of the galaxy map in my game, pan over to another location, and zoom back in, it always zooms back to the center. How can I get it to zoom in on a different area and zoom back out from it properly and what code can I add?
If you zoom out with the L button, move the sprite (bg/map) elsewhere, and zoom back in the sprite scales as it should. How do I make the sprite move so that the area in the middle of the screen (200, 120) stays there when scaling the sprite up?

Broadly: Keep track of the 'focus' location, that is, the part of the sprite that is at the center of the screen, in a pair of variables. Keep track of the zoom level in another variable. When dealing with the user inputs, don't use the sprite commands directly. Modify these variables instead. Once all the variables reflect the new position/zoom, then SPOFS by -FOCUSX*ZOOM/100, -FOCUSY*ZOOM/100, and SPSCALE by ZOOM. You may wish to add offsets to the focus location, or other modifications, but I hope this helps.

Ran into another problem. I applied this to my "galaxy" game and the zooming works but zoomed out it applies the scaling to the movement speed. Game:ZDB3VKHV How do I fix this?

I think I'll solve the issue by using different display mechanics