How do I change Sprite image after creating it?

0 favourites
  • 9 posts
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • 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?

  • 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.

  • 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.

  • 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,

  • 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.

  • Load from url will replace the corresponding frame for all instances, it is how it works.

  • Seems I found it in the closed bugs section:

    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.

  • [quote:2zk1r55r]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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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):

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)