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

Get help using Construct 2

Post » Thu Aug 07, 2014 6:15 pm

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?
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
58
S
18
G
6
Posts: 756
Reputation: 9,591

Post » Thu Aug 07, 2014 6:49 pm

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
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Thu Aug 07, 2014 6:54 pm

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).
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
58
S
18
G
6
Posts: 756
Reputation: 9,591

Post » Thu Aug 07, 2014 7:10 pm

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))
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Thu Aug 07, 2014 7:29 pm

Thank you, I will try this tomorrow. :)

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.
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
58
S
18
G
6
Posts: 756
Reputation: 9,591

Post » Thu Aug 07, 2014 7:46 pm

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.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Fri Aug 08, 2014 1:15 pm

Thats it! Thank you very much! :D
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?

Image

/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:
Image
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
58
S
18
G
6
Posts: 756
Reputation: 9,591

Post » Fri Aug 08, 2014 3:52 pm

That stuff would go on a non scrolling layer.
Parallax 0,0.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Fri Aug 08, 2014 6:39 pm

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) ;)
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
58
S
18
G
6
Posts: 756
Reputation: 9,591

Post » Fri Aug 08, 2014 7:13 pm

Well the viewport is just a rectangle.
Offset from the clamp viewportLeft + offset, viewportTop + offset, etc.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests