Dance Dance Revolution check


#1

Hi everyone,

I’d like to know how i do i check a button pressed at the right time and place

I have an sprite of an up arrow in the bottom of the screen
another sprite up arrow is coming down direct to the previous one
I will press a button when they are crossing
How i check it? It’s almost like Dance Dance Revolution

Thx


#2

Hi. This is just a matter to check if the button is pressed while the two sprites are in collision. Look for ‘collision’ in the events for the sprites and then ‘key pressed’ or ‘key released’ to check for the key, depending on how you want to check.


#3

Thx. That worked, but now there is another problem:

spr1 = static sprite in the bottom
spr2 = sprite that comes down towards spr1

I have multiple instances of spr1 coming down.
One of them is colliding with spr2, but i have several others that aren’t in the position to collide yet.
I need to check when i press spacebar and no spr1 are colliding with spr2
So i made an event with with the condition inverted.

What happens is when i press spacebar when spr1 is colliding with spr2, since i have instances of spr1 not colliding yet, i have the 2 actions ocurring simultaneously:, collind and not colliding.


#4

Yes, it does seem like that. You check for ‘collision’ event and if that’s true then set a flag variable in order to skip testing for ‘non-collision’ event. If ‘collision’ event is ‘not true’ you will move on checking the ‘non-collision’ events.
This is pretty much trying to implement an ‘if-then-else’ statement actually.


#5

I tried this approach, but it is not working

It works for the first collision, than does not work more


#6

Can you also show us the ‘else’ part of the events?


#7

It is this part

If this obejct bola2 is collinding with bola, do this.
else blink bola2


#8

OK. You need to add another event to reset the hitTrue variable after that event to make sure it always ‘0’ unless you have a collision.


#9

Thats working until i miss one press.

bola2 moves torwards bola, if i do not press spacebar and it passes the object bola i can’t delete the next bola2 colliding with bola.


#10

Yes, you are using object variables as flags for the ‘if-then-else’ functionality. Use a common scene variable for this. You last action updates all of Bola2’s objects variables to hitTrue = 0, you don’t want that. Also, try to lose the Repeat for each…’ event and just delete the Bola2 object from within the Bola.2 ‘is inside’ event and see if that works. GDevelop does a smart object selection for some events.


#11

Worked here.

i had an event to delete offscreen bola2 objects, i had to put a for each in that event too.

I have to use the for each to delete bola2, without it gdevelop was deleting all.
Also i needed the last action to update hitTrue to 0, since when it is setted to 1 there wasn’t no event to turn it back.

The final code became this:

Thx for all the help, specially the flag idea


#12

Glad it works now!

What happens if you move the ‘Delete Bola2’ action after the ‘Change the scene variable…’? Isn’t GDevelop just deleting the specific Bola2 sprite?

Also, no need to delete the sprites outside the screen by hand, there is a behavior already that you can attach to the sprites.


#13

What happens if you move the ‘Delete Bola2’ action after the ‘Change the scene variable…’? Isn’t GDevelop just deleting the specific Bola2 sprite?

It’s deleting all

Also, no need to delete the sprites outside the screen by hand, there is a behavior already that you can attach to the sprites.,

Great! I’ll do that!


#14

Now i will try to do “perfect”, “great” and “good” presses, i’m thinking putting an offset in the inside event.


#15

you can use a subevent that checks for distance.
if distance >5 = perfect
if distance <=5 and >10 = good
and so on.


#16

That woulb be a good aproach.

I’m thinking a way do to like this:
If the press is with the 2 sprites centered = perfect
if the press is with an offset of 1/3 of the center = great
if the press is with an offset of 1/2 of the center = good

Figuring now how to know where the press is, or at least what is the condition that i will use for this.


#17

distance check.
if your sprites have the same size, its even easier.
otherwise check distance to center.
spites centered = distance 0 = perfect.
distance >0 <sprite.height()/3 = great
distance >sprite.height()/3 <sprite.height()/2 = good


#18

I managed to do what you told me and it works, kinda.

When i compare de distance beween these 2 objects i am convinced that Gdevelop is using the origin point to compare the distance, there is a way to use the center points of these objects?


#19

Object.PointY(“Center”) I think


#20

I did this way, there is no option to choose the center point