alcemirfernandes / pynguin

Automatically exported from code.google.com/p/pynguin
GNU General Public License v3.0
0 stars 0 forks source link

How to select which of multiple sprite is controlled by the mouse? #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Make two penguins
2.  Click somewhere to m e a penguin
3.  Try to figure outhow to move the other penguin by clicking

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
0.8 Ubuntu 9.10

Please provide any additional information below.

Original issue reported on code.google.com by aresnick...@gmail.com on 13 Jun 2010 at 1:11

GoogleCodeExporter commented 9 years ago
In console:

>>> p2 = Pynguin()

In code area:

def onclick(x, y):
    p2.goto(x, y)

Click "Test" button.

If you have a proposal for a better way to do this, I'm willing to listen.

Original comment by miss...@hotmail.com on 13 Jun 2010 at 2:08

GoogleCodeExporter commented 9 years ago
Perhaps each sprite can have its own activate_click_listener method that 
defines onclick?

Original comment by aresnick...@gmail.com on 13 Jun 2010 at 4:39

GoogleCodeExporter commented 9 years ago
Give the most recent a try.

By default, all pynguins will now respond to mouse clicks.

The signature for onclick() definitions has changed -- It is now a class method 
instead of a plain function and requires a first parameter (self).

You can write a subclass with an overridden onclick() method, or make a 
monkeypatch. See the onclick examples for details.

Also, each pynguin can stop (or start again) listening for clicks by setting 
the respond_to_mouse_click variable:

p.respond_to_mouse_click = False # stop listening
p.respond_to_mouse_click = True  # start listening again

Would it be useful to have right-click set the clicked pynguin to respond and 
unset all of the others? Or maybe there could be a menu with a list of all the 
pynguins and a check next to the one that will respond to mouse clicks. (with 
an "All" choice selected by default).

Original comment by miss...@hotmail.com on 13 Jun 2010 at 6:09