How do I keep a player "on rails"?

Get help using Construct 2

Post » Mon May 18, 2015 2:48 am

R0J0hound wrote:Sorry, I think I neglected the fix in LittleStain's capx. I don't use multi-touch devices so I didn't test. The fix is to do what LittleStain did in his capx.

1st add this event:

Code: Select all
on touched sprite2
--- sprite2: set touchID to touch.touchID


2nd replace sprite2.x and sprite2.y with
touch.XForID(Sprite2.TouchID)
and
touch.YForID(Sprite2.TouchID)

That should make it behave like LittleStain's capx.


I made those changes but nothing seems to have changed. Does this look correct?

Image
B
14
S
2
Posts: 73
Reputation: 794

Post » Mon May 18, 2015 5:38 am

Yeah that's the changes as I described. Can't see what's amiss. I'm unable to test. :/

Ok, the general idea for multi touch is each new finger press has an id.
When you touch a sprite2 the current is saved in a variable so you know which sprite2 goes to what finger.

The code above is supposed to loop over each sprite2 and basically move to the closest point on the circle near that sprite2's assigned finger.

But if it doesn't work then I'm kind of stumped until I do some testing on a multi-touch device.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon May 18, 2015 7:14 am

Looks to me like it should work..
Only thing I did different was resetting the Sprite2.touchID to 0 on drag and drop drop.

@R0J0hound
Could it be that the for each statement here messes it up?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon May 18, 2015 10:06 am

I don't think the "for each" would be the issue. I'm kind of curious if the "or" us throwing it off when combined with the drag n drop behavior. It shouldn't though. Actually it could be the drag n drop behavior isn't correctly handling multiple objects being dragged at once.

Until we can prove that one way or another we could get rid of the dragndrop behavior and do it ourselves with events. Like so:

on sprite2 touched
--- set id to touch.id
--- set dragging to true

dragging is true
for each sprite2
--- set position to (touch.XForID(Sprite2.TouchID), touch.YForID(Sprite2.TouchID))

on any touch end
pick sprite2 id = touch.id
--- set dragging to false
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon May 18, 2015 10:46 am

@R0J0hound

The "for each" doesn't seem to do anything..
Removing it in the capx you posted changes nothing while "playing"

Which makes me think removing it in the example with TouchID will make the program work as wanted..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue May 19, 2015 3:08 am

Image

Yeah, the For Each doesn't seem to make any functional difference. Still no luck getting simultaneous moving objects, either, which seems odd since it's more or less the same as LittleStain's working one as far as that piece is concerned?

It's worth noting that I also tried R0J0hound's "no dragdrop" workaround with no change.
B
14
S
2
Posts: 73
Reputation: 794

Post » Tue May 19, 2015 6:22 am

Instead of using global variables, make ratio, dx, dy and ang instance variables of Sprite2 and all should work..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed May 20, 2015 1:44 am

LittleStain wrote:Instead of using global variables, make ratio, dx, dy and ang instance variables of Sprite2 and all should work..


Good call! Working perfectly now. Thanks for the help, everyone. :D
B
14
S
2
Posts: 73
Reputation: 794

Post » Sun May 24, 2015 3:58 am

Is there anyway to I could possibly accomplish the same movement, but with the arrow keys?
B
8
S
2
Posts: 39
Reputation: 604

Post » Sun May 24, 2015 4:28 am

Cam112549 wrote:Is there anyway to I could possibly accomplish the same movement, but with the arrow keys?

actually there is a tutorial with capx solar system i think, try searching for it, i had the capx long time ago, and it was using arrow keys basically was doing same thing just around some sun
B
75
S
22
G
68
Posts: 1,337
Reputation: 43,271

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Bootfit, Huemerson, jorgmaquoi and 5 guests