Load image with AJAX during preview?

0 favourites
  • 5 posts
From the Asset Store
Elevate your games with our AI Chatbot Integration! Seamlessly connect your Construct 3 projects with GPT-4 for dynamic,
  • 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? :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • IIRC you cannot run AJAX from preview mode. Can anyone confirm?

  • 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 :(

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

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

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