Bounding multiple players to one screen

For questions about using Classic.

Post » Sat Oct 24, 2009 7:17 am

I'm having a "Doh" moment right now so please excuse my use of the no-question-is-a-stupid-question card. I have a camera set up to always focus on the center point between 3 players with platform behavior in a side-scrolling shooter game. So:

How do I prevent players from leaving the edge of the screen?

This is driving me crazy because it seems so simple yet I can't figure it out.
.cap on request; it's a little big.
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Sat Oct 24, 2009 9:10 am

You can either physically restrain the objects by checking that the distance between then is less than display width, or zoom out under the opposite circumstances....but its hard to say for sure without knowing how your moving the camera.
>system scroll to Qarp(spritea.x, spriteb.x, spritecx, 0.5)
should work most of the time, but there is a chance for objects to scroll off screen.
To restrain the objects the expression Distance(x1, y1, x2, y2) < display width should work.
Btw the custom movement behavior has that built in.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Oct 24, 2009 9:39 am

Couldn't you just make a solid "hollow box" sprite the size of the screen and always centre it at the point in between the 3 players?
B
55
S
12
G
8
Posts: 339
Reputation: 9,314

Post » Sat Oct 24, 2009 9:40 am

there is a system expression that returns the x position of the left edge of the screen, and top edge.

im not at my pc, so i cant give you the exact name of it, but if any sprite is less than that, set x position to left edge
if greater than screenleft+screenwidth, set position to screenleft+screenwidth
and likewise with y and the top of the screen
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sat Oct 24, 2009 4:28 pm

like lucid said, use variants of scrollx and scrolly to restrain player positions. scrollxleft just returns scrollx-(0.5*displaywidth), which is the left edge of the window. scrollxright returns the right edge, scrollytop and scrollybottom return the top and bottom of the screen respectively.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Mon Oct 26, 2009 1:15 pm

Awesome. Thanks everyone for your input! Hope to get it working as soon as some othe rnagging problems go away :)
B
51
S
13
G
8
Posts: 194
Reputation: 7,311

Post » Fri Oct 30, 2009 8:17 am

Players are constrained to the screen in the methods that Lucid and Davioware suggested and it works great. Everything is working great except one thing:

The camera is set to always be at an average X point between all active characters. If playerA is on the edge of the screen and playerB or playerC moves the other direction the camera gets pulled towards the playerB/C. Since this forces playerA off screen, the player constrain code kicks in and moves playerA back on screen. Visually, it looks like the camera is sliding player until playerB or C hits the opposite side of the screen.

Tried setting up a check where if any player were on the edge of the screen the camera wouldn't move, but that didn't work because then any player could hold against the edge of the screen to prevent the cam from moving.

Tried doing the same but making it to the camera could only move in the direction of the constrain player but my results were extremely jerky.

I've been working on this problem almost exclusively for the past 4 days and haven't be able to think up a acceptable solution. Looking for a little help :)

caps at mediafire:[url:2owa8hh8]http://www.mediafire.com/?gntyimzzyto[/url:2owa8hh8] and rapidshare:[url:2owa8hh8]http://rapidshare.com/files/299906295/Help02.cap.html[/url:2owa8hh8]
B
51
S
13
G
8
Posts: 194
Reputation: 7,311


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests