How do I create sprite if the comparison is true?

0 favourites
  • 14 posts
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • There is a grid of 4x4 and I've set the instance variables to the IID's. Like 1st sprite IID is equal to the instance var of the same sprite(1st sprite IID(0) = instance variable(0), 13th sprite IID(13) = instance variable(13). And there's an array having elements, so if the instance variable is equal to the array's element, a sprite will be created.

    So, how can I iterate through the instances and what should I compare them with?

    Help would be highly appreciated!!

  • I guess you need to either iterate the instances with "System For Each" loop, or elements in the array with "Array for each element" condition. Or both...

    But I don't really understand your task. What exactly you are trying to achieve?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've made 2 arrays, one stores the coordinates of all the sprites contained in the grid(so 16 coordinates stored). Other one contains the IID's of those sprites on which certain sprites need to be created(Those sprites have different behaviours). Also, if the array's element(2nd array) is equal to the instance variable(note that the instance variable is different for every instance of the same sprite), that certain sprite will be created. So I need to iterate through the 2nd array and instance vars of the sprites to made the comparison. I'm using for each but I'm getting the infinite loops.

  • Also, if the comparison is true, coordinates from 1st array will be used to create the sprite.

  • So, something like this?

    Array2 for each X element:
    .. SpriteA compare variable ID=Array2.CurValue
    .. : SpriteA spawn SpriteB
    

    I still don't understand why do you need that complex system with two arrays. Can you manually place sprites A on a grid and configure all properties in their instance variables, including the type of sprites B to spawn?

  • Many thanks, it worked!! I thought that running the entire stuff on start of the layout may be better than bringing stuff on the layout itself.

  • One thing more, I need to create the remaining sprites which is not equal to the 2nd array elements. Basically, it should be like, if SpriteA compare Variable != array2.CurValue: create spriteC on SpriteA where X = SpriteA(loopindex).X, Y = SpriteA(loopindex).Y

    But it is spawning 315 spriteC everywhere, so instead of that, I wrote.

    X = (SpriteA(loopindex) <> array2.CurValue)).X

    Y = (SpriteA(loopindex) <> array2.CurValue)).Y

    and that is still creating 315 spriteC but now on only one correct location.

    Need to create the spriteC on remaining spriteA. Should I set up the spawners on the layout screen?

    Help would be appreciated!!

  • Basically, it should be like, if SpriteA compare Variable != array2.CurValue: create spriteC on SpriteA where X = SpriteA(loopindex).X, Y = SpriteA(loopindex).Y

    Loopindex doesn't work in "Array for each element" loop, and CurValue doesn't work in all other loops. So I have no idea what you are talking about.

    I thought you decided to get rid of the arrays and configure all parameters directly in spriteA instance variables? Then compare the variable and spawn either spriteB or spriteC.

  • I'm using the arrays because I need to randomise the locations of those sprites which are not in 2nd array. 2nd array sprites just need to be in the static location in the 4x4 grid, other sprites need to be randomly placed.

    Any way to randomly create the sprites without using an array but with that 4x4 grid? Also, if the comparison is false, how can I spawn other sprites.

  • What do you mean by randomize? 16 instances with IDs from 0 to 15 distribute randomly in 4x4 grid? Or shift each instance a short random distance within the cell?

    Or, say 5 instances place on random cells on 4x4 grid, and the rest of the cells will remain empty?

    Either option is possible (and easier) without arrays.

  • 2nd option but in a opposite way. 5 instances of the sprite in locked location and rest 2 sprites instances placed randomly. Is it possible without using arrays?

  • There are many ways. You can use invisible placeholder sprites, or 16 image points on the Grid sprite. Or permutation table feature of AdvancedRandom.

    Example:

    Repeat 2 times
     Placeholder Not overlapping Sprite
     Pick random Placeholder
     ..Placeholder spawn Sprite 
    

    Or you can place 2 instances which need to be randomized outside of the layout. Then pick two random unoccupied placeholders and move the sprite instances to them.

    Repeat 2 times
     Placeholder Not overlapping Sprite
     Pick random Placeholder
     ..Sprite X<0
     ..Pick random Sprite instance
     .....Sprite set position to Placeholder
    
  • Okay, thank so much!! Also, just asking, it is better to leave the layout empty and create every stuff in the ES or lays sprites on the layout and set accordingly?

  • It's up to you, do what is more convenient.

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