Load Image from URL

Discussion and feedback on Construct 2

Post » Mon Nov 30, 2015 6:08 am

I have two sprites connected together in a container. On a certain event I create sprite1 and pin sprite2 to sprite1. And on every tick I set sprite1 to move and sprite2 moves along with it. I continually create sprite1 objects and each time the proper sprite2 seems to be pinned and everything is great.
But after this I use the Load Image from URL where the URL is determined by a subevent to update sprite2 and it seems all instances of the sprite get their image updated. I've tried putting an Opacity action in the same subevent and only the proper instance of sprite2 gets changed. Is there some issue with Load Image from URL not respecting the instance in an event?
B
6
S
2
G
1
Posts: 6
Reputation: 912

Post » Mon Nov 30, 2015 6:03 pm

the load image from url command replaces the current frame of the object so every object gets a new image, you can avoid this by giving the sprite an additional frame then just put an event like "sprite set frame to frame x" and then put the load image from url event, so the other sprites can keep the original image.
B
38
S
11
G
5
Posts: 485
Reputation: 5,340

Post » Mon Nov 30, 2015 8:27 pm

Can I add a frame on the fly or do I have to estimate the number of frames needed at edit time? Also these objects are getting created and destroyed constantly. You think I need some type of counter to figure out which frame to set it to?
B
6
S
2
G
1
Posts: 6
Reputation: 912

Post » Tue Dec 01, 2015 4:29 am

Is there any place that explains this better? I'm digging through the js and I'm trying to figure out what you mean by "replaces the current frame." Seems to me each instance would have a separate current frame.
B
6
S
2
G
1
Posts: 6
Reputation: 912

Post » Tue Dec 01, 2015 5:33 am

All the instances of a sprite share the same animation images. The current frame of an instance just references which image of that sprite object is used. So when you load a image from a url it replaces the shared image.

In other words say your sprite is named "sprite" and it has three animation frames.

Sprite object:
frame 1
frame 2
frame 3

Next you have four instances, all which use frame 1.

sprite instance 1 -> frame 1
sprite instance 2 -> frame 1
sprite instance 3 -> frame 1
sprite instance 4 -> frame 1

So now if you use the "load image from url" action the instance's image isn't replaced (instances only reference images), instead the "sprite" type's image is replaced.

You can't add a frame on the fly with the sprite object. You could just set each instance to use a different frame, but yeah you do need to add them at edittime.
B
94
S
33
G
118
Posts: 5,395
Reputation: 75,851

Post » Tue Dec 01, 2015 6:08 am

Thanks for the info. After some digging I finally figured it out as well. So at least I'm on the right track.
B
6
S
2
G
1
Posts: 6
Reputation: 912


Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests