Creating objects on objects(randomly)

For questions about using Classic.

Post » Sat Jul 09, 2011 9:04 am

Well, to describe what i am aiming at:
Imagine ocean and islands. Islands are random size, shape,number and position. Now lets imagine i want to spawn trees within that islands but at random position.
Now how an i do this?
I know i could:
Set high number of imagepoints for each islands shape. And then make the creation be at random imagepoint.
Make trees spawn randomly over the whole layout but be destroyed if it spawns outside of the island.

First one is troublesome due to many reasons.
Second takes a while to execute.

I tried with spawning the trees randomly ON islands but obviously they ends up being spawned in the island center. I tried with islands position+random(range) but it only adds.

So i would like to spawn the trees ACROSS the islands.

Know any elegent way to do so?
B
16
S
5
G
4
Posts: 211
Reputation: 3,767

Post » Sat Jul 09, 2011 10:01 am

Well spawning means an object created by another object, so you will need to clarify if you want it spawned, or created by the system.
Either way you can get a ranged random from normalrandom().

As a spawn:
+>Island spawn object tree
->tree set position to island.x + normarandom(0,xmaxoffset), island.y + normalrandom(0,ymaxoffset)

As system create:

+>system create object tree at island.x + normarandom(0,xmaxoffset), island.y + normalrandom(0,ymaxoffset)

Then you can take that farther by using numbers as image points with random.
+>set global.value("rangen") to random(4)+1
->+>system create object tree at island.imagepointX(global.value("rangen")) + normarandom(0,xmaxoffset), island.imagepointY(global.value("rangen")) + normalrandom(0,ymaxoffset)
Given you have set up 4 image points numbered 1-4 on the island.

newt2011-07-09 10:03:10
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Jul 09, 2011 3:31 pm

[quote=].x + normarandom(0,xmaxoffset), .y + normalrandom(0,ymaxoffset)[/quote]

I've been looking for weeks for that... :/
constuct wiki is so not up to dateshinkan2011-07-09 15:31:51
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sat Jul 09, 2011 6:04 pm

Not related to create but more to ie. overlaping at offset.
If i do something like
[code]+ A: overlaps B : offset (10,10)[/code]- it checks if object A is overlaping B at lower right corner.
How to check if there's an offset all around object 10pixels?
Could easly do:
[code] + A: A overlaps B
   + System: distance(A.X, A.Y, B.X, B.Y) Lower or Equal to 10
   -> do something[/code]
but is there a way to do this inside "Is overlaping at offset" condition?shinkan2011-07-09 18:07:51
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sat Jul 09, 2011 7:25 pm

Well, if your islands are some random hard to define shape, all you need to do is for each island, run some loop that returns a random x,y position, check if that position is "safe" like on the island or wtv, and if it is, spawn the tree, and repeat until its populated with some arbitrary random number of trees.

you could also just run a loop a random number of times, create all the trees, and then check if the trees are on the island and destroy them if not it really depends how fast you want things to be.
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Sat Jul 09, 2011 7:28 pm

[QUOTE=shinkan] Not related to create but more to ie. overlaping at offset.
If i do something like
[code]+ A: overlaps B : offset (10,10)[/code]- it checks if object A is overlaping B at lower right corner.
How to check if there's an offset all around object 10pixels?
Could easly do:
[code] + A: A overlaps B
   + System: distance(A.X, A.Y, B.X, B.Y) Lower or Equal to 10
   -> do something[/code]
but is there a way to do this inside "Is overlaping at offset" condition?[/QUOTE]

Not without adding 3 other overlap at offset conditions.
You could add an array in a loop, but its just as contrived.
+>for x = 1 to 2
->for y = 1 to 2
-->sprite overlaps sprite2 at offset ({10,-10}@loopindex("x")),({10,-10}@loopindex("y"))
--->do stuffnewt2011-07-09 19:30:15
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sun Jul 10, 2011 5:11 am


Newt. If i would have been a girl, i am would be doing you a bj, right now.
i have NEVER ever heard about normalrandom expresion!
its basicly a range creator O_O
you dont have a bloody idea how many times ive needed that and i tried to mimic it via some crazy ass methods.
Now i consider wiki to be a real pile of poo. something so crusial and handy not being there...
B
16
S
5
G
4
Posts: 211
Reputation: 3,767

Post » Sun Jul 10, 2011 7:11 am

Normalrandom is fairly new, so that would explain why its not on the wiki.
Then again clamp() is in there, as well as many other expressions that give very brief descriptions that leave a lot to be desired.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests