...Spawn WITHIN the window's width and stuff?

Get help using Construct 2

Post » Wed Feb 12, 2014 4:22 am

Good evening, beautiful community!

Here I have another issue that may have a simple fix, but it's just something that my head can't figure out at this time of the night! What I am developing is some sort of infinite jumper - YES, I used the built-in "Infinite Jumper" template as reference - but with my own twists.

I want:

- To limit the spawn of some 32x32 platforms to be WITHIN the window's width only. Current problem: Everything spawns great on the Y axis (every 32px up), but on the X axis it sometimes ends up spawning continuously outside the viewport.

- To make the platforms spawn on the X axis either by exactly +32/+64px, or -32/-64px of the previously spawned platform. Current problem: The way I approached this was by saving the recently spawned platform's X in a variable (NewPlatformX) and telling the next one to spawn random() (like in below's pic). It works, but not the way I want - duh!



Hope that covers my bases and that it turns out to be a relatively simple fix, but right now, like I said, the night isn't helping me.

Thanks in advance!
B
13
S
5
G
1
Posts: 34
Reputation: 2,022

Post » Wed Feb 12, 2014 9:48 pm

Friendly bump. I still haven't found my way around spawning my platforms exactly 32 or 64 +/- pixels from the last one spawned. I checked tutorials regarding random terrain generation as that could give me a clue (maybe an X array is needed?) but still no-go.

I really hope somebody could enlighten me!
B
13
S
5
G
1
Posts: 34
Reputation: 2,022

Post » Thu Feb 13, 2014 3:30 am

Sorry for the late response, I believe you could maybe call an action on creation for the object to set it's position to a random integer within window.minimumX (far left of screen) and window.maxX (far right of screen)

Example: On Created (object.Platform) - Platform.Set X (rand.int(0-800))
// So that it chooses a spot between those two, im not exactly sure how to call a random number so you will have to find that out on your own.

Have fun!Rozen2014-02-13 03:31:00
B
6
S
2
Posts: 19
Reputation: 547

Post » Thu Feb 13, 2014 7:17 pm

@Rozen Indeed. I had already used the random(a,b) expression like in the picture above, and it all works wonders except for doing what I want: spawn exactly +/- 32 or 64 pixels after the latest platform created. That's what keeps bugging me.

Thank you for helping out, though! I may have to jump to your idea of setting variables with min/max and see what I can come up with after experimenting; perhaps saving specific coordinates to spawn on at all times instead of randomization with unnecessary results.

PS: Only after studying it I would've never thought that a lot of creativity and imagination is required to be a good programmer! Things don't fix themselves - that's for sure.
B
13
S
5
G
1
Posts: 34
Reputation: 2,022

Post » Thu Feb 13, 2014 11:12 pm

Hope this helps: infiniteSpawn.capx (r152)

B
55
S
29
G
19
Posts: 1,520
Reputation: 25,670

Post » Sat Feb 15, 2014 1:49 am

@ramones Thank you for that awesome example! It has certainly inspired me to do something radically different, but my infinite jumper game was finally fixed thanks to the choose() parameter (which I may have overseen before). However, I'm still not able to maintain the spawning of instances to be within the window/layout's width at all - not even by dealing with the viewport's sides individually like your example shows.

I'm very grateful for the help, guys. I'll keep trying to figure this out and hopefully, soon enough, you'll see a nice little game surfacing out of this pool of frustration!
B
13
S
5
G
1
Posts: 34
Reputation: 2,022


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests