How do I clamp to a object ?

Get help using Construct 2

Post » Sun Apr 09, 2017 1:41 pm

...hi guys, how can i do this: a target is pinne to my ship..the target is bound to layout. If i go to touch the upper or lower limit it sticks there...this is what I want... since my lauout is very long..this will not happen with the left or right side... how can i achive the same effect also for right and left ? I think putting a sprite as barrier is fine...how can i clamp my target to the sprite ?

thanks
B
37
S
16
G
2
Posts: 447
Reputation: 4,865

Post » Sun Apr 09, 2017 7:17 pm

I'm not completely sure what you mean..
Do you want the Sprite to be bound to the right and left edges of the layout?

Otherwise, you can always use conditions such as
Code: Select all
IF Sprite.X < [desiredXmin]
THEN Sprite.X - set X to [desiredXmin]


and vice versa for the max value:

Code: Select all
IF Sprite.X > [desiredXmax]
THEN Sprite.X - set X to [desiredXmax]


If that's not what you want, please explain your problem more.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sun Apr 09, 2017 7:31 pm

hi, basicly its like the bound to layoout... but immagine that my layout is 20000 long and high 800. This means that the sprite is blocked on top and bottom...but disappaeras on left or right side since the window view is just 1500*800.... i would need something like "bound to screen" ...did u undersand my problem ? thanks
B
37
S
16
G
2
Posts: 447
Reputation: 4,865

Post » Mon Apr 10, 2017 7:38 pm

Alright, I see.
Okay, so just use what I posted above and replace the desiredXmin by the system expression ViewportLeft, replace desiredXmax by ViewportRight.

(Those two expressions return the X coordinate for the left/right edge of the window (not the layout).

Hope that this is what you need.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Tue Apr 11, 2017 11:18 am

To bound the edges to view port.


For each sprite
___System > compare two values .. Sprite.BBoxLeft < ViewportLeft ( the compare does not pick !, why the for each)
________ Sprite > set x to ViewportLeft + Sprite.Width
___Else
_________move the sprite as you are moving it currently
___System > compare two values .. Sprite.BBoxRight > ViewportRight
________ Sprite > set x to ViewporRight - Sprite.Width
___Else
_________move the sprite as you are moving it currently

or pick them this way

System > pick by comparison > expresssion = Sprite.BBoxLeft .. Less than value = ViewportLeft
For each sprite (if more sprites can exceed the boundary's at the same time)

Ether way, you have to pick them.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Apr 11, 2017 1:51 pm

thanks, could u do that on my capx ? iam sch a bad coder...
https://lookaside.fbsbx.com/file/target ... Y6JxOcDvcI
the target should NEVER leave the screen...
tahnks
B
37
S
16
G
2
Posts: 447
Reputation: 4,865

Post » Tue Apr 11, 2017 3:14 pm

you can use Scroll To behavior for the sprite
B
20
S
7
G
5
Posts: 16
Reputation: 3,908

Post » Tue Apr 11, 2017 7:30 pm

thanks
B
37
S
16
G
2
Posts: 447
Reputation: 4,865


Return to How do I....?

Who is online

Users browsing this forum: AllanR, Artcadev and 14 guests