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

27 posts
• Page **3** of **3** • 1, 2, **3**

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

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

**Posts:**5,280**Reputation:**69,971

B

92
S

32
G

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

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.

**Posts:**146**Reputation:**6,773

B

51
S

13
G

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

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.

**Posts:**146**Reputation:**6,773

B

51
S

13
G

7
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

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

**Posts:**5,280**Reputation:**69,971

B

92
S

32
G

107
@R0J0hound YOU ARE TRULY A WIZARD!!!

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!

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!

**Posts:**146**Reputation:**6,773

B

51
S

13
G

7
27 posts
• Page **3** of **3** • 1, 2, **3**

## Who is online |

Users browsing this forum: duditon, sean080, yiuyiu6666 and 24 guests |