Teleporter (I'm Stumped)

Get help using Construct 2

Post » Wed Feb 27, 2013 1:37 am

Ok I'm Stumped.

I want to have a "Portal" sprite object which I can duplicate.
Then link the to portals together..
So when the player hits a portal,, it teleports him to the associated portal.

So I have two instance variables, State and Connection.
State being is it a entrance or exit (really just for the animation)
and Connection being a number that would link the two.. ie 0 and 0 link together.. 1 and 1 link together.

Problem when I have the player detect collision with a portal.. I can't figure out how to "pick" the linked portal..

Then I will just set the player position to the other portal..

I thought about using two sprites .. an A. portal and B. portal.. but still have the same problem if I want more than one set of portals. I still need a way to "pick" the linked sprite.

Thanks in advance for any help/suggestions you guys have. sirrance2013-02-27 01:39:21
B
5
Posts: 9
Reputation: 883

Post » Wed Feb 27, 2013 1:42 am

Lazy man's way to do it: have 2 object types: portalA and portalB. Same instance variables as you had before. Have code for A to B and B to A.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Wed Feb 27, 2013 1:53 am

Yeah this is how I was thinking..but what if I have 2 portalA's and 2 portalB's in the same level. I can't figure out the code to have it know which portalA connects to which portalB. I have the instance varaibles, but I dont know how to compare them in code.

So I want to say.. If player collides with portalA, and portalA connection = 0 pick portalB with connection = 0 and set the player position to portalB.

I can't figure that out in construct code.

B
5
Posts: 9
Reputation: 883

Post » Wed Feb 27, 2013 2:18 am

When you collide with a portal, set a global variable called HitConnection as the portals Connection variable. Then, have a subevent For Each Portal and Portal.Connection == HitConnection -> Set HitConnection to -1 (To avoid referencing another portal afterwards) then set position to Portal.
B
40
S
12
G
7
Posts: 603
Reputation: 7,656

Post » Wed Feb 27, 2013 2:51 am

I think I got it figured out.
using EncryptedCows method.

Thanks a million
B
5
Posts: 9
Reputation: 883


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot], YoHoho and 18 guests