[Solved] Activate button on press (not release)
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.
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.
[Solved] Activate button on press (not release)
Hi everyone,
I am making a minigame where the player must click on a moving button.
However, the clicking only 'happens' upon releasing the mouse button, not pressing it down, which leads to player frustration as they have to release it really quick or nothing happens. It also leads to a strange situation where it works better to always hold the mouse button down then release it on target, instead of just clicking.
So, long story short, is there any way to create a button that activates on pressing down the left mouse button?
I am making a minigame where the player must click on a moving button.
However, the clicking only 'happens' upon releasing the mouse button, not pressing it down, which leads to player frustration as they have to release it really quick or nothing happens. It also leads to a strange situation where it works better to always hold the mouse button down then release it on target, instead of just clicking.
So, long story short, is there any way to create a button that activates on pressing down the left mouse button?
Last edited by goldo on Sun Jul 21, 2019 12:58 pm, edited 1 time in total.
- Per K Grok
- Miko-Class Veteran
- Posts: 882
- Joined: Fri May 18, 2018 1:02 am
- Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
- itch: per-k-grok
- Location: Sverige
- Contact:
Re: Activate button on press (not release)
goldo wrote: ↑Sun Jul 07, 2019 9:09 am Hi everyone,
I am making a minigame where the player must click on a moving button.
However, the clicking only 'happens' upon releasing the mouse button, not pressing it down, which leads to player frustration as they have to release it really quick or nothing happens. It also leads to a strange situation where it works better to always hold the mouse button down then release it on target, instead of just clicking.
So, long story short, is there any way to create a button that activates on pressing down the left mouse button?
key mousedown acts on press, so you can use than to build your own 'button' that reacts to on press.
You could do it with the code below.
bX,bY is the position of the button
bW,bH is width and height.
Code: Select all
screen checkMouse():
key "mousedown_1" action Jump("checkClick")
---------
label checkClick:
python:
mX=renpy.get_mouse_pos()[0]
mY=renpy.get_mouse_pos()[1]
if bX<mX<bX+bW and bY<mY<bY+bH:
--- god things happen ---
else:
--- bad things happen ---
jump gamelabel
If by moving you mean jumping from point to point in an instance you will always know bX and bY, so that will not be a problem.
If you mean moving like in a Duck Hunt type game that can be more problematic dependent on how the movement is coded. But that can be handled to.
Re: Activate button on press (not release)
Else:Per K Grok wrote: ↑Sun Jul 07, 2019 11:49 amgoldo wrote: ↑Sun Jul 07, 2019 9:09 am Hi everyone,
I am making a minigame where the player must click on a moving button.
However, the clicking only 'happens' upon releasing the mouse button, not pressing it down, which leads to player frustration as they have to release it really quick or nothing happens. It also leads to a strange situation where it works better to always hold the mouse button down then release it on target, instead of just clicking.
So, long story short, is there any way to create a button that activates on pressing down the left mouse button?
key mousedown acts on press, so you can use than to build your own 'button' that reacts to on press.
You could do it with the code below.
bX,bY is the position of the button
bW,bH is width and height.
One thing you have to watch out for with this time of solution is 'side rollback'. You need to have that turned off or make certain the 'button' never is in the side rollback area.Code: Select all
screen checkMouse(): key "mousedown_1" action Jump("checkClick") --------- label checkClick: python: mX=renpy.get_mouse_pos()[0] mY=renpy.get_mouse_pos()[1] if bX<mX<bX+bW and bY<mY<bY+bH: --- god things happen --- else: --- bad things happen --- jump gamelabel
If by moving you mean jumping from point to point in an instance you will always know bX and bY, so that will not be a problem.
If you mean moving like in a Duck Hunt type game that can be more problematic dependent on how the movement is coded. But that can be handled to.
viewtopic.php?f=51&t=51263
Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18
Sawa - a game of the Drow Nation
Honest Critique
Poses in visual novels, or how to hold a character properly in the frame
Help save articles to the webarchive. [/color]
Sawa - a game of the Drow Nation
Honest Critique
Poses in visual novels, or how to hold a character properly in the frame
Help save articles to the webarchive. [/color]
Re: Activate button on press (not release)
Thanks! It is a kind of duck hunt type game.
Branching to a jump will not be practical as I will have several moving buttons that must keep running at once, but I guess a Function would work just as well.
The only problem is: how can I get the button's coordinates at the time of clicking to make sure the cursor is over it? (the button is being moved around with ease transforms)
Branching to a jump will not be practical as I will have several moving buttons that must keep running at once, but I guess a Function would work just as well.
The only problem is: how can I get the button's coordinates at the time of clicking to make sure the cursor is over it? (the button is being moved around with ease transforms)
- Per K Grok
- Miko-Class Veteran
- Posts: 882
- Joined: Fri May 18, 2018 1:02 am
- Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
- itch: per-k-grok
- Location: Sverige
- Contact:
Re: Activate button on press (not release)
I did a duck hunt type game a while back in ren'py (with a bit of extra pygame)goldo wrote: ↑Sun Jul 07, 2019 1:21 pm Thanks! It is a kind of duck hunt type game.
Branching to a jump will not be practical as I will have several moving buttons that must keep running at once, but I guess a Function would work just as well.
The only problem is: how can I get the button's coordinates at the time of clicking to make sure the cursor is over it? (the button is being moved around with ease transforms)
viewtopic.php?f=11&t=51931&p=496272&hil ... ok#p496272
What I did was that I created a small loop in the script in which I updated the position of the ducks (or pterodactyls in my case). I also checked for hits in that loop (using pygame's keydown). So I always was updated on the position of each hitbox.
Code: Select all
label timerlab:
$renpy.pause(delay=0.02, hard=True)
label runner:
python:
mx, my = pygame.mouse.get_pos()
--- check hit ---
--- update position of 'ducks' ---
--- update and show 'hunter' (direction the weapon is pointed)---
jump timerlab
An admittedly hacky solution. But it worked for me.
Thanks for mentioning functions. That suddenly made me realize that a function could be the solution to a completely different problem I have struggled to find a good solution to.
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Activate button on press (not release)
You could always use imagebuttons, you can move those and they can be clicked on even while moving with no need to track position.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Re: Activate button on press (not release)
Yeah but so do normal buttons, I am back to my original problem which is how to click them when the button is pressed, not released. I am thinking I might look in a different direction if I can't get it to work. I'll keep you updated on the issue.
Re: Activate button on press (not release)
Hi guys, still trying to work on a solution.
Do you know if it's possible to create a renpy button as an object and store it as a variable? Then, could I ask that object for its coordinates at a point in time?
The logic would be like:
Do you know if it's possible to create a renpy button as an object and store it as a variable? Then, could I ask that object for its coordinates at a point in time?
The logic would be like:
Code: Select all
buttons = [button1, button2, ...]
while running:
--- make buttons move ---
--- checks for mouse button down ---
if mouse button down:
--- ask for cursor coordinates ---
for button in buttons:
--- if cursor coordinates == button coordinates ---
--- CLICK HAPPENS ---
break
Re: Activate button on press (not release)
Hi guys,
I'm happy to report I found a way, it's actually surprisingly easy.
Before running the mini-game, I use this code to change button behavior:
Then, after the mini-game is over, I use this to go back to regular button behavior:
While changing config values mid-game is not necessarily a good idea, this doesn't seem to cause any negative side effects, so it works for my purposes.
I'm happy to report I found a way, it's actually surprisingly easy.
Before running the mini-game, I use this code to change button behavior:
Code: Select all
$ config.keymap['button_ignore'] = []
$ config.keymap['button_select'] = ['mousedown_1', 'K_RETURN', 'K_KP_ENTER', 'K_SELECT']
Code: Select all
$ config.keymap['button_ignore'] = ['mousedown_1']
$ config.keymap['button_select'] = ['mouseup_1', 'K_RETURN', 'K_KP_ENTER', 'K_SELECT']
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Google [Bot]