How to prevent the sprite from leaving the layout?

For questions about using Classic.

Post » Thu Jun 30, 2011 8:33 am

Hi I'm new here.Sorry my English is bad.

I set a 8-direction movement for a sprite and it just keept on moving and moving until it disappeared from the screen.

But I want it to STOP moving when it reach the edge of the window.
Is there a way to do that?
Thanks!
B
2
G
1
Posts: 1
Reputation: 452

Post » Thu Jun 30, 2011 9:06 am

IF Sprite X<0: Set Sprite X = 0
IF Sprite X>[insert your layout Width]: Set Sprite X = [Insert your layout width]
IF Sprite Y<0: Set Sprite Y = 0
IF Sprite Y>[height of your layout]: Set Sprite Y = [Your layout height]

try itThe_Funny_Guy2011-06-30 09:06:51
B
16
S
5
G
4
Posts: 211
Reputation: 3,767

Post » Thu Jun 30, 2011 9:15 am

If you are using sprite with 8-dir movement you can create Tiled Background object around game window (outside the layer) and make that object solid.
No event, no coding :)shinkan2011-06-30 09:16:24
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Jun 30, 2011 1:17 pm

[QUOTE=shinkan] If you are using sprite with 8-dir movement you can create Tiled Background object around game window (outside the layer) and make that object solid.
No event, no coding :)[/QUOTE]
yes but the sprite will get neurotical attack whenever he'll hit the solid obstacle. with my method he'll just nicely stop without suddenly going apes***t
but bottom line is - yes, both methods will work just fine.
B
16
S
5
G
4
Posts: 211
Reputation: 3,767

Post » Thu Jun 30, 2011 1:23 pm

Can't remember this happen to me. but i'm always using square detectors not actual "hero" sprites... so yes it can start to move like crazy
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Jun 30, 2011 2:02 pm

Easy and effective way:

+ System: Always (every tick)
-> Sprite: Set position to clamp(.x, 0, LayoutWidth ), clamp(.y, 0, LayoutHeight )
B
2
S
2
G
2
Posts: 158
Reputation: 1,366

Post » Thu Jun 30, 2011 2:07 pm

[QUOTE=DtrQ] Easy and effective way:

+ System: Always (every tick)
-> Sprite: Set position to clamp(.x, 0, LayoutWidth ), clamp(.y, 0, LayoutHeight )
[/QUOTE]

Tell that to people who are still scared or never found system expressions

We're trying to help using simple and understandable things for begginers
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Jun 30, 2011 2:55 pm

It's never too early to start learning :)
B
2
S
2
G
2
Posts: 158
Reputation: 1,366


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests