How to randomly generate an object in specific image area?

Get help using Construct 2

Post » Sun Jul 26, 2015 7:37 pm

Hi C2 community! ^^

I'm trying to randomly generate a scenic object in the red areas of the isometric image below and I'm not succeeding. I tried this using known techniques, but unfortunately I didn't succeed. Said object contains only one emergence and disappearance animation, without needing to be generated in the same place again.

Anyone have any suggestions to make it work?

Thank you in advance the attention and cooperation of the C2 community.

Example:
Image
B
39
S
9
G
3
Posts: 261
Reputation: 4,367

Post » Sun Jul 26, 2015 7:48 pm

It depends how you have the grid.

The easiest would be to have the red grids each be a separate sprite instance. Then you could give those squares a boolean instance variable "empty" with an initial value of true.

As an example say you wanted to create 100 trees, you could do this:

start of layout
repeat 100 times
redgrid is empty
pick redgrid at random
--- create tree at redgrid.x, redgrid.y
--- redgrid: set empty to false
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Sun Jul 26, 2015 8:00 pm

Thanks for the help, @R0J0hound. :D

Currently each red area is one separated image.

I actually want to create a random effect of bubbling lava on these red areas, so that some bubbles arise only while the player character is present on the screen.

What is the best solution in this case?
B
39
S
9
G
3
Posts: 261
Reputation: 4,367

Post » Sun Jul 26, 2015 8:40 pm

The same as above but instead of at the start of layout use every x seconds or something.

To only have tiles near the player bubble, use the pick by comparison condition with the distance expression to only pick tiles in a radius from the player.

You could also compare the x and y positions of the tiles to the edges of the screen.

Like for x you could do the picking like this:
X > viewleft
X< viewright

The same could be done for y.

A third idea would be to have an invisible sprite pinned to the player and then only pick tiles overlapping that tile.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Sun Jul 26, 2015 8:56 pm

Thanks for the solution, @R0J0hound. :D

I'll try it and give a feedback soon. ^^
B
39
S
9
G
3
Posts: 261
Reputation: 4,367

Post » Mon Jul 27, 2015 3:42 am

Better explaining my problem, @R0J0hound, I need lava bubbles arising in the red areas only when these areas are on the screen, so not to overload the memory of mobile devices.

Now I'm testing your recommendations. ;)
B
39
S
9
G
3
Posts: 261
Reputation: 4,367


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 17 guests