Use an Array for Image Loading?

Discussion and feedback on Construct 2

Post » Sat Jul 23, 2011 5:06 am

Errr you are overcomplicating things imo.

First thing first, Xeed you got it wrong considering the use of the array object.
Instead of having some system loops, you have an event within the array object to help you browse through it. (Array:For each element)

There you determine if you want to go through the X coordinates, the XY or the XYZ.

That means that some loops will be automaticly done (cycling through the coordinates) and the action you set will apply to the "cell" at said-coordinates.

For example I have a 10X10 array, I want to fill each cell with a value I'll do:
System:On startup of layout
..Array:For each element XY
.....Action - Array Set at XY

This action has 3 Fields : The X coordinate, the Y coordinate and the Value.
X and Y can be obtained with the system expression Array.CurX and/or Array.CurY (Where Array is the name you gave your array object).
Then you set Value as you like.

Instance Variables apply for the whole object. In your example, you modify the values of your variables posX and posY for the size of your array, but in the end, you only have a single value for each variable.

In fact, in your case, I guess that you would like something like :
X in Array represents an instance of sprite Ground
Y in Array will hold "posX" and "posY" (so respectively Y=0 and Y=1)

This mean that in array coordinates : 0,0 will be instance 0, posX for what you're willing to achieve. 0,1 will be instance 0, posY. 1,0 will be instance 0, posX, etc...

First thing to do in the startup is to set up the size of your array.
Action Array:Set size. Three fields again Width (X), Height (Y) and Depth (Z).

In our case, Width will be the final number of Ground instances that you will deal with (if instances are already created you can access it thanks to Ground.Count), Height will be 2 (posX, posY in your logic).

Then, you will have a "For each Ground" loop in which 2 actions Array.Set at XY will be used.
First one: X is Loopindex, Y is 0, Value is Ground.X
Second : X is Loopindex, Y is 1, Value is Ground.Y

And there you have it. Your array will be filled with the X and Y positions of each Ground sprite instance.
To access it : Array.At(X,Y)

If I want the position X of my 9th instance : Array.At(9,0) (9 is the 9th instance, 0 is X).
If I want the position Y of my 52th instance : Array.At(52,1)

There you got a "proper" use of the array object.
Take the time to get used to it, it's really tricky at first.



But in the end, I'm still not convinced that what you need is an array. As you didn't explained yet clearly what you are trying to do, I answer hit by hit to your questions but I think you're overdoing at some point.

I'm thinking that you are trying to compare a character's sprite coordinates with the Ground coordinates, to know where it is.
You could achieve this by checking which ground instance is the character overlaping, and you would then have direct access to the X and Y coordinates of ground without having to store them in an array.
But yet, as I don't know if that's what you want to do, maybe I'm missing the point there.

Anyway, hope to have helped about the array.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Sat Jul 23, 2011 5:21 am

If you want the array to be a virtual representation of the grid, going the vector way is definitely not the way to go. Going 3d is more intuitive and human readable, and take as much as memory space.

However, I don't think he needs any kind of array representation of anything. Normally, you would build a grid or map using the info you've got stored in the array, not the other way around.
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Sat Jul 23, 2011 5:37 am

[QUOTE=Magistross] and take as much as memory space.[/quote]

Are you totaly sure about this ?

[QUOTE=Magistross] However, I don't think he needs any kind of array representation of anything. Normally, you would build a grid or map using the info you've got stored in the array, not the other way around.[/QUOTE]

As I said, he aks, I answer ^^
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Sat Jul 23, 2011 6:48 am

[QUOTE=Kyatric]
Are you totaly sure about this ?
[/QUOTE]Yeah, in the end it all comes down to the number of elements in the array. A 10x10x2 3d array is pretty much the same as a 100x2 2d array in term of memory allocation.
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Sat Jul 23, 2011 5:05 pm

[quote]Then, you will have a "For each Ground" loop in which 2 actions Array.Set at XY will be used.
First one: X is Loopindex, Y is 0, Value is Ground.X
Second : X is Loopindex, Y is 1, Value is Ground.Y

And there you have it. Your array will be filled with the X and Y positions of each Ground sprite instance.
To access it : Array.At(X,Y)

If I want the position X of my 9th instance : Array.At(9,0) (9 is the 9th instance, 0 is X).
If I want the position Y of my 52th instance : Array.At(52,1)[/quote]

This is the information i was searching for. Just didnt know how to access more than one value for an instance.

I will try this and post a little tut for success in time. :-)
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Sat Jul 23, 2011 8:38 pm

Is there no way to set the array grid data without having a grid as sprites?
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Sat Jul 23, 2011 9:26 pm

[QUOTE=xeed] Is there no way to set the array grid data without having a grid as sprites?[/QUOTE]

Event
Array:For each element X or XY or XYZ
Depending on how you want to use the array.


New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Sun Jul 24, 2011 12:33 pm

Is there any keyword list here on Scirra to take a look at the sense of keywords like "Loopindex" in the Event Editor?

A kind of expression / function list for c2?xeed2011-07-24 12:35:40
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Sun Jul 24, 2011 2:36 pm

xeed, haven't you seen the object panel while the parameters dialog is up? It lists every expression available in the project.
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Sun Jul 24, 2011 2:46 pm

I'd see it, but it is not available for keywords like "loopindex", which are defined before the action.

Anyway, i tried to fit the coordinates of the grid into an array, but the output doesn't work. Text keeps "0". U got any ideas?

B
15
S
3
G
5
Posts: 396
Reputation: 4,977

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 16 guests