Looking for a solution to address touching small objects.

0 favourites
  • 13 posts
From the Asset Store
Various Bell Sounds (from small to huge) / 35 Unique Clips / 2:46 minutes of audio
  • Hi there,

    Ok so I have this game that really is best on 7"+ screens, but i think the reality is that because I'm doing android, it's going to run on phones and phones are a BIG market to leave out anyway, so here is my situation.

    This is a prototype of what i'm working on. http://part12studios.com/temp/FredexTest2/ in short you flick the boxes into the trucks.. this is meant to eventually be something more like my prior gamesalad version (that i'm remaking in C2)

    Subscribe to Construct videos now

    the problem i have is that the trucks and boxes have to be so big for phones to be easy to pick up that when you play them on bigger screens, so much space is wasted because everything is way bigger than it needs to be on those screens. in this example

    Subscribe to Construct videos now

    you can see i made it for the ipad.. this was my first prototype.. the problem is that if this were to be taken down to an iphone size screen those boxes would be very difficult to grab.

    So i'm trying to figure out a way in C2 to allow me to have the boxes be smaller, at a size that often would be tough to reliably grab on a touch screen.. i'd want to grab the closest one to my finger touch event, but its very likely that

    one thought was to do some kind of distance compare, but when i tried to imagine doing it, it seemed like a rabbit hole of uncertainty.. i just wouldn't know how to do a mass comparison.. the boxes could get numerous so the comparison would have to be each box independent of which one it is (there are 5 unique boxes, each with sub box classifications, icy, explosive, etc)

    another thought was to have some kind of "grip" sprite attached to each box, but my concern there is that since boxes would very likely have overlapping "grips" you'd grab multiples or grab the wrong one..

    So really i just would like it to be able to make it where i can only grab one box at a time and that i'm insuring I'm grabbing the "most right" box possible because the game gets pretty frantic so i could see players getting frustrated if they are finding they are unable to grab the box they want..

    Thanks!

    Caleb

  • What you're looking for is the 'pick nearest' condition, and you can use it with a family for all your boxes like so:

    On touch

    Pick nearest boxes to touch.x, touch.y

    If distance(touch.x, touch.y, boxes.x, boxes.y) is less than whatever amount

    That will ensure that only one instance is picked, and only if it's close enough to the location touched. If your sprites require a non-centered hotspot, than you can use a 'grip' sprite as you mentioned in the same way.

  • ah that's right.. families.. i remember those now!

    I got the family setup so that's awesome, but I quick realized I'm stuck replicating your approach.. here is what I am doing

    but i'm not sure about the IF distance and how you'd structure that. i can't find an "if" equivalent. When i try to call on compare actions, they are X and Y separate, not a fused one that a distance formula would work in.

    This is super exciting though. I definitely see what you're getting out, I just need to figure out how to check X,Y distance as you've stated.

    Thanks!

    Caleb

  • part12studios

    For the "if distance" part you must use System>Compare two values

    First value is the distance(Touch.X, Touch.Y, Box.X, Box.Y)

    is Less or Equal

    Second value is the maximum offset. i would use a global variable maxOffset and set it to whatever you think is the best value for your game.

  • ok i've seen that compare two values before, just never had a need to use it much till now!

    so when it "picks" the nearest... what exactly is happening? the nearest has focus? the nearest "wakes up"? Is there perhaps some "is picked" condition?

    when i look at a single box object, there is the pick nearest/farthest condition for that individual object, but i'm trying to access the choice from the family, not the individual objects..

    its just that everything fires off so fast, I'm trying to understand step by step here how i insure that if say.. Box2 (there are 5 unique boxes) is the nearest.. and it's within the distance range, it knows to be grabbed..

    if i do the rule of distance from it from the Box2 event sheet, that seems like it would ignore the family rated answer...

  • Use 'on any touch start' instead of 'on touched boxes.' That will be more accurate, since the event will run even if the user misses a box by a little bit.

    Give the family a variable, 'selected.' Then all objects in the family have that variable. Have events like this:

    On any touch start

    Pick nearest boxes to touch.x, touch.y

    If distance(touch.x, touch.y, boxes.x, boxes.y) is less than whatever amount

    • set family variable 'selected' to 1

    If boxes variable 'selected' = 1

    • set boxes position to touch.x, touch.y

    On touch 0 end

    • set boxes variable 'selected' to 0

    If you're not sure how picking works, I suggest going through the starter tutorials if you haven't already.

  • ok cool i'll definitely try that. this gives me several things to look into that i hadn't done in the past.. i'll have to reconstruct things a little to support this, but it will be totally worth it!

    I'll report back later tonight when I have some quiet time to focus on this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry this took so long. I had a vacation coming up shortly after the other post. I hoped I could get in there in time, but ran out of time to test this properly. I'm back now and have spent the morning exploring this. This is what I have so far.

    http://part12studios.com/temp/FredExTest3/

    here you can see I have the "Grip" object attached to the physical object.. this is working great. i'm very close i think to having this working i just need to figure out how to compare both of these (or more in future cases) but only drag the closer of the two rather than grabbing both when they overlap as you see in the link above.

    In short, see how you can grab both boxes if they overlap? I don't want this to happen, I only want it to grab the box that is closest to the Touch x,y position.. this way you could have say. a dozen tiny boxes overlapping, but you only grab the one closest to the touch event.

    I tried what was suggested regarding the family instance variable and it just didn't seem to be working the way I expected. I've researched the "pick nearest" and the manual doesn't go deep enough for me to follow what it's actually doing. Since a family variable is for the whole family it seems that it would just apply the variable to everyone in it, not the nearest. So that's the part i'm confused by.

    I setup the variable as advised to the best of my understanding.. but what I'm seeing is that change to both of the boxes so it negates the point what i would think is the point of the variable. to distinguish which one to touch. You will notice that when you click either of them the number goes from 0 to 1 and back to 0. this is the family variable. what I would imagine is the right result is that only the nearest one would become 1 and thus only that one would drag.

    I must be doing something wrong because i would have though that the pick nearest condition would only effect the nearest object be effected, but a familiar variable seems to apply to all of the boxes in the family.. but then i don't know how i could distiguish boxA from boxB..

    I disabled the distance because it made things act a little strange. by that i mean i could drag things sometimes, but not always. there did seem to be some distance behavior involved, but it didn't exactly make sense.

    Thanks!

    Caleb

  • Arima and brunopalermo I'm so close! I must be missing some little thing about how the pick closest object works. maybe someone could make a quick demo of how closest select works?

    It seems like what's missing is a way to flag one object in a family, not all of them.

  • Here's an example.

  • that's awesome! thanks so much. i'll deconstruct this and apply it to mine tomorrow. I have a long stretch of time to work on it. I'll report back on how I do on it.

    Right now i'm actually having great success with CocoonJS/Ouya porting.. first game is just going to be a totally free game with no IAP, but it seems that everything needed to do trial/IAP stuff is there, I just have to figure out how to plug it up.. and I definitely plan on that for the next Ouya game.

  • ok that's awesome. now i see how it works. very cool. still a little mysterious, but i'm definitely seeing the results. http://part12studios.com/temp/FredExTest4/ i have to go back and re-engineer things a bit in my prior version.. I have one more question Arima

    here is the project in it's current state (see capx below as well)

    Is there a way to keep an offset when i click something here? I've spent most of the day today hacking away at different things. I've realized that I believe I don't need the "grip" effect at all, however when you click objects with a mouse and grab something, sometimes it "jumps" to center and this can cause neighboring boxes to get bumped.

    I've tested this on iphone 5s.. and it seems to work really well.. thin walls don't always stop boxes, but the one on the right should be ok and i have space for thicker walls like that.

    Here is the capx in it's current state built from what you did. I added some rules for colliding with the red walls.. but that's

    https://dl.dropboxusercontent.com/u/6999242/C2_capx_files/pickclosest2.capx

    Thanks so much for your help with this.. it's been challenging to experiment with various possiblities, but it's help me really understand how to use families effectively.

    Thanks!

    Caleb

  • Ok so I kept at it this morning (amazing what even a little sleep can do) and realize i wasn't really using families as well as I could. I also tend to pack unnessesary features into tests..

    so i went back to the original example and was able to get the offset to work as it should. very exciting stuff! now that i have the basic offset working.. i will be layering more things back into the game. hopefully though this time the pieces will fit nicely on top of this basic logic.. attached is the improved (and minimal) pick closest capx

    https://dl.dropboxusercontent.com/u/699 ... sest3.capx

    Thanks!

    Caleb

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