[Cuis-dev] [ANN] Cuis-Smalltalk-RoadTrip idle game + a question on implementing a ZoomPanMorph

Jon Hylands jhylands at gmail.com
Thu Feb 29 13:27:06 PST 2024


Hi Ian,

I did something similar a few years ago, writing a python map editor for
doing floor layout maps (it was for work - thus python).

I ran into the same issue. I ended up implementing a pair of transform
functions, that take into account pan and zoom, and create a pair of lambda
functions for points. One to transform from screen coordinates to map
coordinates, and the other to do the opposite. Any time you need to switch
coordinate systems, you use the transform functions.

I can show you the code if you really need to see it, but it's a lot of
python 2.6 code running in tkinter, so it isn't as nice as Smalltalk.

- Jon


On Thu, 29 Feb 2024 at 13:03, Ian Jeffries via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> Hi all,
>
> I'm working on an idle game for learning geography. The first version of
> it's up here: https://github.com/seagreen/Cuis-Smalltalk-RoadTrip
>
> It doesn't do much at the moment, there's just a car that noodles around
> between US cities. However I wanted to go ahead and publish it so I could
> get advice on the zooming and panning mechanism.
>
> Previously when I've implemented zoom-and-pan everything was based on
> screen coordinates. On zoom-in I stored a new scaling factor, and then when
> drawing the game applied this scaling factor to the game coordinates to get
> screen coordinates. Easy enough.
>
> For RoadTrip though I'm taking advantage of Cuis' local coordinate system
> to keep my coordinates in longitude and latitude all the way to the user's
> display. It's extremely neat the users can pull up the morph halo and see a
> grid in long/lat.
>
> But this makes scaling "interesting". On zoom-in when I apply `scaleBy:`
> to the morph the US map wants to shoot up and to the left off the screen.
> I'm currently handling this by moving the `morphPosition` after each zoom
> to offset this, so that while scaleBy makes the map jump up and to the
> left, the morph itself moves within its parent down and to the right to
> make up for it, hopefully keeping the map at the same place.
>
> Unfortunately I can't figure out how to make it exactly accurate and it
> jerks around a lot when zoomed in. Before putting more debugging work into
> this I wanted to ask if it seems like I'm on the right track or if I've
> missed something obvious.
>
> Thanks for the help,
> Ian Jeffries
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240229/ef1402b9/attachment.htm>


More information about the Cuis-dev mailing list