How to Get Mouse Position?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
franny
Newbie
Posts: 17
Joined: Tue Sep 22, 2015 12:07 pm
Location: Philippines
Contact:

How to Get Mouse Position?

#1 Post by franny » Thu Dec 31, 2015 3:23 am

(Sorry for messy English)
I'm planning to create an android app with dialogue and minigames. The minigames would be pretty basic, just swiping things and drag and drop stuff. I can't figure out how to get the mouse position, though, or where/how to put the game loop for the minigames. I did some searching and it has something to do with user-defined displayables, but I don't understand the explanations well.

Can someone give me a dummies explanation on user-defined displayables and point me in the right direction?
How can I do this?

(extra: I read that Ren'Py has gesture controls, I wonder if having minigames with a swipe mechanic is a bad idea?)

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: How to Get Mouse Position?

#2 Post by xela » Thu Dec 31, 2015 10:31 am

Look for it in the docs. renpy.get_mouse_pos or pygame's direct call will return the right values.

No idea about gesture controls but if it's true that they're working, why not try them, if only to test the system?
Like what we're doing? Support us at:
Image

synedraacus
Regular
Posts: 58
Joined: Tue Jun 09, 2015 8:10 am
Github: synedraacus
Contact:

Re: How to Get Mouse Position?

#3 Post by synedraacus » Fri Jan 08, 2016 1:51 am

The easiest approach for your creator-defined displayables will be probably like this: put all the drawing into render (and make sure all objects on screen know their position, probably by wrapping them in transforms). Then put all the gameplay logic into event() method, which gets called with event type and coordinates (ie left mousebutton got released at x, y) and update objects every time the event occurs. Something like "If ev.type=TYPE_1: do this elif ev.type=TYPE_2 and within(x, y, block.coords) do that". I also found it convenient to put some part of logic (processing opponent move in my case) into per_interact method which gets called every time the new interaction starts.
This will be enough for a turn-based game. If you want real-time, I'm pretty sure you can emit some kind of events every so often to simulate a proper game cycle, although I don't know exactly how to do that.
Although renpy in general is not that great for creating complex touchscreen interfaces with gestures, real-time gameplay and so on. If you do not really need the visual novel logics, you may want to have a look at eg. Kivy, which is a bit lower-level than renpy and gives you more control over what your displayables (called vidgets there) do and when. No point using it if you do need VN logic, though, that would be a lot more pain to implement than dealing with quirks of renpy CDDs.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot