Changing Images at Runtime

For questions about using Classic.

Post » Sun Nov 18, 2012 6:35 am

I want to create an object based on each file in a directory and change its image to that file. I'm using Texture Setter in a similar fashion to this example...

http://dl.dropbox.com/u/5426011/examples15/tiles_TextureSetter.zip

My tiled background objects are called Texture. I am using a global variable called Folder to store which folder the user chooses.
I am using an array called Tileset to store the name of each file in that directory.

[QUOTE]
For Each Texture

Texture: Load Texture From File global('Folder') & Tileset(loopindex)

[/QUOTE]

This crashes Construct immediately. I have tried some different variations of this with the same result. How would I properly do this?
B
7
S
2
Posts: 123
Reputation: 1,061

Post » Sun Nov 18, 2012 7:26 am

I had to load my textures at runtime as well for my zombie game, and used a couple of different methods (tiled backgrounds, sprites, unique sprites + texture setter combos).

You might find the source useful: I Had Hope Alpha + SourceJayjay2012-11-18 07:26:56
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Sun Nov 18, 2012 8:22 pm

Sprite01.LoadFrameFromFile("Lava1.png")

this seems to work but it loads the same picture for every instance of a tile something i think many before me have encountered as a problem!DarkShroom2012-11-18 20:23:12
B
4
Posts: 31
Reputation: 412

Post » Mon Nov 19, 2012 3:09 am

@DarkShroom, yes but if you create a bunch of blank frames and load into them you'll avoid this issue of overwriting the same frame I thinkJayjay2012-11-19 03:10:18
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Tue Nov 20, 2012 7:07 am

DarkShroom: Yes that will only load one picture for each frame, also I'm using different tiledbackground objects.

Jayjay: Your project is interesting for a lot of reasons, and I'm going to spend a lot of time pouring over it and learning from it.

Unfortunately, since you know all of the files you are using you aren't changing textures in the way that I am. I am creating a bunch of objects based on how many files are in a folder that the user chooses, then each object is given the texture of each different file.

Since I have stored the path in a global variable, and each filename in an array, and ive tested that both are storing them properly I'm not sure what I'm doing wrong. Maybe it's too much for construct all at once? Maybe I'm unintentionally entered something improperly?
B
7
S
2
Posts: 123
Reputation: 1,061

Post » Tue Nov 20, 2012 2:25 pm

There is one case where I didn't know how many frames/files I'd be loading, you may find it interesting to look at the image loading code for the MapObject's

Hmm, that shouldn't be a problem if it can find each file alright. Can you upload your cap file with just events for texture file loading?
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Tue Nov 20, 2012 9:27 pm

Ok so I've gone through and stripped all of the events out. I haven't removed all of the objects that I don't need, but it should be close enough.

As it is it won't even start up, it crashes immediately.

If for whatever reason it does start, to add a folder click the folder with the plus on it and it should open up the browse directory common dialog. (I've included the graphic for that button incase it doesnt show up)

https://dl.dropbox.com/u/69407974/folder%20plus.png
https://dl.dropbox.com/u/69407974/texture%20loading%20example.cap
B
7
S
2
Posts: 123
Reputation: 1,061

Post » Wed Nov 21, 2012 2:48 pm

Looks like it's the "For Each Texture object" loop that's causing the crashing. It seems to be running every tick right now, is that what you need it to do or only during loading new texture files?
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Wed Nov 21, 2012 5:09 pm

Just once during loading. I think I actually tried changing it so another condition was when a variable was set it would start, but it still crashed after that.
B
7
S
2
Posts: 123
Reputation: 1,061

Post » Thu Nov 22, 2012 6:51 pm

Okay, I'll look at it tonight and see if I can fix the crashing for you
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests