VERY SERIOUS BUG! Sprite Created in Real Time For Loop Prob

Bugs will be moved here once resolved.

Post » Wed Sep 30, 2015 1:35 pm

Problem Description
If a Series of Image Sprites are Created in real time and then INSIDE the for loop calling each image sprite to load a different image, they will ALL load the same image.

Attach a Capx
http://expirebox.com/download/68be82f69 ... e1211.html

Description of Capx
CapX file plus the exported version, this will only work if running on server because of "Load Image from URL"

Steps to Reproduce Bug
  • Just run the program and see the code, the image boxes should load alternate different images, but they ended up all loading the SAME images.

Observed Result
Just run the program and see the code, the image boxes should load alternate different images, but they ended up all loading the SAME images.

Expected Result
They should all be loading different images.
This ONLY happens if the Sprite Object is created in a for Loop, it doesn't happen if the sprites are created in the Editor.
This is terrible, please fix this.

Affected Browsers
  • FireFox: (YES/NO)

Operating System and Service Pack
Windows 7

Construct 2 Version ID
The Latest Version
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Wed Sep 30, 2015 4:18 pm

This is by design. Instances of the same type all share the same animation images so if you load an image for one it changes that shared animation frame for all of them. The reason for this is memory efficiency.

Now if you want each instance to be able to have a different image you can use a different plugin besides Sprite. There are third party versions of the Sprite plugin that does that. I think it was called uniqueSprite or something.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Wed Sep 30, 2015 4:25 pm

You COULD also use the loop index and load each different image into a separate frame or animation, then set that specific sprite instance to that specific frame or animation. This should resolve your issue nicely without the need for third party plug-ins.
B
49
S
9
G
4
Posts: 426
Reputation: 7,071

Post » Wed Sep 30, 2015 8:13 pm

Dear R0J0hound, you are quite the expert here and I respect your opinion a lot.

What you see in the sample only instantiate the sprite, but I assure you if the instantiate component is a TextBox, the text boxes can all have unique text across all of them, I know this because I am actually doing it for a massive game for a school that loads thousands of student data and when the text box are real time generated and fill with unique data, you don't see them all having the same data but instead retain the unique text given to the TextBoxes upon its creation in the for loop.

The idea that it works like this across the board but the sprite doesn't behave like this really is a sign of a bug.
and a pretty serious one I might add.

In actual practice I am real time generating all the sprites calling them to load different student profile images.
The textboxes generated in realtime are filled with their data and the TextBox behaves perfectly.
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Wed Sep 30, 2015 8:18 pm

Dear Brashmonkey, not that this should be the way, but assuming your method work, This will have to do.
Now...How DO you URL Load images into a separate frame or animation as you have said ?
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Mon Oct 05, 2015 1:16 pm

Toddler wrote:Dear Brashmonkey, not that this should be the way, but assuming your method work, This will have to do.
Now...How DO you URL Load images into a separate frame or animation as you have said ?


I think he means adding more empty frames to your sprite object, then before you set "load image from URL" you first set the frame you want. You should also make the animation speed 0 beforehand.

So it would look like this

From 1 to 10
-Set sprite animation frame to loopindex
-load image from url
B
125
S
43
G
41
Posts: 849
Reputation: 28,260

Post » Mon Oct 12, 2015 4:04 pm

Closing as by design, exactly as @R0J0hound described.
Scirra Founder
B
403
S
238
G
89
Posts: 24,654
Reputation: 196,155


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 3 guests