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

0 favourites
  • 6 posts
  • 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. <font color=red>Current problem:</font> 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. <font color=red>Current problem:</font> 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!

    <img src="http://i60.tinypic.com/211utyh.png" border="0" />

    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!

  • 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. <img src="smileys/smiley24.gif" border="0" align="middle" />

    I really hope somebody could enlighten me!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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!

  • 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. <img src="smileys/smiley19.gif" border="0" align="middle" />

    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.

  • Hope this helps: infiniteSpawn.capx (r152)

    <img src="https://dl.dropboxusercontent.com/u/8367729/construct/pics/infiniteSpawn.PNG" border="0">

  • 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! <img src="smileys/smiley41.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)