Populate Tree and move them

Get help using Construct 2

Post » Wed Dec 14, 2016 1:09 am

Ok so here the plan I want to populate a game full of trees but to manage Z order correctly between players and trees is madness. So I've figured that it would be far easier to move the trees away from each other so that I do not run into issue like being in-front of a tree when its suppose to be behind and etc.

So for this little game i have a 9 patch being use for the stalk of the tree to randomly generate different height without losing graphic issues. next I am using a invisible sprite with all the image point because i want the limbs and such to be the same height n width. but just on different height in scaled according to the tree height. That part i got it perfected. I even got a collision helper box at the base of the tree to help with the player Z order as in when to be in-front of the tree and behind the tree.

My problem is that I want to randomized the location of these ten trees and to not overlap each other. so in otherword I want to sort a lock the tree that are not overlapping so that the newer tree that get created that are overlapping to move somewhere else to fill in the space of the void.

problem is that i do not know how to implement such system for such creation.

I think it has to do something with a picking system but is there such a system where i can repick and recheck each ones but leaving other to lock cause i almost had it down but it infinity move the trees around so.....how do I lock each tree but keep moving the overlapping new tree around to a new space away from the tree . Or i could just simply Oppacity the tree to 0 when two are there to avoid the issue but id rather not.

here the pictures of what im talking about

Image

Image

Image
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Wed Dec 14, 2016 10:59 am

I need to avoid you about the efficience of this method:
  • It's not efficient;
  • Will consume a lot of CPU usage dealing with each object and ordering it;
  • The easiest way to do it is using family

Now, answering your doubt:
Try use it only on start of layout and when spawning the trees. Don't spawn trees over the entire layout, it will use precious resources for nothing. Limit it to the visualization area.
Sort it by its Y position and place the tree origin point on the top instead of the bottom, use another image point on the bottom if you want manipulate the trunk by there.
Sort the trees and branch by using "For each ordered" and select the trees, ordering by its Y position. The action should be "Place on the top", that's it.

Image
Image
Image
B
108
S
24
G
18
Posts: 1,373
Reputation: 22,824

Post » Thu Dec 15, 2016 12:27 pm

well the plan is to create such a randomized world so that no two player has the same game so to speak and yes what i didnt show is that you see the spawner code I have it base on global number so i can change to what ever and how many tree i want so its just ten so far.

the problem with your little example is that the tree is a 9patch sooooooooooo im limited

I cannot manage tree origin point cause im using 9 patch instead of sprite which is why i got pins like a ragdoll lol.

Alright so after trying your method it seem to not do anything other then reducing code structures. And im grateful for pointing that out now im having a problem of where the player is now alway behind the tree sprite rather then infront when approaching from bottom going up ward

And my question still stands how can can i spawn the trees to be furthur apart cause after restarting the game several times the tree get clumped up together like a dense forest which is what i dont want. but rather to be spread out but randomly placed.
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Thu Dec 15, 2016 12:53 pm

edited: nevermind here is a capx


Gearworkdragon wrote:And my question still stands how can can i spawn the trees to be furthur apart cause after restarting the game several times the tree get clumped up together like a dense forest which is what i dont want. but rather to be spread out but randomly placed.


that is easy, there are different aproaches... either use arrays, either create ur own array by using sprites/or a placer on bg and turn it on off then tell the tree where it finds place = the bg slots are not frame1 or overlapping a tree.

however you might want to look intro arrays, using sprites as arrays, will increase draw calls, even if they are not doing nothing, and cpu utilisation will basically explode if u got like over 3000 bg slots on a level map. which i guess ur going to do a large game... so yea.. Arrays.









or nevermind what i said about arrays, and try this capx edit 2
B
78
S
23
G
69
Posts: 1,353
Reputation: 44,005

Post » Thu Dec 15, 2016 2:11 pm

@gamecorpstudio What you got is where i have the problem.

What i am trying to do is to do something like if the first tree get created then just lock it in place and move on to the 2nd one so that it spread out with placement rather then jumping all over the place.

Ive manage to do get it to do the following either one way it will infinite move all teh object around or it wont move at all.

This has to be the most baffling thing ever Ive now tried to just do On created check its placement problem is that it wont activate the rest of the dam code or even let it repeat its own code im about to do the extreme by doing destroy recreate until it does what ive asked it to do. and I know that will just spike the dam cpu to no ends.
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Thu Dec 15, 2016 3:04 pm

...You can manage the origin of almost anything in C2.

Image

Try it, it will avoid events running everytick and slowing your game.
Image

You can also use
Image
Image
B
108
S
24
G
18
Posts: 1,373
Reputation: 22,824

Post » Thu Dec 15, 2016 11:27 pm

Wouldnt your last two line of code just wreck havoc on the actual zorder between player and the tree what if for example you got two tree only spaced out on the Y axis by say 40 unit apart just enough room to squeeze between them and by space out I mean at teh tree trunk not the actual size of sprite.

Let call bottom tree A and top Tree B, There is three possible Z axis ordering i need to happen is
One if player goes below treeA the player just need to be Infront of tree A and Tree B
Two if player goes between Tree A and Tree B The player need to be behind Tree A but infront of Tree B
Three if player goes above Tree B it need to be behind them both

this is just the basic what if there is three I can get possiblility 1 and 3 to work but on number 2 possibility ........It either Z order incorrectly such as the player goes through tree A but is infront of tree B

Ive tried pick instance Tree trunk helper sprite nearest to player to do the z order .....it just bugs out when there too many tree nearby. which is why I really need to space them out when spawning the trees.
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Sat Dec 17, 2016 2:51 am

ok i solve it seem like i was doing the events backwards Basically what i did was that i used a sprite helper at the size of each tree and then order the event in such a way

Image

so if anyone looking to how to move object randomly but not overlapping each other this is pretty much the code to do that
B
52
S
24
G
6
Posts: 391
Reputation: 7,845


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests