I have about 60 images that should be able to change between 6 different pictures from time to time and I wonder what the easiest way to do this would be? Im am thinking of something like gotoAndStop in AS3.
Sincerely,
Max Tillberg
I have about 60 images that should be able to change between 6 different pictures from time to time and I wonder what the easiest way to do this would be? Im am thinking of something like gotoAndStop in AS3.
Sincerely,
Max Tillberg
60 placeholders?
Your best bet would to be assign a RenderTexture to each Image.
You can then freely update the texture without the need of re-instantiation - although this does require a re-cast.
RenderTexture(image.texture).draw(photo);
So 60 images in 6 'movieclips'?
If the textures are big:
Create 60 Textures; one for each of your images.
Create 6 Starling Images.
Set the texture you want to display to the Image instance you want to display it on.
else if the textures are small:
Create an AtlasMap (sprite sheet) of your images
Create 6 StarlingMovieClips
Show the correct image using MovieClip.currentFrame
If we aren't talking about animation, you can swap out the texture property of an Image.
var image:Image = new Image(texture1); addChild(image); //change texture image.texture = texture2; image.readjustSize(); //back to the original image.texture = texture1; image.readjustSize();
If the textures are the same width and height, then you don't need to call readjustSize().
Thanks a lot Josh, it works perfectly. So simple. I still have a question about defining the textures. In this case I defined them like this
// enables the use of the png image file [Embed(source = "image0.png")] private var StarlingBird1:Class; [Embed(source = "image1.png")] private var StarlingBird2:Class; var bmp1:Bitmap = new StarlingBird1(); var bmp2:Bitmap = new StarlingBird2(); // creates a Starling texture with our bitmap: var texture1:Texture = Texture.fromBitmap(bmp1); var texture2:Texture = Texture.fromBitmap(bmp2);
But I wonder if it would be better/easier to use a SpriteSheet, what do you think?
Sincerely,
Max Tillberg
Using a texture atlas will be better for performance than creating textures from separate bitmaps.
Ok, If I use a texture atlas I guess
image.texture = texture1;
will not work. Is there a similar function for changing between two images in a texture atlas?
Sincerely,
Max Tillberg
Have you called:
image.texture = texture1; image.readjustSize(); // <-- !!
?
I have a similar issue but in my case bitmapData object is being modified in a runtime (with draw function) sevreal times so it cant be predefined in texture atlas.
How to solve it, is starling proper for this?
What exactly do you want to do, and which problem do you have?
You must log in to post.