Load image with AJAX during preview?

Get help using Construct 2

Post » Thu Jul 11, 2013 2:46 pm

Yo,
I've searched around and tried to figure this out but to no avail...
So, when previewing on localhost, where exactly would I point to with AJAX to get to images on my harddisk? Which also asks, WHERE should I place my files to load them?
It seems it's a good idea to load all images as "Project files", but in my game, I have LOTS of images, like 100's, possibly thousands (which is why I'm going to load them externally), so I don't think Project Files is a good way forward.
Also, when using an image in project files as a test, I could call the file with AJAX, and then tried "Load sprite from URL" with AJAX.LastData, but it wouldn't change the frame.
Any useful tips? :)
B
50
S
20
G
10
Posts: 570
Reputation: 9,792

Post » Thu Jul 11, 2013 3:12 pm

IIRC you cannot run AJAX from preview mode. Can anyone confirm?
B
38
S
16
G
8
Posts: 469
Reputation: 8,051

Post » Thu Jul 11, 2013 3:49 pm

I'll check it out, never tried exporting :P

EDIT: Ok, so the setup I have is that pressing a key will request the file with AJAX for the file "image1.png" with tag named "1".
Upon load, it will set a Sprite to the correct frame and then load image from URL from AJAX.LastData
Upon error, a sound will play to signify that it didn't load.
I tried exporting as nodewebkit both times.

On the first export, I had "image1.png" as a project file and exported. Opened the .EXE, pressed the key, and the frame would change to correct frame and no sound plays, BUT the sprites frame doesn't change.

On the second export, I had no project files at all, but instead, I put "image1.png" in the directory of the .EXE. Same results as previous; no sound, animation changed, but no actual sprite change.

I conclude: AJAX is detecting the files, but for some reason it's failing to load them to the sprites image.


EDIT2.0: Oh wow I just realised, AJAX actually retrives the ACTUAL image, rather than it's directory, which the sprite doesn't do anything with since "Load from URL" would require a... URL... not actual image data. XD

EDIT3: I realised project files aren't so bad after all; BUT I also discovered (also on another thread), that Load image from URL replaces ALL sprites image, not just the one specified. This is bad for my case :( Jase002013-07-11 16:34:56
B
50
S
20
G
10
Posts: 570
Reputation: 9,792

Post » Thu Jul 11, 2013 6:42 pm

If you use Sprite or Tiled Background's 'Load image from URL' it can load off the web, even in preview, providing the server sends the 'Access-Control-Allow-Origin: *' header. The node-webkit object can load files off disk, but they would have to be data URIs in text files!

Most cases where people need lots of images, they're doing something wrong (e.g. the player has 100 weapons, so they draw all 10 player animations again for each weapon, resulting in 1000 animations... when you could just make the weapon a separate object and position it by the player). Try not to use so many images. If you have to, just use project files, what's wrong with them?
Scirra Founder
B
378
S
220
G
84
Posts: 23,871
Reputation: 188,157

Post » Thu Jul 11, 2013 7:22 pm

@Ashley , I realised that project files are actually fine to use now, I didn't look into them enough til now :P Are project files only loaded into memory when they are called ingame? Or are they always loaded just for being a project file?
Also, I do the "Separate weapon object" method, but when having two weapons that I want to be different (Say I load image from URL for a sword on one "WeaponSprite", and an axe on another "WeaponSprite"), it would replace ALL the frames of all "WeaponSprite", which I can imagine is by design, but if that's the case, then I'm seriously trapped in my project D:
B
50
S
20
G
10
Posts: 570
Reputation: 9,792


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests