Convert to a sprite animation at fps speed with x or y frames

The arguments x and y set the number of frames in the texture. Use x for an horizontal arrangement or y for vertical. One and only one of the arguments must be different than 0, as an animation can only be on a line and cannot wrap.

Property definitions

gamnit :: flat_core $ Texture :: to_animation
	# Convert to a sprite animation at `fps` speed with `x` or `y` frames
	#
	# The arguments `x` and `y` set the number of frames in the texture.
	# Use `x` for an horizontal arrangement or `y` for vertical.
	# One and only one of the arguments must be different than 0,
	# as an animation can only be on a line and cannot wrap.
	fun to_animation(fps: Float, x, y: Int): Animation
	do
		assert (x == 0) != (y == 0)

		var n_frames = x.max(y)
		var frames = new Array[Texture]

		var dx = (x/n_frames).to_f/n_frames.to_f
		var dy = (y/n_frames).to_f/n_frames.to_f
		var w = if x == 0 then 1.0 else dx
		var h = if y == 0 then 1.0 else dy
		var left = 0.0
		var top = 0.0
		for i in n_frames.times do
			frames.add new RelativeSubtexture(root, left, top, left+w, top+h)
			left += dx
			top += dy
		end

		return new Animation(frames, fps)
	end
lib/gamnit/flat/flat_core.nit:605,2--631,4