How do I Spawn an object using Array

0 favourites
  • 6 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • So I have an array, is there anyway to move a sprite from one block to another? Or to spawn an object on a block of the array that has a value of 1?

  • An array is a data structure, spawning an object from it makes no sense. If there is a 1-1 correlation between the array element and a screen position, then you can just use system.createObject using the array element indices.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yeah there is in this situation. The array is 36 by 36 (2D) and it fits the the whole screen. What I want is say one block of the array has a value of one, how can I make something spawn in that position

  • Assuming you're using X/Y dimensions of your array:

    Something like this should work. The second condition is System > Compare two values

  • Ok thanks! but why the multiply the Array.CurX and Array.CurY by 16?

  • Because CurX/CurY are indices into the array e.g. 0,1,2,3,4,5,6 and so on. If you use these as sprite positions they will overlap each other by one pixel. You scale it up by the size of the image you are creatting, in this case 16 x 16.

    I would advise not using the constant 16 though, but definiing a Global constant OBJECT_HEIGHT OBJECT_WIDTH so you can easily change it. Generally you should not have constants that represent a value in code unless it is something like "200" for a score (say).

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