How create actor in any random location off screen

MeToo

  • Posts: 355
Here is what I've tried, but it just keeps creating them in the same spot towards the top left of the screen.

TF101

  • *
  • Posts: 82
Hi,
Try to insert the "create actor" on the bottom and insert at x and y your Attributes at x and y of the create actor.

Create actor at x of asteroid and y of astroid

MeToo

  • Posts: 355
Thank you for your advice, however I'm still for the most part experiencing the same problem. My asteroids are set to all share a random trajectory.  Sometimes all of them spawn in that same top left region, sometimes most but not all of them do. I've attached the game file, hoping that someone can help me solve this.

Luyren

  • *
  • Posts: 2747
Your problem is your math. Your first random X condition is always creating between the border of the scene and the middle of the first quadrant of your scene, for example. Here is one example that creates the actor within the screen:
Code: [Select]
X of Camera + (random between 0 and screen width - Actor width)

So if you want off screen, use X/Y of camera minus the desired position for the left/up directions, and X/Y of camera + width/height of scene + your desired position off screen for right/bottom directions.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

MeToo

  • Posts: 355
Hello Luyren. Thank you again for your advice. I tried to implement your instructions as I understood them, except towards the end when you said "width/height of scene" I think you must have meant screen?

I'm still getting asteroids spawning in the top left quadrant. It's confusing. Here is my code and the save file:

« Last Edit: January 27, 2021, 02:17:56 pm by MeToo »

Max Marin

  • Posts: 138
I'm human

MeToo

  • Posts: 355
Thank you for your help Max. I would say that you did an excellent job of setting up an asteroid field for a different game than the type of game I'm trying to make. What I am trying to do is set up a game where the ship is always in the middle of the screen and eventually also program it so that's always facing the direction that the astroids are coming from, and all astroids are always moving in the same direction, all of this is to create the illusion that the ship is traveling through an asteroid field where the astroids aren't moving, and the ship will never run out of the scene. and I'm not trying to have all of them be on a collision course with the ship, though I want all of them to pass through the screen.  It's going to be a little tricky, frankly I still don't see why the Luyren's solution didn't work, it doesn't quite make sense to me. Again it was very nice of you to set up a viable asteroid field for a stranger and his game. But it's not compatible with the kind of game I'm trying to make. Do you understand what I'm going for?

« Last Edit: January 28, 2021, 01:03:10 pm by MeToo »

Luyren

  • *
  • Posts: 2747
If the asteroids are only visuals, why don't you use a background for that? You have blocks to change a background layer's speed, so you can manipulate the direction they are moving with that.

If you want a scene without boundaries, you can use this code at the beginning of it:
Code: [Select]
Engine.limitCameraToScene = false;And just create your asteroids outside of the camera boundaries. Again, remake your math from 0, go over my explanation one more time, and if that fails I can show you a screenshot or something.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

MeToo

  • Posts: 355
Thank you, Luyren. The astroids are not just visuals, colliding with them is part of the game. I am currently away from my computer but I am eager to try that bit of code you supplied for the limitless scene. I will also give a go at your math again going from zero. Thanks. I'll let you know what happens.

MeToo

  • Posts: 355
Thank you both very much for your help. Max's code spawns asteroids randomly at three out of four cardinal directions. It should be easy to see what he did and copy it for the fourth. I used your custom code Luryen and I was very excited because it seemed to be working, but if I move left or up the background goes away and it's just blackness. Whereas when I move down or right there is indeed infinite distance and infinite background. If I could use this infinite scene it would make the rest of my programming much easier, including being able to use a lot of native Stencyl behaviors for the rest of my game. Is there some alteration I can make to the custom code so that the backgrounds don't go away when I'm moving up or left?

Max Marin

  • Posts: 138
the first I think is what you want but the second is better try it ;D
I'm human

MeToo

  • Posts: 355
Thank you very much, Max. Those are both fun games you made: one about moving ever upward while horizontally dodging incoming astroids. And another in which the goal seems to be taking out asteroids that are coming at you from every direction.

My game is one where the ship is moving through an asteroid field with motionless asteroids.

 I will message the two of you with a bit more of the details so that you can understand what I'm trying to do. I know that generally the etiquette is to keep it in the forum posts in case it can help other people, but I don't want to make the details of the game I plan to make super public.

« Last Edit: January 29, 2021, 02:07:51 pm by MeToo »

Luyren

  • *
  • Posts: 2747
I've made a behavior that can make repeating background work as expected with the camera limit removed, attached in this post. It can configure multiple layer IDs with individual parallax factors, and assign them to specific scenes. The fix is based on the actor's X/Y speed, so you attach it to your player actor. It also includes the code to remove the camera limit if the current scene is included in this behavior's configurations.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

MeToo

  • Posts: 355
It works! Thank you so much. I used the importing method with the possibility of multiple backgrounds in the future. Thanks again, buddy!