How do I create HUD icons to show where offscreen object are

0 favourites
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • Hi. I am working on a new game and want to use the scale feature to zoom in/out of the layout. There is a special object in the layout and if it is not in the current viewport (not visible) there should be a new Icon in the HUD pointing to the location where it is (in the upper right corner for example) and it should move when the player moves to always show the shortest way back. (like wing commander and other space shooters show the enemy ships with arrows which move around the screen edges)

    It found the "is on Screen" event and this should work with different scales of the layout. But did someone already make something like this and has some hints how to do it?

  • Object1 is visible, do nothing here

    ->trigger once while true, set object2 invisible

    Else, object2 set angle towards object1

    ->system trigger once, set object2 visable

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, this will point the object towards the object out of screen and works fine if you have some kind of compass or a fixed position for the pointer. But do you know a good way to position the pointer around the screen? So Object1 is in the upper right outside of the screen the Pointer Object should be in the upper right corner. And if I move right it begins to move to the middle because Object1 is now above me (but still out of screen).

  • Not sure what you mean, but I'm guessing you want an indicator to point at the object when its off screen.

    That would be the above with set x to clamp(Object1.X,ViewportLeft(yourlayer),ViewportRight(yourlayer)), set y to clamp(Object1.y,ViewportTop(yourlayer),ViewportBottom(yourlayer))

  • Thank you, I will try this tomorrow. <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    Here is an example: http://youtu.be/qqtyGuV49rc?t=5m7s

    there are red triangles appearing around the circle in the middle if the current target is outside of it.

  • Yeah that's it pretty much.

    The vid is clamped to a set radius. Not sure how good that would look with 2d, but it is doable.

  • Thats it! Thank you very much!

    It works fine for the viewport (viewable area) and shows the indicator to let you know where you need to go to come back to Object1.

    I thought this would be way more complicated.

    Update: I played around with it a bit and changed the sprite origin for the indicator object to keep it more in the viewport when moving around but the edges (I used a arrow image >) are often outside of the screen. Is there something like "Bound to Layout" behavior for the viewport to keep it always on screen or does anyone know a simple way to keep it always in sight completely?

    /edit: If I add some kind of HUD at the bottom of the screen it would be great if the arrow could always stay in the "game" area above and not overlap the HUD/UI.

    Maybe with collision checks to keep it above?

    Example image:

  • That stuff would go on a non scrolling layer.

    Parallax 0,0.

  • I tried it with a simple rectangle and just used:

    On Arrow Collision with object HUD > Set Arrow Y to Arrow.Y-130 (the hud height). It seems to work fine in most cases, only sometimes a small "jumpy" behavior can be noticed. Do you know a "better" solution to keep the arrow out of the region at the bottom? (It will be more difficult if the hud is not just a rectangle like in the great paint image above)

  • Well the viewport is just a rectangle.

    Offset from the clamp viewportLeft + offset, viewportTop + offset, etc.

  • thanks newt

    if you are dealing with multiple objects, do you have to discriminate by UID or is there a way to put the object and the indicator in a container so it only picks the relevant objects?

  • Containers are great for that. I just have the indicator set position to the object when it is on screen.

  • newt ahh nice..thanks

    what if your enemies are in a Family? I notice there's no way to add a container to the whole family... So if I add the indicator to each enemy container...

    Then could you do:

    If EnemyFamily is OnScreen etc... and would it pick the appropriate indicator (that's in it's container?)

    EDIT: you can't add the same object to different containers.. so it seems I need separate objects for each enemy indicator?

  • newt

    I'm having a little trouble with the picking.. I've tried a couple different methods, neither fully work. It feels like I'm overlooking something.. can someone take a look?

    Try spawning in 2 different enemies...(spacebar and ctrl)

    https://dl.dropboxusercontent.com/u/362 ... n_ind.capx

  • https://dl.dropboxusercontent.com/u/666 ... n_ind.capx

    Containers don't play well with families.

    I would suggest placing the enemies into a single object and using multiple instances/ frames.

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