Linking two different object types.

0 favourites
  • 4 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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 :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)