[Solved] How do I Load sprite frame from file

0 favourites
  • 11 posts
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • NWjs isn't creating a correct path to the file so it can never load. Function.Param(3) = "Textures/pawn-icon.png".

    Open image in a new tab to see un-forums-cropped version...

    I've tried using NWjs.DroppedFile too. Same result. NWjs properties do not have paths to files.

    What am I doing wrong?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What is the function Global_Log and what is Function.param(3)?

  • What is the function Global_Log and what is Function.param(3)?

    I added what F(3) param is above in OP. Global_Log writes to Console.Log. It shows "Textures\pawn-icon.png". It's correct.

  • Ok, so these on the right events are within a function..

    So http://localhost:50000/textures/pawn-icon.png does exist?

    Or Would you need a different directory?

    Seems like this is a preview and you are trying to reference a directory inside an exported project, or are these project-files we are talking about?

  • Ok, so these on the right events are within a function..

    So http://localhost:50000/textures/pawn-icon.png does exist?

    Or Would you need a different directory?

    Seems like this is a preview and you are trying to reference a directory inside an exported project, or are these project-files we are talking about?

    Right now I'm just running in preview mode.

    "Textures" is a folder in the Project root. Where should I put an image file that I want to load in code?

  • Project Files

    Yep that worked. Import it into "Files" then the path to the image is simply "pawn-icon.png"

    LittleStain Thank you!

  • The problem remaining is you MUST "import" the file in C2 editor. You cannot tell a Player to drop files in this folder and expect them to load when the game runs :-/

    Sadly a running C2 game has no way to reference a local file during runtime that wasn't imported during design/build time.

  • The problem remaining is you MUST "import" the file in C2 editor. You cannot tell a Player to drop files in this folder and expect them to load when the game runs :-/

    Sadly a running C2 game has no way to reference a local file during runtime that wasn't imported during design/build time.

    It does have "load image from url" and it has "filechooser" and there is the nwjs-object:

    The NW.js object allows access to features specific to the NW.js exporter, such as reading and writing files to the local disk drive.

    But I'm sure you have read The Manual extensively..

    Like this part:

    Previewing

    Note that previewing with NW.js runs directly from its install directory. As a consequence, the AppFolder expression will return the install path. If this poses a problem for you, use the following workaround: have a global string variable; if 'Is in preview' is true hard-code it to some development folder somewhere else.

  • In preview mode NWjs.AppFolder is blank. I'll try exporting to see if it then has any path string.

    Ok... so the manual, that I did read fairly thoroughly, has an error and is missing a sentence in the "Previewing" section. NWjs.AppFolder does not contain the install folder in "preview" mode. It is blank. You must export your game as NWjs for AppFolder to contain the path to the install folder.

    So this evening I'll try hard-coding a full path like "C:\somePath\someFolder\pawn-icon.png" in the Sprite.LoadFromUrl method and see what happens. According to the manual, this will load the image from disk.

    EDIT: Actually the manual quote above about hardcoding a path is referring to the NWjs methods like Read and Write, not the Sprite.LoadFromUrl. So my test above will fail. So the answer to my OP is you must be running an NWjs exported project to load a Sprite image (that is not known prior to runtime and imported into C2) from disk. That's the only way you can do this.

  • LittleStain Thanks again for your replies. I have a much better understanding of the limitations of loading from disk now

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