How could i make an Image Texture appear on screen as it is moving? For Example, When i click the Open button, a Frame Appears in the middle of the screen with a texture like Image Label, i want this texture to appear moving.
How can i make an animated Image Label?
1 answer
Do you want it to move across the screen, or have an animation like a video or something?
Movement Animation
To animate the movement of a GUI element, you can use TweenSize() and TweenPosition()to animate size and position respectively, or use TweenSizeAndPosition()to do both at the same time. Take a look at the at the wiki.
Fixed/Video Animation
Another way to animate an element is to give it a sprite sheet to work with. If you don't know what a sprite sheet is, just search MegaMan Sprite Sheet on the web. It works by using a single large image where all your frames are located, and then accesses each one in a certain order to produce an "animation" (just different sections of the image displaying in quick succession).
To do so we use two properties of all ImageGUIs: ImageRectOffset and ImageRectSize. The latter sets the size of each sprite, and the former selects which frame will be displayed. After that, just create a script that can handle the sprites and you're done! I'll give you some example code that would work for this purpose.
while wait() do -- 'image' is a reference to the ImageLabel you want to animate. Replace the image of the ImageLabel with your sprite sheet
for i = 1, n do -- Replace 'n' with the amount of frames
image.ImageRectOffset = Vector2.new(image.ImageRectOffset.X + m, 0) -- Replace 'm' with the size of each frame
wait(.5) -- Change to the time between switching frames
end
image.ImageRectOffset = Vector2.new(0, 0) -- Resets to the first frame
end
The code above works only with horizontal sprite sheets. If you were to make a vertical or squared one, then the code must be adapted to do so. Hope this helps!
This discussion is preserved as it was. New answers, comments, and votes are closed.
