How do I detect parallax positions (if obj is out of view)

Get help using Construct 2

Post » Mon Feb 08, 2016 8:21 am

Hi there,
I'm building a game with 3 layers of parallaxed background objects. They generate on the fly, out of the viewscreen, but I can't seem to determine how to check if they are out of screen from the spaceship which is always in the middle of the screen.

The parallax values get twisted each time a certain object is created in one of the paralax layers.

if Parallax is say 50,50 does that mean X and Y is X/2 and Y/2 ? If I compensated for the rest like that, would that theoretically work?

This is a space iphone game, and background moves and everything moves, while spaceship doesn't.
B
38
S
6
G
1
Posts: 306
Reputation: 2,902

Post » Mon Feb 08, 2016 9:20 am

If everything moves but the spaceship, maybe you don't even need parallax in different layers.

Can't you simply move each background at different speeds ?
ImageImage
B
44
S
14
G
10
Posts: 166
Reputation: 7,779

Post » Mon Feb 08, 2016 1:38 pm

@zed2100 I have a intuitive feeling that parallax is optimized better than moving something with code. I'm trying to keep the game really light because of mobile platform final destination.
B
38
S
6
G
1
Posts: 306
Reputation: 2,902

Post » Mon Feb 08, 2016 2:07 pm

You can implement both in separate projects and profile each of them using the development tools in chrome or firefox, then choose what to use in your specific case based on performance.

Personally I don't think there is any difference in performance between setting a x coordinate and trying to compute the exact position of an object in a layer with parallax. What I would be worried about is the delay in development such a feature may cause. You have to know the formula of parallax that C2 is using and adapt it to your game, then test to see if everything works. Sometimes you just have to do it in the most stupid way possible as long as it looks good, then move on to more important features.
ImageImage
B
44
S
14
G
10
Posts: 166
Reputation: 7,779

Post » Mon Feb 08, 2016 3:01 pm

@Zed2100 I can't argue with that :) Makes sense. I just don't want to go through the testing again, but If I have to :)
I'll try to find a solution and add it here because this forum is like a searchable massive manual :)
B
38
S
6
G
1
Posts: 306
Reputation: 2,902

Post » Mon Feb 08, 2016 3:56 pm

There are expressions for dealing with this: LayerToCanvasX, LayerToCanvasY...

https://www.scirra.com/manual/126/system-expressions
ImageImageImage
B
71
S
22
G
249
Posts: 3,762
Reputation: 138,575

Post » Mon Feb 08, 2016 7:11 pm

@blackhornet wow cool. I thought they could be what I needed but I abandoned the search. Thank you!!
Having some trouble applying this. How do I for an example move a sprite over my spaceship (my spaceship is not on a parallax, but the cube is on a 50,50 parallax) ?
B
38
S
6
G
1
Posts: 306
Reputation: 2,902

Post » Tue Feb 09, 2016 12:04 am

You convert from Layer Y to Canvas, then from Canvas to Layer X.
www.blackhornettechnologies.com/Constru ... ample.capx
ImageImageImage
B
71
S
22
G
249
Posts: 3,762
Reputation: 138,575

Post » Tue Feb 09, 2016 8:08 am

@Blackhornet Thanks man :) a .capx and everything. That should cure my stupid brain.
Here's another example where they transfer back and forth from parallax https://www.scirra.com/tutorials/1167/l ... er-example
for anyone needing this. :)
B
38
S
6
G
1
Posts: 306
Reputation: 2,902


Return to How do I....?

Who is online

Users browsing this forum: Cubeeo and 28 guests