How do I Import IMAGE to a Sprite?

1 favourites
From the Asset Store
Elevate your games with our AI Chatbot Integration! Seamlessly connect your Construct 3 projects with GPT-4 for dynamic,
  • Hi All,

    Sorry for all the questions ;)

    I have a button called: "Btn_Import" I made the browser dialog to appear and let me select .PNG and .JPG files so far so good..

    Now, I want to PLACE the selected file in a specific frame of a specific sprite called: "BG_User"

    As you can see I've tried something but... I don't really know what I'm doing:

    Any tips doing this in the most efficient way?

    Screenshot of the code will be much easier for a noob like me to follow.

    Thanks ahead! :)

    Tagged:

  • Sprite Load Image from NWjs.ChosenPath

  • Sprite Load Image from NWjs.ChosenPath

    Thanks for the quick reply! :)

    I'm not sure if I got it correctly... what should I fix and how to make it work?

    When I choose the .PNG file, nothing happens I cannot see the image on the sprite which is waiting on the layout and it is visible (but the first frame is empty).

  • Sprite's 'Load image' action takes a URL, not a file path. They're not the same thing. You probably should use the NW.js object to read the file in to a Binary Data object, then load the Binary Data object's URL instead.

  • Ashley Load image from file path works in Construct 2, that's why I posted it. Didn't know it doesn't work in C3 anymore.

    Alon

  • If it works in C2, it's accidental and unintentional. File paths are not the same thing as URLs, but depending on the specific circumstances, sometimes a file path is accepted where a URL is expected and vice versa, but this isn't the kind of thing that should be relied on.

  • Ashley Load image from file path works in Construct 2, that's why I posted it. Didn't know it doesn't work in C3 anymore.

    Alon

    Thanks Ashley and dop2000

    I tried to follow the image but I got stuck when it asks for Destination parameter since it shows "No items" so I cannot proceed without choosing anything.

    Sorry for the confusion...

  • Add BinaryData object to your project.

  • Add BinaryData object to your project.

    Thanks!

    Now that it's imported how can I let the user remove it? (using a keyboard shortcut is fine)

    Do I remove it from the sprite? from the binary object? what's the most efficient way for memory cleanup consider the user can import image after image on the same session... how do I actually do that?

    You can easily tell how confuse I am.

  • Loading an image in to a Sprite unloads and replaces the existing image. There's nothing you need to do to manage memory if you keep loading in different images, the old ones are already being released.

  • Loading an image in to a Sprite unloads and replaces the existing image. There's nothing you need to do to manage memory if you keep loading in different images, the old ones are already being released.

    That's great! so the users can switch images as they want with no worries!

    Because I would like people with low-memory / older computer to be able to use this feature.

    I still don't know how to unload the image, I didn't found any unload option while exploring it,

    Can anyone please show me how to do that via screenshot so I can follow ?

  • Sorry for the bump, I could use some help:

    Can somebody please show me where the unload is hidden or even more helpful showing me via screenshot how

    I can unload the image that already imported using a keyboard press key?

    Thanks ahead!

  • Load an empty image, URI: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="

    Or destroy/recreate the sprite.

    Or load an image from another empty sprite.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Load an empty image, URI: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="

    Or destroy/recreate the sprite.

    Or load an image from another empty sprite.

    Thank you so much dop2000 it works great!

    I'm not even trying to understand how would I guess this "very short" combination of characters...

    just to get to unload an image.

    Shouldn't we have an "UNLOAD Image" option, thinking about noobs like myself... this is a scary line. :)

  • Any true programmer knows this short combination of characters by heart!

    Others (like me) can google something like "URI smallest image" and copy-paste it from stackoverflow.

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