Changing a texture in runtime
by Jake Vinson · in Torque Game Builder · 10/31/2005 (5:28 pm) · 1 replies
I'm sure there's something simple I'm missing here, but I can't figure out how to change the texture of an object dynamically.
An example of what I'd like to accomplish is something like a pachinko machine that creates a bunch of balls, which randomly pick a texture from a pool of 5 or so (for randomly different colored balls). I've found, using echo statements, that I can take the image map and assign a new textureName to it, which sticks, but doesn't apply to new instances of the object.
Do I have any options besides creating new image maps for each one? I'd prefer to just declare an array of possible filenames and randomly pick based on the upper bound of the array.
Alternatively, I haven't done anything with animation yet, but I suppose I could make an animation with each possible texture appear as a frame in the animation and just pick a random starting point without actually playing the animation...
Any ideas or suggestions?
An example of what I'd like to accomplish is something like a pachinko machine that creates a bunch of balls, which randomly pick a texture from a pool of 5 or so (for randomly different colored balls). I've found, using echo statements, that I can take the image map and assign a new textureName to it, which sticks, but doesn't apply to new instances of the object.
Do I have any options besides creating new image maps for each one? I'd prefer to just declare an array of possible filenames and randomly pick based on the upper bound of the array.
Alternatively, I haven't done anything with animation yet, but I suppose I could make an animation with each possible texture appear as a frame in the animation and just pick a random starting point without actually playing the animation...
Any ideas or suggestions?
About the author
Torque Owner Alex Rice
Default Studio Name
datablock fxImageMapDatablock2D( BalloonsData ) { textureName = "~/client/levels/balloons/images/balloons.png"; mode = cell; cellWidth = 85; // 6 * 85 = 510 (t2d will pad texture up to 512) cellHeight = 85; // 6 * 85 = 510 imageCount = 36; }; // later on for (%i = 1; %i <= 36; %i++) { ... %tPiece.setImageMap( BalloonsData, %i ); ... }Or if you don't want to make a cell-ed imagemap then just create 1 datablock for each ball, and then do like
I think that syntax would work but I have not tried it.