[Solved] How do I Load sprite frame from file

Get help using Construct 2

Post » Sun Dec 06, 2015 4:04 pm

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

Image

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

What am I doing wrong?
Last edited by locohost on Mon Dec 07, 2015 12:41 pm, edited 5 times in total.
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Dec 06, 2015 4:08 pm

What is the function Global_Log and what is Function.param(3)?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Dec 06, 2015 4:10 pm

LittleStain wrote: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.
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Dec 06, 2015 4:19 pm

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?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Dec 06, 2015 4:33 pm

LittleStain wrote: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?
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Dec 06, 2015 4:51 pm

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Dec 06, 2015 4:59 pm

LittleStain wrote:Project Files


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

@LittleStain Thank you!
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Dec 06, 2015 5:06 pm

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.
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Dec 06, 2015 5:59 pm

locohost wrote: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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Dec 06, 2015 10:24 pm

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.
B
13
S
4
Posts: 280
Reputation: 1,573

Next

Return to How do I....?

Who is online

Users browsing this forum: Iftikhar555, jpstudio, LaurenceBedford, OddConfection, Xeeko and 14 guests