Spawn random at exact increments?

Get help using Construct 2

Post » Sun Mar 17, 2013 11:58 pm

I was wondering if anyone knows of a system expression to spawn a sprite randomly at 32 pixel increments?

Like this:



I thought I had this figured out sometime last year but I cant find my old .capx, and for the life of me I just cant figure it out again.

On start of layout --> System create object Sprite random(?), ?



Any help would be greatly appreciated.

Wink2013-03-17 23:59:15
B
50
S
11
G
8
Posts: 479
Reputation: 9,911

Post » Mon Mar 18, 2013 12:07 am

LightResponse !

First of all ... Set your object origin to 0,0

Then ...

Just add ;

Create object (floor((wantedX)/32),floor((wantedY)/32))

Here we go ,

You are pretty lucky I'm currently making a grid-pased proceduraly generated dungeon crawler :P

Cheers...
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Mon Mar 18, 2013 1:10 am

@Whiteclaws Thank you but I cant seem to get those expressions to work with what I am trying to accomplish.

Perhaps I haven't properly explained what I am trying to do. On the start of my layout I will be destroying the sprite. Then I want to spawn just one sprite randomly on my layout at specific 32 pixel grid based distances.

Here is a simple .capx with the sprite set to be destroyed on start of layout in case you or someone else has an idea on how I can accomplish this with system expressions:

https://dl.dropbox.com/u/43763487/examples/random.capx
B
50
S
11
G
8
Posts: 479
Reputation: 9,911

Post » Mon Mar 18, 2013 1:18 am

B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Mon Mar 18, 2013 1:25 am

Ahh, I see what I was doing wrong now.

Thank you very much Whiteclaws that's exactly what I wanted.

It works perfect
B
50
S
11
G
8
Posts: 479
Reputation: 9,911

Post » Mon Mar 18, 2013 1:30 am

Always happy to help people who helped me when I was a n00b
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Mon Mar 18, 2013 3:22 am

@Whiteclaws I think I might have spoke to soon.

It seems that your code only randomly spawns the sprite inside of the first 32 pixels. I was hoping it would spawn randomly across to whole layout at 32 pixel increments. Maybe this just isn't possible.

Thanks anyway for trying to help me.Wink2013-03-18 03:23:58
B
50
S
11
G
8
Posts: 479
Reputation: 9,911

Post » Mon Mar 18, 2013 11:20 am

Well , Just remplace the "/32" by "/16" , and that'll do the job !
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Mon Mar 18, 2013 11:44 am

Here is another example:

Random grid spawn
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Post » Mon Mar 18, 2013 7:24 pm

Here we go , Updated the capx. !
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Next

Return to How do I....?

Who is online

Users browsing this forum: Vegamon007 and 17 guests