How to randomly generate an object in specific image area?

  • 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:

  • 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

  • Thanks for the help,

    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?

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the solution,

    I'll try it and give a feedback soon. ^^

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)