Resize handles [example]

Get help using Construct 2

Post » Mon Dec 07, 2015 11:55 pm

Another Example
Here is a another example/experiment that implements the custom rotation points per sprite and the beginnings of some simple object hierarchy (only one level for now).
https://dl.dropboxusercontent.com/u/542 ... tspot.capx
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Tue Dec 08, 2015 5:06 am

What a wonderful example, thank you very very much R0J0!
B
12
S
4
G
1
Posts: 116
Reputation: 1,680

Post » Tue Jan 05, 2016 1:46 pm

The touch example as provided was kinda broken. I was able to get it nearly perfect by wrapping some of the provided statements in ABS(). But now I'm running into issues when the two touch points pass each other.

So if you're trying to make something smaller and you're scaling vertically, once the two touch points pass each other on the y axis it starts, growing even though the touches are still going the same direction. I know this is because of the ABS(), I feel like maybe I should should have used a min() instead or something.

I'll try to post a capx and a vid later. I think it'll make much more sense. :)
B
37
S
9
G
7
Posts: 143
Reputation: 6,017

Post » Mon Jan 11, 2016 8:09 am

@R0J0hound Here's the bug I was talking about: https://www.youtube.com/watch?v=3yQFdnor1q0

The two scenarios I'm having trouble getting to work are:

1.) When scaling smaller vertically, and at minimum size, when the thumb touch points pass each other it should not start growing.

2.) When scaling smaller vertically, and at not at minimum size, when the thumb touch points pass each other it should continue to shrink.

Here's my WIP capx based off your previous suggestions: https://www.dropbox.com/s/rhczlfuxbp643 ... .capx?dl=0

Whatever solution will also work for the same situations horizontally too, but you don't really run into here since it's in landscape. Let me know if you need any other info. THANKS!

p.s. also if you want to split this off into a different thread I can do that since it's deviated.
B
37
S
9
G
7
Posts: 143
Reputation: 6,017

Post » Tue Jan 12, 2016 12:45 am

I'm not super familiar with what i did in the example anymore and it's too much trouble for me to use a multitouch device to test but you could possibly do the following. Considering I haven't made any math errors.

Basically keep track of the current and previous positions of the touches and then use a dot product to get a signed distances in particular directions (parellel and perpendiculat to the box's angle). Basically that's to get the scaling factors in either direction. Next in order to actually scale in those directions I used another dot product like above and then used some trig to get a resulting position. Likely the math could be simplified further if you like.

global number oldtouch0x=0
global number oldtouch0y=0
global number oldtouch1x=0
global number oldtouch1y=0

on touch 0
--- set oldtouch0x to touch(0).x
--- set oldtouch0y to touch(0).y

on touch 1
--- set oldtouch1x to touch(1).x
--- set oldtouch1y to touch(1).y

touch id 0 is touching
--- box: set position to self.x+(touch(0).x-oldtouch0x), self.y+(touch(0).y-oldtouch0x)

global number ang=0
global number xscaling=0
global number yscaling=0
global number dotn=0
global number dotd=0
global dotx=0

touch id 1 is touching
--- set dotn to cos(box.angle)*(touch(1).x-touch(0).x)+sin(box.angle)*(touch(1).y-touch(0).y)
--- set dotd to cos(box.angle)*(oldtouch1x-oldtouch0x)+sin(box.angle)*(oldtouch1y-oldtouch0y)
--- set dotx to cos(box.angle)*(box.x-touch(0).x) +sin(box.angle)*(box.y-touch(0).y)
--- set xscaling to dotn/dotd
--- set dotn to cos(box.angle+90)*(touch(1).x-touch(0).x)+sin(box.angle+90)*(touch(1).y-touch(0).y)
--- set dotd to cos(box.angle+90)*(oldtouch1x-oldtouch0x)+sin(box.angle+90)*(oldtouch1y-oldtouch0y)
--- set doty to cos(box.angle+90)*(box.x-touch(0).x) +sin(box.angle+90)*(box.y-touch(0).y)
--- set yscaling to dotn/dotd
--- box: set x to touch(0).x+xscaling*dotx*cos(box.angle)+yscaling*doty*cos(box.angle+90)
--- box: set y to touch(0).y+xscaling*dotx*sin(box.angle)+yscaling*doty*sin(box.angle+90)
--- box: set size to (self.width*xscaling, self.height*yscaling)

touch id 0 is touching
--- set oldtouch0x to touch(0).x
--- set oldtouch0y to touch(0).y

touch id 1 is touching
--- set oldtouch1x to touch(1).x
--- set oldtouch1y to touch(1).y
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Thu Jan 14, 2016 5:50 am

@R0J0hound YOU ARE TRULY A WIZARD!!! :shock: :shock: :shock:

It's close, but not quite working. :/ See video.
https://www.youtube.com/watch?v=aTVGavWBkCc

Here's the capx I ended up with: https://www.dropbox.com/s/vggk894lm5m8u ... .capx?dl=0 . Any guesses? Everything look close?

-------
Also a few mistakes(?) I noticed as I was implementing. I wanted to double check:

touch id 0 is touching
--- box: set position to self.x+(touch(0).x-oldtouch0x), self.y+(touch(0).y-oldtouch0x) <-- Should be oldtouch0y
==========
global doty=0 <--Was missing but referenced. I added it in.
==========
global number ang=0 <---- Not used?


But seriously, thanks so much for all your help! :)
B
37
S
9
G
7
Posts: 143
Reputation: 6,017

Post » Thu Jan 14, 2016 8:40 pm

@basspenguin
It looks like it stops working, or at least jumps, when it goes to just one touch. Maybe setting the oldtouch value when a touch is released would alleviate that. I think I addressed that in my original capx, but I haven't looked.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests