How to work with an array of sprites

0 favourites
  • 5 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • I created an array of sprites. I want to be able to create a random sprite from this array every three seconds. When I select 'create object' Construct does not give me the option to select an item from the array. Can this be done in Construct? Can anyone help me out with the syntax? Thanks!

  • I think the easiest way to do it would be to have one sprite with a bunch of frames. That way you create the same object, but change the frame based on the array. Otherwise, you'd have to put them all in a family and reference things that way (I believe).

  • Try using Rex_nickname plugin. It allows you to create an object based in a given nickname (this nickname could be the value stored in the array).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What you'd do is:

    Every 3 Seconds
     > Set variable "var_randomsprite" to random(Array.Width)
     > Create object "Sprite"
     > Set Sprite.Width to Array.At(var_randomsprite, 0)
     > Set Sprite.8Direction.MaxSpeed to Array.At(var_randomsprite, 1)
    And so-on - you choose a random number first, then create your sprite with values according to the entry held at that value on the array. It's a bit of a mind-squeeze getting your head around arrays - but if you can master these and working with loops, you're pretty much set.
  • You can not create objects during runtime.

    You always create an instance (of an object) during runtime.

    Assuming dat we speak about animated sprites, then every sprite will have one unique object assigned to it.

    Every object needs to be in the layout before runtime.

    Therefor, create a placeholder object for every sprite in the layout. Assign a sprite to it from the array during an 'on layout start' event.

    (if you want a .cap from that stap, then post de .cap with the array)

    Then it is easy to use Construct's family-pick-system to create random things. As in this .cap



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