Want a wrap effect but wrap behaviour is too inflexible

  • Have my game set in portrait mode and I basically want what is essentially a paddle in a breakout-like game to wrap to the other side of the screen instantly (so if the paddle sits perfectly on the edge of the layout the right side of the paddle sits on the left of the screen and the left side of the paddle sits at the right). Collisions intact. So the player can 'cheat' to get to the other side quickly and hit the ball. The wrap behaviour as it is isn't good enough for this. Will this be a complex thing to pull off it's just I don't have the slightest idea for what would be a good starting point. Thanks

  • Ok, so I've looked through the below topic since:

    And I downloaded the test.capx in the last post in that topic and what I want works perfectly in that test.capx. So I've tried to incorporate what works there into my own and... there is a wrap for my paddle but it isn't instant and seamless as the one in the test.capx. Going right results in the same sort of delayed wrap that the wrap behaviour does and going left results in my paddle disappearing before it hits the edge and then the same delayed wrapping as when moving to the right.

    X > LayoutWidth+self.Width/2

    set X to self.X-LayoutWidth-self.Width

    X < -self.Width/2

    set X to self.X+LayoutWidth+self.Width

    I'm trying to get a feel about what the code above means but I don't think I've got it. Could someone explain it to me, please?

  • Take a look at these 2 events. If you use 2 paddles exactly 1 WindowWidth apart and both with all the same behaviors (remove the wrap behavior), this will give you exactly what you want.


    The reason the example you found doesn't work is, it just moves the paddle to the other side of the screen. You can't split the paddle into two pieces to show on either side. My version fakes splitting the paddle by using 2 paddles. As 1 leaves the screen, the other enters the screen. When the paddle off screen gets too far to the left or right, it jumps to the opposite extreme. Since it's off screen when it jumps, the player never sees it and it just looks like the paddle is wrapping around.

    The attached capx shows how my method works.

    [Edit] modified the attachments to fix a bug

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [quote:3cs3assw]Take a look at these 2 events. If you use 2 paddles exactly 1 WindowWidth apart and both with all the same behaviors (remove the wrap behavior), this will give you exactly what you want.

    Wow. That's a brilliant idea for a workaround. Thank you very much. One thing, I think it is on my end (a setting of some sort) but when I run the capx the paddle disappears when it passes the center of the screen.

  • No, it was my fault. I used hard coded numbers when I created it and tried to modify it to go off the window width. See the modified version of the attachments. I put back the hard coded numbers. It's going off a window width of 400.

  • Thanks again. If it's not too much trouble, could you explain the code? I'm trying to get a handle on it but since I am using a different layout size I think the hard coded numbers are incompatible (the wrap is starting late). If I understood it better I might be able to go about making it work for my project. I did try LayoutWidth but that doesn't seem to work (object starts to disappear as it nears the edge, it does this in your capx if I use LayoutWidth in that). I think what's tripping me up is the hard coded numbers say 600, 800, etc, and I'm trying to figure out how that corresponds to the actual layout. Sorry for being so dense I just want to actually understand it.

  • Here is a breakdown of what is going on:



    Distance between the two paddles:

    400 (or equal to the LayoutWidth)

    Maximum position to the right the paddle can move:

    600 (equal to 200 or half the LayoutWidth to the right of the layout)

    Maximum position to the left the paddle can move:

    -200 (equal to 200 or half the LayoutWidth to the left of the layout)

    Distance to add or subtract from the X value when one of the max positions is reached:

    800 (or LayoutWidth * 2)

  • Damn it, I am a numbskull. My layout size was different to my window size. >O<

    It works now. Thanks for all your help.

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