Want a wrap effect but wrap behaviour is too inflexible

Just started using Construct 2? Post your questions here

Post » Tue Mar 17, 2015 4:58 pm

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
B
8
S
2
G
1
Posts: 34
Reputation: 623

Post » Tue Mar 17, 2015 7:24 pm

Message: GDSag3 can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Ok, so I've looked through the below topic since:
viewtopic.php?t=72197&start=0#343000

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?
B
8
S
2
G
1
Posts: 34
Reputation: 623

Post » Tue Mar 17, 2015 7:39 pm

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.

Capture.PNG


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
You do not have the required permissions to view the files attached to this post.
Last edited by FragFather on Tue Mar 17, 2015 8:57 pm, edited 1 time in total.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Tue Mar 17, 2015 8:34 pm

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.
B
8
S
2
G
1
Posts: 34
Reputation: 623

Post » Tue Mar 17, 2015 8:58 pm

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.
Last edited by FragFather on Wed Mar 18, 2015 9:50 pm, edited 1 time in total.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Wed Mar 18, 2015 5:36 am

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.
B
8
S
2
G
1
Posts: 34
Reputation: 623

Post » Wed Mar 18, 2015 1:33 pm

Here is a breakdown of what is going on:

LayoutWidth:
400
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)
Last edited by FragFather on Wed Mar 18, 2015 9:49 pm, edited 1 time in total.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Wed Mar 18, 2015 9:25 pm

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

It works now. Thanks for all your help.
B
8
S
2
G
1
Posts: 34
Reputation: 623


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests