How do I access a local url for an image

0 favourites
  • 10 posts
From the Asset Store
Ludo Local Multiplayer board game can be played by 2 to 4 players
  • I want to be able to access an image in a local folder using the load image from URL. I want my user to be able to swap it out by copying a new image to the folder and just renaming to the same name as the last image eg: "Background.jpg" or "myface.png". I had suposed it could be done with "images/Background.jpg " but that doesn't seem to work.

    Can anyone help?

  • Would the FileChooser object work for you?

  • Thanks zenox98,

    So if I were to use FileChooser how do I use that to set the URL of an image loaded into a sprite?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you are talking about the images folder that construct creates after exporting (which contains the images of the sprites etc.): you don't need to change anything in your event system. The swapped image will appear in the game (possibly it could lead to errors, if the swapped in image has the wrong format).

    If you are talking about imported files: if you created a subfolder, you load the sprite from URL with: "subfolder/image.png", if not you can just load "image.png".

    If you want your users to dynamically store pictures in the game, you could build an editor in your game. A textfield could be used for pasting in urls from images, a file chooser for local images. Load the images to a placeholder sprite and then use the canvas plugin (or paster plugin) to paste the images onto the canvas/paster and save the base64-string of the contents to webstorage (or a database of yours). Everytime your user starts the game, the value will be retreived and loaded into the sprite (if it exists).

    Modifying animations will not be practical.

  • Thanks mindfaQ I will look into all of these.

  • mindfaQ, I take it Paster plugin is not default with C2?

  • You stand correct.

    You can also use the native canvas screenshotting feature of Construct 2 for it (I think), but with it you will have to resize and reposition the screen for the screenshot to the resolution you need the image to have.

  • Thanks mindfaQ, That's not really what I had in mind. I want my user to pick one image in a folder. Then have the path to that folder update a bunch of other images.

    So if a background image is picked then a bunch of other images img001.jpg, img002.jpg etc all update from the same path.

  • If you are talking about the images folder that construct creates after exporting (which contains the images of the sprites etc.): you don't need to change anything in your event system. The swapped image will appear in the game (possibly it could lead to errors, if the swapped in image has the wrong format).

    If you are talking about imported files: if you created a subfolder, you load the sprite from URL with: "subfolder/image.png", if not you can just load "image.png".

    The subfolder method doesn't work for me. Does this need to be on a hosted folder or can it be localhost?

  • Hmm, looks like construct doesn't create the subfolders physically but instead dumps everything into the same (main) directory.

    So one way you could do subfolders would be adding the folder names and files after export to html. But you will probably run into problems with other exporters, where maybe you can't change the file structure.

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