How do I set an object's position to the borders?

Get help using Construct 2

Post » Tue Apr 22, 2014 1:13 am

We want the object to always start in the border. We need it to fit the size of the cellphone no matter what resolution we are using.
B
12
S
3
G
1
Posts: 188
Reputation: 1,377

Post » Tue Apr 22, 2014 7:42 pm

Anyone?
B
12
S
3
G
1
Posts: 188
Reputation: 1,377

Post » Tue Apr 22, 2014 7:54 pm

Take a look at the "Anchor" Behavior. Its meant for things like buttons or text that should always be in the same place.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Tue Apr 22, 2014 8:03 pm

I tried with this, but the object I want, should always stay on the edges of the window. It will work like an invisible wall, and must always be in that position no matter the screen size.
The problem is that the scale of the screen changes, when it is getting much in the middle and white edges appear.
Or do I improve the way I make the scale of the game, or simply adjust the object position and makes a bigger background.
Last edited by vitorfgd on Tue Apr 22, 2014 8:06 pm, edited 1 time in total.
B
12
S
3
G
1
Posts: 188
Reputation: 1,377

Post » Tue Apr 22, 2014 8:05 pm

Unless I've used anchor behavior wrongly, do not know if it will serve. Can someone explain to me how to do this?
B
12
S
3
G
1
Posts: 188
Reputation: 1,377

Post » Tue Apr 22, 2014 8:40 pm

Your probably using it wrong then... this is exactly the functionality your looking for. It guarantees the position of the object relative to the boundary of the layout regardless of scrolling or scaling. You only need to specify what corner (top,left - bottom,right , etc) to make sticky.

I my case I have text in the top left corner of the screen but I use inner scaling so it can crop of some of screen and potentially hide some of the text. To ensure my text is always approximately 50 pixels (give or take) or so from the top left corner of the view-able layout I set the Anchor Property "Left edge" to "window left" and the "top edge" to "window top" ensuring that the top left corner of my text is fixed in its location to the top left corner of the view-able screen.

I would play with it a little more. Or check out the manual. I'm sure this is what your looking for.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Tue Apr 22, 2014 9:03 pm

The anchor behavior only keeps an object in its position relative to the borders of the screen - it does not move it to the edge of the screen.

Have a look in the manual for "viewport". You can place the object using that system expression. For example, if you want to place an object touching the left edge of the viewable screen:

set Sprite.X to ViewportLeft("HUD" + Sprite.Width * 0.5) .... where "HUD" is the layer name of you HUD.

Have a look at this demo I put together for an example of this.
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,207
Reputation: 43,836

Post » Tue Apr 22, 2014 9:37 pm

I will test the hint here, then inform the result, hope this helps someone else ^^
Thanks @Colludium, is there any other topic that I can use to tell me more about it?
B
12
S
3
G
1
Posts: 188
Reputation: 1,377

Post » Tue Apr 22, 2014 9:46 pm

Always happy to help! I found these forums extremely helpful when I first started (I'm hardly an expert now!) so it only seems fair. Feel free to ask away when you get stuck.
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,207
Reputation: 43,836

Post » Tue Apr 22, 2014 11:49 pm

@Colludium yes, this forum is a great help for any developer. And people like you make this forum grow further, thanks ^ ^.
How can I adjust the size of my sprite according to the screen size? Could anyone help me with this? ^^
B
12
S
3
G
1
Posts: 188
Reputation: 1,377

Next

Return to How do I....?

Who is online

Users browsing this forum: tarek2, Yahoo [Bot] and 14 guests