UI confetti effect

so im very new to UI effects but im trying to make confetti effect like u see in popular games. im trying to code the imagerectoffset, on the sprite sheet etc so i can animate the confetti.

unfortunately its not doing anything atm, but it is in the very left corner of the sprite sheet to start with. i appreciate any help!

sprite sheet function:

return function(self)
	local image = self.image :: ImageLabel
	local TotalFrames = self.attributes.TotalFrames
	local imageRes = self.attributes.ImageResolution
	local framesPerRow = math.sqrt(TotalFrames)
	
	local frameWidth = imageRes / framesPerRow
	local frameHeight = imageRes / framesPerRow
	
	image.ImageRectOffset = Vector2.new(0,0)
	image.ImageRectSize = Vector2.new(frameWidth, frameHeight)
	
	local currentFrame = 0
	local FPS = 60
	local frameTime = 1 / FPS -- time per each frame
	
	local row = math.floor(currentFrame / framesPerRow)
	local column = currentFrame % framesPerRow
	
	image.ImageRectOffset = Vector2.new(column * frameWidth, row * frameHeight)
	
	--reset currentFrame back to the beginning if it completed all frames
	currentFrame = (currentFrame + 1) % TotalFrames
end

code 2:

function confettiModule:Emit(count)
	local attributes = self.attributes

	for img = 1, count do
		local image = Instance.new("ImageLabel")
		self.image = image
		image.Name = "image"
		image.Parent = confettiGui.confettiFrame
		image.AnchorPoint = Vector2.new(0.5, 0.5)
		image.Position = UDim2.fromOffset(0.5, 0.5)
		image.BackgroundTransparency = 1
		local imageSize = math.random(attributes.Size.Min, attributes.Size.Max)
		image.Size = UDim2.fromOffset(imageSize, imageSize)
		self.imageSize = image.Size
		image.Position = UDim2.fromScale(0.5, 0.5)

		self.runServiceConnection = runService.RenderStepped:Connect(function(dt)
			--i'm calling the sprite sheet function here
			self:update()
		end)
	end

	print(self)
end


image

solved !

sprite sheet function:

return function(self)
	local image = self.image :: ImageLabel
	local TotalFrames = self.attributes.TotalFrames
	local imageRes = self.attributes.ImageResolution
	local framesPerRow = math.sqrt(TotalFrames)

	local frameWidth = imageRes / framesPerRow
	local frameHeight = imageRes / framesPerRow

	image.ImageRectSize = Vector2.new(frameWidth, frameHeight)

	-- Store animation state in self
	self.currentFrame = self.currentFrame or 1
	self.t = self.t or tick()
	local FPS = 24
	local frameTime = 1 / FPS -- time per frame

	-- Check if enough time has passed to update frame
	if tick() - self.t >= frameTime then
		self.currentFrame += 1
		if self.currentFrame > TotalFrames then
			self.currentFrame = 1
		end

		-- Calculate new position in sprite sheet
		local column = self.currentFrame
		local row = 1

		-- Find correct row and column
		repeat
			if column > framesPerRow then
				column = column - framesPerRow
				row = row + 1
			end
		until column <= framesPerRow

		-- Apply animation frame
		image.ImageRectOffset = Vector2.new((column - 1) * frameWidth, (row - 1) * frameHeight)

		-- Update timer
		self.t = tick()
	end
end

and the function call:

function confettiModule:Emit(count)
	local attributes = self.attributes

	for img = 1, count do
		local image = Instance.new("ImageLabel")
		self.image = image
		image.Name = "image"
		image.Parent = confettiGui.confettiFrame
		image.AnchorPoint = Vector2.new(0.5, 0.5)
		image.Position = UDim2.fromOffset(0.5, 0.5)
		image.BackgroundTransparency = 1
		local imageSize = math.random(attributes.Size.Min, attributes.Size.Max)
		image.Size = UDim2.fromOffset(imageSize, imageSize)
		self.imageSize = image.Size
		image.Position = UDim2.fromScale(0.5, 0.5)

		self.runServiceConnection = runService.RenderStepped:Connect(function(dt)
			--i'm calling the sprite sheet function here
			self:update()
		end)
	end

	print(self)
end

credits:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.