loopindex load image

Get help using Construct 2

Post » Tue May 05, 2015 10:28 pm

I have a for loop and calling "Load Image from URL" with loopindex("levelCount") & "-2.jpg" into a created object.
All the images have been imported into the project as Files

The loop works fine but for some reason only the last image is being pulled out and so all images are the same, whereas they should all be different.

Current outcome:
Loop first pass pulls 3-2.jpg
Loop second pass pulls 3-2.jpg
Loop third 3-2.jpg

Expected outcome:
Loop first pass should pull 1-2.jpg
Loop second pass should pull 2-2.jpg
Loop third 3-2.jpg
B
9
S
3
Posts: 146
Reputation: 1,150

Post » Tue May 05, 2015 10:43 pm

All instances of Sprite share the same texture of the same frame in the same animation.
Image ImageImage
B
169
S
50
G
169
Posts: 8,291
Reputation: 108,226

Post » Tue May 05, 2015 10:48 pm

Its on purpose that it works like that, even though it makes little sense that it does. The only way to work around it is to add the number of frames you need before hand. So if you need a maximum of 50 images to be loaded you have to add 50 empty frames to your sprite.

When you load the image you have to increase the frame number each time, otherwise it will just overwrite the image regardless of you loading a new image. Also if you need to store images in different sprites (instances) you also have to do this workaround, as the image is loaded for all sprites of that object type, as picking is ignored when using "Load image from url"

So regardless of what you do, if you are not sure how many images you need you are going to waste memory or limiting you program.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Tue May 05, 2015 11:51 pm

Perhaps I need to add the jpgs as animation frames first as they are currently all separate files loading into the created object.
B
9
S
3
Posts: 146
Reputation: 1,150

Post » Tue May 05, 2015 11:56 pm

If you need X amount of images, you might as well add them before hand rather than using Load from Url as you need to add the frames anyway, so performance wise you wont benefit from using it "Load image from URL" or at least not a lot. If that is was you are trying to achieve by using it.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Thu May 07, 2015 5:05 pm

Not sure I'm tackling this the right way.
I thought that loading in a jpeg when required would make it quicker than trying to load in 100 at the beginning.
If I put the 100 images within animation frames would they all need to load before any could be used.

Basically which would take up less resources
1. Load from uri jpgs within files folder
2. Add all images as animation frames within one sprite
B
9
S
3
Posts: 146
Reputation: 1,150


Return to How do I....?

Who is online

Users browsing this forum: Lancifer, Yahoo [Bot] and 58 guests