Looking for a solution to address touching small objects.

Get help using Construct 2

Post » Fri Jun 27, 2014 3:34 pm

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) https://www.youtube.com/watch?v=jBk2CPETZyk

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 https://www.youtube.com/watch?v=P3uzXSbn45I 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
B
59
S
9
G
1
Posts: 939
Reputation: 6,545

Post » Fri Jun 27, 2014 6:32 pm

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.
Moderator
B
94
S
33
G
33
Posts: 3,006
Reputation: 27,749

Post » Fri Jun 27, 2014 7:38 pm

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

Image

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
B
59
S
9
G
1
Posts: 939
Reputation: 6,545

Post » Fri Jun 27, 2014 8:14 pm

@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.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
16
S
4
G
1
Posts: 408
Reputation: 2,297

Post » Fri Jun 27, 2014 9:25 pm

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...
B
59
S
9
G
1
Posts: 939
Reputation: 6,545

Post » Fri Jun 27, 2014 9:43 pm

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.
Moderator
B
94
S
33
G
33
Posts: 3,006
Reputation: 27,749

Post » Fri Jun 27, 2014 10:29 pm

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.
B
59
S
9
G
1
Posts: 939
Reputation: 6,545

Post » Mon Jul 07, 2014 4:21 pm

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

Image

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
B
59
S
9
G
1
Posts: 939
Reputation: 6,545

Post » Tue Jul 08, 2014 4:56 am

@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.
B
59
S
9
G
1
Posts: 939
Reputation: 6,545

Post » Tue Jul 08, 2014 5:16 am

Here's an example.
You do not have the required permissions to view the files attached to this post.
Moderator
B
94
S
33
G
33
Posts: 3,006
Reputation: 27,749

Next

Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], facecrime, Yahoo [Bot] and 30 guests