Bounding multiple players to one screen

This forum is currently in read-only mode.
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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?

  • 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

  • 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.

  • Awesome. Thanks everyone for your input! Hope to get it working as soon as some othe rnagging problems go away

  • 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:http://www.mediafire.com/?gntyimzzyto and rapidshare:http://rapidshare.com/files/299906295/Help02.cap.html

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)