Best way of wrapping starfield?

For questions about using Classic.

Post » Sun Sep 21, 2008 1:03 pm

Hi guys.

Whats the best way to make my stars wrap around the play area (when they go offscreen, to appear on the screen and the opposite side again).

I'm using paralax scrolling. I've done this by changing the scroll rate on the layer. However, when the stars move, construct thinks their X,Y position is the same (fair enough).

I mean, i could just screw the scroll rate idea and make them use the ball movement or similar and compare it to my ship's speed to make the stars appear to be paralax. But is there a good way to do this with construct's inbuilt scroll rate thingy?

Thanks,
Al
B
2
S
2
G
5
Posts: 448
Reputation: 2,546

Post » Sun Sep 21, 2008 1:40 pm

I just reset the XY when it leaves the play area. If the layout is 800 x 600 for example, just subtract/add the XY it leaves at based on which side it left.

As for the other issue, that may be something that can be added. An option to have the XY update based on actual position rather than where it would have been.
B
2
S
2
G
5
Posts: 391
Reputation: 2,432

Post » Sun Sep 21, 2008 3:12 pm

Why not make individual star sprites and have them always move in one direction and apply a wrap behaviour? Although it sounds like a resource hog, unless you are putting a huge amount of shaders and more than 200 stars on screen at one time then you shouldnt see much fps drop.
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Mon Sep 22, 2008 3:54 am

[quote="Jayjay":3ly5dn4n]Why not make individual star sprites and have them always move in one direction and apply a wrap behaviour? Although it sounds like a resource hog, unless you are putting a huge amount of shaders and more than 200 stars on screen at one time then you shouldnt see much fps drop.[/quote:3ly5dn4n]

That's exactly what I would do... you could still use paralaxed layers with that method... though I would probably make it so the stars moved on the angle the ship is moving, minus 180 so it gave a feeling of proper direction.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
45
S
17
G
37
Posts: 2,853
Reputation: 25,966

Post » Mon Sep 22, 2008 10:43 am

But if you're moving the stars, then actually, you want them to have a scroll rate of 0%...

Maybe I'll start doing it like that. However, I want to avoid using CPU abusive things at all costs, i mean, this game is going to have alot more stuff going on that is currently happening..

I'll look into these though, thanks guys.
B
2
S
2
G
5
Posts: 448
Reputation: 2,546

Post » Mon Sep 22, 2008 12:57 pm

Well, you could still use a scroll rate for each layer, that way you can have all the stars move with a single event instead of one event per layer. The event could move them all at the same speed, but using the layer scroll rate would give the layers in the "background" a slower natural movement.

I guess the other thing being, is it wouldn't use much CPU if the objects were using simple ball movement, and were looping/wrapping on a per screen basis and not covering the entire "level".

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
45
S
17
G
37
Posts: 2,853
Reputation: 25,966

Post » Mon Sep 22, 2008 1:28 pm

Umm... Does it currently take a lot of resources? Optimisation is futile if there is any need to optimise. And I think layer scrolling takes less resources from CPU, IF it's relying on some DirectDraw things. Does it, Ashley / Dave / Rich? Using ball/bullet/whatever movement takes more resources from CPU, 'cause it needs to calculate every object's position... But currently, if it isn't slow already, I wouldn't try to fix it.
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Mon Sep 22, 2008 3:02 pm

I think it's too early to worry about CPU usage. Try both ways running uncapped. I doubt the FPS will be much different.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Mon Sep 22, 2008 3:21 pm

I suppose my question is more "How do you check when a star has left the screen when using scroll rates, as scroll rates affect X,Y positions (2 objects may be overlapping, but if they are on different layers with different scroll rates their X,Y positions may be completely different)"?

And also, which side of the screen the star just left.

Any Ideas? Not entirely sure how this works in construct.
B
2
S
2
G
5
Posts: 448
Reputation: 2,546

Post » Mon Sep 22, 2008 3:41 pm

I can't check right now (ISP still being incompetent; at the library), but I think the ScrollXLeft, ScrollYTop, ScrollXRight, ScrollYBottom expressions give the current viewport, and if you add a layer parameter, it should give the appropriate values for that layer. Eg. on a parallaxed layer "Stars", ScrollXLeft("Stars") should give the X co-ordinate of the left visible edge. If this isn't implemented, then I'll try get it in to the next build. You could then use these values to determine if the stars have left the viewport of the parallaxed layer.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests