Linking two different object types.

Get help using Construct 2

Post » Mon Nov 05, 2012 8:34 pm

I have a situation where my game objects can disappear off the edge of the screen, but continue to exist. The player needs to know where these objects are so that he can track/follow/avoid them. Rather than a radar, I prefer the idea of having little icons which float around the edge of the screen, in the direction of the objects.

I'm trying to work out the best way to do this. One idea I'm thinking is that when the object is created, an icon object is created at the same time, with some sort of ID for both - i.e they could both have a variable which is set to the same value. The game then needs to check each frame to see if the object is on the screen - if it is, the corresponding icon has it's visibility turned off - if it isn't, the icon is made visible and it's position calculated. And of course, when the main object is destroyed, the icon has to be destroyed too.

This would probably work but sounds a bit intensive and fiddly.

Is there a better way of doing this?

B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Mon Nov 05, 2012 9:19 pm

The easiest way to link is with the .uid's
i'd have something like:

--
+For each Sprite
+Sprite.IconUID = 0
     >Sys | Create object Icon at Sprite.x,sprite.y
     >Sprite | set value IconUID to Icon.UID
--

and then, to set the position of Icons..

--
+For each sprite
+Pick Icon by UID: Sprite.IconUID
     >Icon | set position to sprite.x, sprite.y


Edit: For the whole positioning/ transparency thing you could do:

+For each sprite
+Pick Icon by UID: Sprite.IconUID
          >Icon | set position to clamp(sprite.x,Viewportleft(),ViewportRight()), clamp(sprite.y,ViewportTop(),ViewportBottom())
     +Sprite Is on Screen
          >Icon | set invisible
     +Else
          >Icon | set visible
keepee2012-11-05 21:24:48
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Mon Nov 05, 2012 9:50 pm

B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Tue Nov 06, 2012 1:13 am

Excellent replies guys, and a big thank you :)

This is exactly what I need as I had a feeling there was a better way than I was describing. I was particularly confused about how I'd get the image to show at the edge of the screen, since the screen is rectangular so it's not just a case of showing the objects at a certain distance and angle from my spaceship. This describes that very well and without it it would have taken me forever to work out :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest