How do I use arrays to create swipe mechanicsm?

0 favourites
  • 7 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • 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

  • 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.

  • 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].

  • 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.

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • jayderyu..

    can you give me a capx? ._.

  • nope, I just did already. thank you everyone

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)