Mouse click on OnScreenImages

I am building a minimap for a real-time strategy-like game. My code currently uses OnScreenImages to put up a background and moving dots. I would like to be able to click on the background OnScreenImage and have the camera move accordingly. I tried using the standard collision-handling system and having the traverser begin at render2d, but that didn’t seem to work.


Try to use the search link above before to ask, mcstrother
To give you a little push to start you up I did it for you: check this thread out

Thanks for the push, but I actually already found that application and adapted the code for my program. It works very nicely to display objects, but it doesn’t handle clicking on the minimap, which is what brings me here.

I did another search just to make sure I wasn’t missing something else on the forums, but I didn’t find anything. Any other recommendations?

AFAIK there is not such a snip ready to go for you (actually it’s always like this in programming) - but this could be a nice exercise to learn Panda3D - I guess you need to learn, above all, how collisions works in panda and this topic will give you some basics then the chess tutorial of the panda3d samples pack gotta some python related to this issue to snatch from.
keep in mind that if you’ll succeed (I’m very positive on this) and you’ll post here your code the next fella with this same need will benefit of this.
good luck :wink:

Well, here’s what I came up with.

The actual clicking behavior is a bit of a cheap workaround, but it works.

I’ll keep it in my dropbox account until I either find a more permanent place to host it or just get sick of looking at it.

Note that is exactly meant for that sort of hosting.

nice one mcstrother - clicking the mouse though (inside or outside the radar makes no difference) I got an error - it is that for you as well? what is supposed to happen at the click event?

Here’s an updated version that only does something if you click inside the bounding box of the minimap: provides the methods:
screenToWorldCoordinates(self, screenCoordinates)
screenToMinimapCoordinates(self, screenCoordinates)
worldToMinimapCoordiantes(self, worldCoordinates)

which Minimap demo uses to handle mouse clicks, but other than that, defining the behavior when the minimap is clicked on is done entirelyin

I ran both the old and the new version on my computer and I don’t get an error. Would you mind posting or sending me your output? The click is supposed to move the camera to wherever you clicked.

it’s the Panda version I used - your code it is not 1.5.4-compatible, with 1.6.2 I see no errors
anyhow I guess the cam targetting need to be fixed cos if I click the big red dot - the walking panda position - the cam do not spot the panda but a wrong area
keep up!

thanks for sharing

Ah. Glad to hear it was just a compatibility issue.

Like I said, the file provides the hooks to define what you want to do on mouse clicks, but doesn’t actually define the behavior. If you go into the file and change the line

 newPos = (newPos[0],newPos[1], 


 newPos = (newPos[0],newPos[1]-30, 

it will appear as if the camera is focusing where you click.

I will be working on a more general solution later. Thanks a lot for your interest and help debugging! Let me know if you find anything else. (I haven’t fully tested setting the minimap’s point of reference to a NodePath rather than a static point, so that is the most likely place you’re going to find issues.)

Ok. Fine, you’re right. Wanting to click on the minimap and have it focus the camera on the point is probably a common enough desire to support it directly. Here you go: :slight_smile:

The link should stay up too, thanks to p3dp and pro-rsoft.

that’s what I was talking about, nice job mcstrother