How do I make enemies spawn from every places

Get help using Construct 2

Post » Tue Apr 26, 2016 10:38 pm

So I used a template to make my game, and I can't understand how variables work.

Problem is my monsters are only spawning from the right, I want them to spawn randomly from both sides, and up and down. In short, from all directions. And all from outside the window.

How to do that?

These are the numbers:

Image
B
9
S
3
G
1
Posts: 20
Reputation: 1,169

Post » Tue Apr 26, 2016 11:25 pm

not the best version, but the easiest to understand
The global variable is TEXT and it just stores from which direction the enemy should appear
Edit: North, South, West, East
check the variable and place it slightly out of the layoutSize (30px)
to check if it is working just replace 30 with 0

Image

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707

Post » Wed Apr 27, 2016 3:16 am

Are you some kind of Wizard? That worked p-e-r-f-e-c-t-l-y. Like a charm. Thank you so much.

Just one question out of curiosity, is "N", "S", "E," "W" by default recognized as directions by Construct 2? So whenever I use these texts as variables, it will read as directions?

fm4fanAT wrote:not the best version, but the easiest to understand
The global variable is TEXT and it just stores from which direction the enemy should appear
Edit: North, South, West, East
check the variable and place it slightly out of the layoutSize (30px)
to check if it is working just replace 30 with 0

Image
B
9
S
3
G
1
Posts: 20
Reputation: 1,169

Post » Wed Apr 27, 2016 7:35 am

THX,

Just one question out of curiosity, is "N", "S", "E," "W" by default recognized as directions by Construct 2? So whenever I use these texts as variables, it will read as directions?


NO
it's just what I have chosen. You can take numbers or "L" "R" "U" "D" or whatever you like e.g. "left"

Line1: set variable to random direction in this case N, S, E, W
Line 2-5: check what variable is set
e.g. if "N" then create object on top of the screen

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707

Post » Wed Apr 27, 2016 9:25 am

In your original code, you spawn monsters in the layout at a X position of 1500 pixels and a Y position of between 0 and 1024.
The X position was always 1500, which makes it "right" if your windows size is less than 1500 pixels wide.

In your case, you could use further expressions :
In the X field : choose(random((Monster.Width*2)*-1,(Monster.Width) *-1)), random(LayoutWidth+Monster.Width, LayoutWidth + Monster.Width*2))
This made it choose between two location.
One location is a random value between - Monster.Width (the width of your Monster instance * -1) and double its width.
So this is the left border of the screen, negative values.

The other location is past the Layout width (right of the screen/layout) + an interval between monster's width and monster's width *2
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
296
S
119
G
96
Posts: 7,332
Reputation: 71,306


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests