Read an Xml file, create sprites from data

0 favourites
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Create a C2 app that is user customizable in that she/he can provide a folder of images and an Xml file. The Xml specifies certain set of game elements to create during runtime that correspond to the image files. Think "a TCG deck" for example.

    A C2 sprite cannot be dynamically created by a name/Id. So there is literally no way to do this in a C2 app other than hard coding a "card factory" function with an enormous block of if/thens?

    Thanks for any tips

  • I do know the "create a giant sprite sheet that has every card face" option, then you can select the sprite frame by an Id. But this means every card sprite in play is huuuuge because every card is the entire set of all cards! Wouldn't this use a S-ton of RAM when you get a bunch of cards out?

  • All cards are practically the same, except the copy on them and a few images specific to the card.

    You need a card.

    You need the info to populate the card and load in some custom image (character portrait).

    And you want user to customize it....

    Text file or json (both are easier than xml)

    Text use tokenat or regex

    json load into array or dictionary

    I know c2 can load images in, they just need a url which can be stored with all the data in text or json.

    Not sure if you can include from folder, but you can have user pass a url via his text/json file.

    Edit: I am talking from not actually having done this to such a degree

  • I know c2 can load images in, they just need a url which can be stored with all the data in text or json.

    Yes this is true, I've considered this, however I'd need to either distribute a Node/Express web app with the game just serve the images. Or I'd have to host the images on a web site, which is possible but not practical. Plus that means the game will never work offline.

    Someone must have made a plugin to load images from a local folder right? I'm searching...

  • filechooser?

    [quote:39gjhf3s]Using files

    Once a file has been selected, it can be accessed using a URL. While many URLs reference web resources on the Internet, the File Chooser plugin returns a special URL that refers to the local file. This URL typically starts with "blob:" (since the browser's term for an arbitrary set of data is a "blob") followed by some kind of unique ID. By accessing this URL the local file is accessed, without using any Internet connection, so this also works offline.

    The file URL can be used like any other URL. For example, it can be requested by the AJAX object to load its contents as text, or passed to the Sprite object's Load image from URL action to display it.

  • Interesting. I'll look at that. Thank you!!

  • "Someone must have made a plugin to load images from a local folder right? I'm searching... " -- locohost

    Ashley made an awesome one!

    Node webkit.... and drag and drop file. (it works for folders too)

    In your load from URL:

    NWjs.DroppedFile&"\images\PathToYourSprite\anotherPathToYourSSprite\YourSprite.png"

    Check the manual, there is a whole section on NodeWebkit, where it is explained very well. I am not sure if there is another way.

    You can also get the filename list, and loop through the names too, so you dont have to fill out the local path part at the end. (with a for loop)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • jojoe Still reading but it looks like just the ticket! Thank you!

  • Oh but wait, I think when you load the sprite image from url, it will change the image for every sprite on the screen, not just one particular instance. So you still would need a many, many unique sprite instances for each different card. Damn I think this kills it.

    We need to be able to create an instance of one sprite, call it "cardSprite", then load that cardSprite instance image from the file and not change the image of every other cardSprite instance.

  • locohost

    Use a background, or a single sprite and change the frames, the URL will load into the current frame,

    Backgrounds are the only ones that can have different images. Sprites can only have different images as different frames.

    Sprites can be scaled, but backgrounds can not, so it is up to your needs on what you pick.

  • jojoe Not sure I follow "Use a background". Can I place many instances of one small TiledBackground object (say it's 100px X 200px, whatever, small) on the layout, load it's image from a file using NWjs and then this will not change the images for the other existing instances?

  • System.create the background tiles one at a time in your loop, then load the URL right after you spawn it.

    Or give them a instance variable like "Type", so you can choose which tile you load it into with a system.pick by comparison: background.Type="Thumbail" (or whatever)

    sorry my english is not so great

  • or a single sprite and change the frames, the URL will load into the current frame

    Ok I think I follow this part. I could create one "cardSprite" that has the size for 60 cards, but the sprite sheet can be completely blank. Then each time I create an instance of cardSprite, increment the frame, then load the image into that frame. I think this will work right?

    Wait...

    But ultimately the cardSprite will eventually contain every card image in every frame in every instance of each card on the screen. So I may as well just start with a cardSprte that has every card image and then just switch frames based on the Xml data. it's no difference. Am I thinking right?

  • System.create the background tiles one at a time in your loop, then load the URL right after you spawn it.

    Or give them a instance variable like "Type", so you can choose which tile you load it into with a system.pick by comparison: background.Type="Thumbail" (or whatever)

    sorry my english is not so great

    Your English is pretty good

    This might be the way to go. I'll look into this.

  • "But ultimately the cardSprite will eventually contain every card image in every frame in every instance of each card on the screen. So I may as well just start with a cardSprte that has every card image and then just switch frames based on the Xml data. it's no difference. Am I thinking right? " -- locohost

    You got it

    Yeah get 52 frames in an animation, then cycle the frames and load each frame url.

    You can change animations if you want too as you load the images, so you can break it down into suits or whatever.Might be easier to deal with later if the card animation frame matches the number on the card.

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