Use an Array for Image Loading?

Discussion and feedback on Construct 2

Post » Thu Jul 21, 2011 5:15 pm

Hi,


I got a layer with 500+ same size Sprites, which must be set in continued rows and columns.

In Flash I would give a value in an array the parameter "image" and "position", like array[0][0].image = "myfolder/image.png".

My question is, Is there a way in c2 to handle multiple Sprites in an Array?
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Thu Jul 21, 2011 5:46 pm

Hi I'm a bit confused by your message, I'm not sure exactly what you want to do.

Your title leads me to suggest that you want to load images in sprite during runtime. (which I believe isn't available in C2 at the moment, was in CC with an event like "Animation: set image at frame").
But the rest of the message makes no reference to this and speaks about "handling" multiple sprites ?

I'm a bit lost, would you care to explicit what is it that you want to achieve and the method you would like to use to achieve it ?
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: 7,000
Reputation: 57,795

Post » Thu Jul 21, 2011 6:00 pm

The sprites need to be loaded at runtime, because these are many sprites and they could change by file.

But the first thing i would know, if there is a way to automatically place inserted sprites in rows an columns at specific distances, in this case the height/width of the sprites.
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Thu Jul 21, 2011 6:10 pm

[QUOTE=xeed] The sprites need to be loaded at runtime, because these are many sprites and they could change by file.[/quote]
As I said, this is not implemented in C2 yet I think.
You need to have at least one sprite containing all your images.
You could then create instances of this sprite, stop the animation and set the animation frame to the sprite you want to display.

[QUOTE=xeed]But the first thing i would know, if there is a way to automatically place inserted sprites in rows an columns at specific distances, in this case the height/width of the sprites.[/QUOTE]

Automaticly as an event "Map grid", no. You would need to code some loop.

A loop that would go through each sprite instance and position (set its X and Y) accordingly to what you tell it to. (a function referencing its row, its column and using its width and height as parameters)
(action Sprite:Position, field X and Y)
You could also set the animation frame to this instance to display the image you want.

Is a tile map what you have in head ?Kyatric2011-07-21 18:12:34
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: 7,000
Reputation: 57,795

Post » Thu Jul 21, 2011 6:33 pm

So the duplicated Sprites do have instance numbers? That would help a lot! I am new at construct, could you tell me how to access an instance of a Sprite for the loop?

And I could make the map with the Tile Editor too, yes. But I think c2 does not support these maps at this time.
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Thu Jul 21, 2011 7:22 pm

You have the event System:Pick the nth instance self explanatory in which actions you code will only affect the one object (sprite in our case) picked.

Else I will link you to Ashley's post which explained me how C2 handles events and which is a good post to bookmark ^^
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: 7,000
Reputation: 57,795

Post » Thu Jul 21, 2011 9:40 pm

Thanks, this help a lot.

For creating the columns the easiest way would be a second "for each" inside the first. But how can I put a "for each" inside another one?

(interleaved loops)xeed2011-07-21 21:45:23
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Thu Jul 21, 2011 9:56 pm

For each (object) will go through every instances of an object.

For your columns, you might prefer using a "for" loop (similar to the "for" structure in many coding languages) as a subevent.

You are asked Name (as the name for the loop), the starting and ending index.
Use the expression "loopindex" to have the actual index in the loop.
Kyatric2011-07-21 21:57:09
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: 7,000
Reputation: 57,795

Post » Thu Jul 21, 2011 10:16 pm

So I need to put the for Each as Event, and the for as subevent of this Event? I'll try this right now.

Another question is, is there a way to automatically set exact positions for every Sprite after they where put in? I dont speak about the ground Sprites with the for-loop. I mean that all Objects on a layer should be auto set in a raster, on dependence in which "square" x and y of the Sprite is pre-set per Drag and Drop. I hope you know what I mean, my english is not the best. :D
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Thu Jul 21, 2011 10:35 pm

[QUOTE=xeed] So I need to put the for Each as Event, and the for as subevent of this Event? I'll try this right now.[/quote]

Well as explained in Ashley's post, acting on an object will automaticly behave as a for each loop. So in theory you would only need the for "column" loop in which you'd have an action sprite:set position that will automaticly apply for each instances of this sprite.

[QUOTE=xeed]Another question is, is there a way to automatically set exact positions for every Sprite after they where put in? I dont speak about the ground Sprites with the for-loop. I mean that all Objects on a layer should be auto set in a raster, on dependence in which "square" x and y of the Sprite is pre-set per Drag and Drop. I hope you know what I mean, my english is not the best. :D[/QUOTE]

I'm sorry I'm lost there. ^^
From what we've talked so far I guess that you have a full grid of sprites (those we've been making so far) and you would like to use some of them as reference point on top of which other elements (different sprites) will be draged/dropped ?

So far C2 hasn't a Drag/drop plugin yet (unlike CC) so to have such a behavior you would have to emulate it in code. (code the interaction between the events of the object mouse and some destination sprite).

But maybe I'm missing the point. Try to explain what you want to do step by step. Also what is your language ? I speak French, English and a bit of German.
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: 7,000
Reputation: 57,795

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 12 guests