How do I Spawn an object using Array

Get help using Construct 2

Post » Sun Jul 19, 2015 12:34 am

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?
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Sun Jul 19, 2015 7:05 am

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.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Mon Jul 20, 2015 3:12 am

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
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Mon Jul 20, 2015 6:10 am

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

Image

Something like this should work. The second condition is System > Compare two values
B
10
S
2
Posts: 33
Reputation: 710

Post » Tue Jul 21, 2015 12:10 am

Ok thanks! but why the multiply the Array.CurX and Array.CurY by 16?
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Tue Jul 28, 2015 6:14 pm

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).
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, Bootfit, Exabot [Bot], Google [Bot], Huemerson, unicornspitfire, Yahoo [Bot] and 3 guests