Read an Xml file, create sprites from data

Discussion and feedback on Construct 2

Post » Fri Oct 16, 2015 9:14 pm

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 :-)
Last edited by locohost on Fri Oct 16, 2015 9:24 pm, edited 1 time in total.
B
13
S
4
Posts: 280
Reputation: 1,578

Post » Fri Oct 16, 2015 9:17 pm

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

Post » Fri Oct 16, 2015 9:30 pm

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
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Fri Oct 16, 2015 9:36 pm

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

Post » Fri Oct 16, 2015 9:42 pm

filechooser?
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.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Fri Oct 16, 2015 10:01 pm

Interesting. I'll look at that. Thank you!!
B
13
S
4
Posts: 280
Reputation: 1,578

Post » Fri Oct 16, 2015 10:03 pm

"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)
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Fri Oct 16, 2015 10:15 pm

@jojoe Still reading but it looks like just the ticket! Thank you! :-)
B
13
S
4
Posts: 280
Reputation: 1,578

Post » Fri Oct 16, 2015 10:18 pm

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

Post » Fri Oct 16, 2015 10:22 pm

@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.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 12 guests