Changing Images at Runtime

This forum is currently in read-only mode.
From the Asset Store
500 monsters and creatures images for card games - Set 1
  • 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...

    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.

    For Each Texture

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

    This crashes Construct immediately. I have tried some different variations of this with the same result. How would I properly do this?

  • 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 + Source

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 think

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

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

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

    dl.dropbox.com/u/69407974/folder%20plus.png

    dl.dropbox.com/u/69407974/texture%20loading%20example.cap

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

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

  • Okay, I'll look at it tonight and see if I can fix the crashing for you

  • Looks like it was a mix of issues with loading textures every tick for each object, and also something with the file array events.

    I've bypassed the file arrays though, here's the image loading working: https://dl.dropbox.com/u/4714446/Texture_Load_test.zip

  • Thank you so much! Actually the issue turned out not to be the "For Each Texture" but the fact that I wasn't loading the files properly. I saw how you formatted that part, changed mine accordingly, and now it works!

  • Ah awesome, glad to hear crowtongue! Good luck with the rest of your game <img src="smileys/smiley4.gif" border="0" align="middle" />

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