How do I change Sprite image after creating it?

Get help using Construct 2

Post » Sat Apr 05, 2014 10:35 am

Hi! I used Create Object for Sprites a few times in other projects and it seemed to work fine if you add some actions right after the create action to set instance variables or options.
But if I add "Load Image from URL" all created sprites have the same image. Do I have to add Instance Variables for the UID and add a loop for all instances (pick all) to change their image? Or is there another/easier way to do this?
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
56
S
17
G
6
Posts: 748
Reputation: 9,420

Post » Sat Apr 05, 2014 12:50 pm

Not sure what the problem is, how do you apply the image?

Also I posted a way to apply changes to newly created objects here: https://www.scirra.com/forum/the-annoying-picking-problem-ashley-please-clarify-it-ty_t101030?start=10

Which I have had great success with while testing it, and to be honest after I went through my game, I found several errors, where suddenly out of 50 objects 1 or 2 would fail for no apparent reason, so I change it to how I did it in the last post in the link. And haven't had any problems all objects get initialize without any problems. And decided to make this the standard way ill do it in the future. You can try it and see if it solves your problem as well.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sun Apr 06, 2014 6:18 am

It looks like this:
Something Happens > Create Sprite on Layer0 at x,y
---------------------------- Set Bullet Angle of Motion to 90
---------------------------- Load image from URL: URL here

Setting instance variables or changing behaviors like the bullet seems to work fine directly after creating an object to apply the changes to this object. But the Load Image from URL action seems to apply it to all instances of the object. (Sprite)

I will take a look at your link, thanks.
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
56
S
17
G
6
Posts: 748
Reputation: 9,420

Post » Tue Apr 08, 2014 3:33 pm

This seems to be a bug, this happens only with "Load image from URL", rest of properties and variables are working as expected.

I am too struggling for the same but no clue till now,
Image
B
52
S
12
G
2
Posts: 258
Reputation: 5,014

Post » Wed Apr 09, 2014 7:39 am

I am not sure, but it could be a bug since all other actions I tried seem to work different and "pick" the last created object as target.
It would be much easier (for my needs in this project) if it would just work like the other actions and change the image of the last created sprite. Did anyone else have problems with this?

Maybe I can add an Instance Variable with the image url/filename and create another "for x=1, numSprites" loop and then change the image of the sprites? I will test this when I have more time this evening. But I am not very experienced with picking objects, yet.
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
56
S
17
G
6
Posts: 748
Reputation: 9,420

Post » Wed Apr 09, 2014 1:23 pm

Load from url will replace the corresponding frame for all instances, it is how it works.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Thu Apr 10, 2014 9:09 am

Seems I found it in the closed bugs section: viewtopic.php?f=152&t=94873

But is it possible to add new frames on runtime and load a different image for all frames for a sprite object and then set the shown frame for each object?
I cant test it right now because I don't have access to C2 here.
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
56
S
17
G
6
Posts: 748
Reputation: 9,420

Post » Thu Apr 10, 2014 9:50 am

But is it possible to add new frames on runtime and load a different image for all frames for a sprite object and then set the shown frame for each object?
I cant test it right now because I don't have access to C2 here.

I don't think you can add frames to objects during runtime, at least not what I can see, you can however add the amount of frames you need before hand so it matches how many you need. And then just use them if you need or make it so it doesn't apply them if you don't.

Here is an example of how you can apply different images from URLs to your sprites. If you want to exclude some of them, you can change how the "Set frame" work in the object handler.

You could do the same without the object handler, by simply move it to the create event.
You do not have the required permissions to view the files attached to this post.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sat Apr 12, 2014 5:43 pm

Thank you very much! I changed the animation image in the for-loop and set it to loopindex and it works. :)

But I have some problems getting the image/sprite height after loading an image. It seems it is not updated properly after loading a image from URL.
Did you ever use Sprite.Height or .ImageHeigt after loading an image?
After many tries I were not able to get the proper values so I reported it (may be a bug): sprite-height-and-sprite-imageheight-not-working-properly_t101460
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
56
S
17
G
6
Posts: 748
Reputation: 9,420


Return to How do I....?

Who is online

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