How do I use arrays to create swipe mechanicsm?

Get help using Construct 2

Post » Tue Mar 04, 2014 9:45 am

hi, i need need to use some arrays to make some swipe mechanicsm.
I use array for each button and use some swipe mechanics to determine how far down the array to go. like writing message on handphone. if you press 2 button once, you choose 'a', if you press 2 twice, you choose 'b', something like that.

when the array goes beyond it's limit, place it back at the top, so it scrolls around like a slot in a slot machine.
.
can somebody help me?
Thanks. sorry for my bad english
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
62
S
14
G
2
Posts: 286
Reputation: 6,576

Post » Tue Mar 04, 2014 12:25 pm

https://www.scirra.com/tutorials/202/to ... put-method
If you are new to touch controls such as the swipe, check out the tutorial there. It sounds like you have a pretty tough question for me to answer, though, but I think I understand what you're saying.

First of all, when your finger makes contact with the object being swiped, in that moment an invisible (visible when prototyping) line needs to be placed with its origin directly under your finger. The location of the line will remain there until you lift up your finger. As you move your finger down the line, the location of your finger on that line when you take your hands from the screen/finish swiping can represent which slot on the array to choose.

Admittedly there are other factors in play here: the speed of the swipe, for one, but I am not sure at the moment of the best way to handle that.
B
11
S
2
G
1
Posts: 172
Reputation: 1,486

Post » Wed Mar 05, 2014 3:14 am

nooo...
let's say I have an array [10],
what I looking for is how to use a button (up for example) to select array index[x]. then, when I press another button (down) i choose array index[x-1].
.
but when I continously press down till the array goes beyond index[9], it's placed back at array index[0].
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
62
S
14
G
2
Posts: 286
Reputation: 6,576

Post » Wed Mar 05, 2014 3:50 am

you could use a variable "Position" to hold the current index. Have it start with a value of 0 (at the top of the array, or bottom - depending on how you want to look at it).

Then if you press the down button, subtract 1 from "Position, then check if it is less than 0, if so set it to 9.

If you press the up button, add 1 to "Position", then check if it is greater than 9, if it is then set it to 0.
B
94
S
33
G
20
Posts: 438
Reputation: 17,615

Post » Wed Mar 05, 2014 5:40 am

Math is your friend

looping index scope
index = index % array_size
array[index] = stuff
index + 1

the other method to limit your index scope is
index = clamp(index, 0, array_size)
array[index] = stuff
index + 1
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Wed Mar 05, 2014 7:06 am

jayderyu..
can you give me a capx? ._.
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
62
S
14
G
2
Posts: 286
Reputation: 6,576

Post » Wed Mar 05, 2014 7:27 am

nope, I just did already. thank you everyone :D
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
62
S
14
G
2
Posts: 286
Reputation: 6,576


Return to How do I....?

Who is online

Users browsing this forum: davidbox, Mayfly and 6 guests