How do I bound an object to current camera view?

Get help using Construct 2

Post » Fri Aug 12, 2016 11:55 am

Overview: If there was such thing as tags on solids that would solve the trick, but unfortunately if I just bound the view with invisible solids then enemies can't pass through (these enemies use bullet behavior as well, so if I try deactivating the solids when the enemy reaches it it'll just bounce off). So I need an alternative way to bound my player to the current visible space... Any suggestions?

Long story:
So I have a game where there are two types of bullet-behaving 'enemies'. The 'square' type bounces off the 'rectangle' type enemy as follows: rectangles are solids but they don't bounce off solids, and squares aren't solids but they do bounce off solids. The square enemy is also warp-behaving while the rectangle enemies aren't. I realised that when I change the viewport (aka screen) area, I can still move my player outside the viewport, but it is bounded by the layout. I want it to be bounded by the viewport (which is configured to be always inside the layout). Unfortunately as described above, if I try to bound the viewport using invisible solids, the square type enemies will also interact with them. If I only activate them/deactivate them based on certain touch-conditions, what if both a square needs to pass through and the player is touching them? So I haven't got any ideas left, any suggestions?

Thanks in advance!! :D

Eliclax
B
14
S
4
Posts: 17
Reputation: 938

Post » Fri Aug 12, 2016 12:01 pm

Bound your enemies or objects with events instead of using solid objects to bounce from.

If they exit the viewport by 1 pixel then have them change direction by something like (self.angle-random(170,190))

Is this what you want to happen?

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Fri Aug 12, 2016 12:15 pm

Maybe I should upload the capx.file

https://www.dropbox.com/sh/npf5lulci385 ... sx3Oa?dl=0

So in the 'Original' layout, if you run it, click and drag to start playing. You'll notice that if your height:width ratio is not exactly 2:1 then you can move the player outside of the viewport, but not the layout. The enemies (I'll call them bullet projectiles (bp) from now) are free to move in and out of the viewport, but the player isn't supposed to be able to do that. The square bps also warp though, so setting an invisible solid to destroy the bps will affect the square bps and they won't be able to warp.

And yes this is intended to be a mobile game, just in case you were wondering :)
B
14
S
4
Posts: 17
Reputation: 938

Post » Fri Aug 12, 2016 12:21 pm

I'll take a look... so you want to bound the player to the viewport, but not the enemy? Is that correct?

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Fri Aug 12, 2016 12:23 pm

Yes, Thanks! :D
B
14
S
4
Posts: 17
Reputation: 938

Post » Fri Aug 12, 2016 12:27 pm

Your link leads me to the project folder - but there is no capx file there (only a backup).

I'm going to suggest though without looking at it, that you can bound the player to viewport (at any size or shape) by using the method I mentioned above. I have done this for my camera object on a layout that is unbounded scrolling.

[If player.X is less than viewportleft("layer") + (player.width/2)]
--- Player.X set X to viewportleft("layer") + (player.width/2)

Do this for each side of the viewport (top, bottom, right) and your character player won't be able to leave the view, but enemies are free to move around the entire layout still.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Fri Aug 12, 2016 12:35 pm

Ok Thanks! I'll try that

In the meantime, how do I actually link something useful?
B
14
S
4
Posts: 17
Reputation: 938

Post » Fri Aug 12, 2016 12:45 pm

You need to save it as a single file, not as a project folder. Then you can link in dropbox like you did before, but to the file only :)

Like this EXAMPLE capx that I made which bounds the player to a definable area on the viewport. You can adjust the bounds as you wish - and can even set them to an expression if you want (like [player.width/2] for example).

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Fri Aug 12, 2016 12:57 pm

Ok I see

I hope this works: https://www.dropbox.com/s/ui2c41l5yd7c5 ... .capx?dl=0

I've PMed you the password (I just remembered this isn't a personal project)
B
14
S
4
Posts: 17
Reputation: 938

Post » Fri Aug 12, 2016 1:16 pm

That's a pretty cool idea for a game, nicely made so far as well :D

I think my example should do the trick for you. I was playing with mouse though, not sure if the player is supposed to appear so far away from the mouse cursor position or not - but I found it a little disorienting to control because of the offset to the cursor. The powerup collection and the effects are nice though. It has a nice feel even when using the mouse. I had to shew my browser into a funny shape though to get everything in screen - I didn't check what scaling method you're using but it's definitely not computer friendly lol.

The example I made will work for moving the player in any way (mouse, 8 direction, physics, etc) yet still keeping within the defined bounds (the minimum you can use is like 1, or maybe something as long as it's greater than 0).

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Next

Return to How do I....?

Who is online

Users browsing this forum: BackendFreak, farsen, lahbach, newt, TRMG and 17 guests