lifebar - corner of screen even if moving

Get help using Construct 2

Post » Mon Apr 28, 2014 1:21 pm

What is the expression for the x and y positions of the top left corner of the screen?

I need it for my lifebar. I already have anchor behavior and also separate HUD layer with 0,0 parallax. But I want to set the position through events because there are multiple layouts (levels) and I want to avoid having to manually move the lifebar for each layout.

I already tried scrollx, scrolly and windowheight, windowwidth. so far, they don't work. I use start of layout as condition.
Last edited by sgn15 on Wed Apr 30, 2014 1:20 pm, edited 1 time in total.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Mon Apr 28, 2014 1:45 pm

Have you tried these :
ViewportBottom(layer)
ViewportLeft(layer)
ViewportRight(layer)
ViewportTop(layer)
Return the viewport boundaries in layout co-ordinates of a given layer. Not all layers have the same viewport if they are parallaxed, scaled or rotated separately.
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Mon Apr 28, 2014 3:59 pm

yeah i tried the left and top of viewport too. doesn't change the position. It doesn't do anything.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Mon Apr 28, 2014 4:21 pm

Hmmm... The top left of the screen should always be 0,0 on a 0 parallax-ed layer.

Make sure that the lifebar object exist on a layer with 0,0 parallax and 0 scale factor and on start of every layout set its position to 0,0.

You can do that with code so it happens automatically for all layouts:

On Start of Layout---> system | create "lifebar" on layer "HUD" at (0,0).

Of course this means that a layer named "HUD" should exist on every layout with its parallax and scale factor values set to 0.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Mon Apr 28, 2014 5:07 pm

oh? I was using the Set Position since I already have 1 instance of it in the layout. ok. Now, I first used Destroy on the existing one then create a new one. Never thought of that. Thanks!
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Mon Apr 28, 2014 8:30 pm

The Set Position should suffice for the first layout. I think that the anchor behavior was messing around with the position. You don't really need it, I think it's useful in circumstances like when the browser window change in size and you want the objects to dynamically adjust within the screen. Since you are interested in 0,0 coordinates, these do not change no matter what, so if you set the position once per layout you are ok!
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Tue Apr 29, 2014 3:26 am

@eli0s
My layouts are horizontally longer than the window size, so the game levels have a scrolling effect.

I'm still using your method (destroy existing ones then create new ones). I did not use set position.

I removed lifebar's anchor behavior, then I tried walking the character until the camera moves. The lifebar isn't scrolling.

I put back the anchor behavior, the lifebar moves with the scrolling BUT it seems to fail to keep up with the scrolling. It's like there's an "earthquake effect" or "teetering effect" on the lifebar (not sure if I described the effect correctly) while the camera is scrolling.

how do I fix this?
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Tue Apr 29, 2014 2:57 pm

Make sure that the lifebar object exists on a layer with its parallax values set to 0,0! You can get access to a layer's properties by clicking on a layer and then look at the properties panel.

All objects within a layer with 0,0 parallax values will not be affected by the scrolling. They will remain at their initial position on the screen, something that is ideal for HUDs.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Tue Apr 29, 2014 3:55 pm

@eli0s
it's ok already. I just forgot that I clicked undo on the changes I made to layer's scale but I forgot to change it back to 0

Can you teach me how to create multiple lifebars (for multiple bosses) ?

So far, this is what I did.

Start of Layout
->store the number of boss objects (using count) into a global variable

Then using that value, I need to create that same number of lifebars for each of the multiple bosses (top down from right side of screen)

The single lifebar at the left is for the player.

How do I position them (without overlapping one another) and also how to differentiate which lifebar is for which boss?

Please see attached pic for reference
You do not have the required permissions to view the files attached to this post.
B
16
S
7
Posts: 301
Reputation: 2,726

Post » Tue Apr 29, 2014 7:14 pm

This is the best I can do. It works, but there must be a more elegant way to do it.

http://eli0s.com/Tests/EnemyHealthBars.capx
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests