Page 3 of 5

Re: Testing the new things in 0.9.0

Posted: Sat Jun 29, 2013 4:15 am
by slime
But love.window.isVisible works properly? ffffuuuuu

EDIT: I think I found the issue, but the fix will probably be a bit hacky... oh well.

Re: Testing the new things in 0.9.0

Posted: Sat Jun 29, 2013 4:23 am
by Santos
Yep, love.window.isVisible works just great, sorry! :rofl:


Here's an example of creating a SoundData and a Source from a base64 encoded string, and a couple of new SoundData methods:

Code: Select all

function love.load()
	data = 'RXh0ZW5kZWQgTW9kdWxlOiBzb2x... etc. Check out the .love file to test it!'
	filedata = love.filesystem.newFileData(data, '.xm', 'base64')
	sounddata = love.sound.newSoundData(filedata)
	source = love.audio.newSource(filedata)
	source:play()
end

function love.draw()
	love.graphics.print('Number of samples: '..sounddata:getSampleCount(), 0, 0)
	love.graphics.print('\nDuration: '..sounddata:getDuration()..' seconds', 0, 0)
end
solarbeams.love
(8.16 KiB) Downloaded 93 times

Blend modes!

replace is new, and alpha and multiplicative are different.
blendmodes.love
(25.07 KiB) Downloaded 96 times

Re: Testing the new things in 0.9.0

Posted: Sat Jun 29, 2013 3:59 pm
by Santos
love.math.random and such!
random.png
random.png (2.99 KiB) Viewed 2468 times

Code: Select all

function love.load()
	love.window.setMode(450, 170)

	love.math.randomseed(123)

	s = 'The random number generator is portable.\nIf you run this, you should also get the numbers ' ..
	love.math.random(100) .. ', ' ..
	love.math.random(100) .. ', and ' ..
	love.math.random(100) .. '.\n\n'

	rg1 = love.math.newRandomGenerator()
	rg1:randomseed(123)

	rg2 = love.math.newRandomGenerator(123)

	s = s .. '(Which are also '..
	rg1:random(100)..' and '..rg2:random(100)..', '..
	rg1:random(100)..' and '..rg2:random(100)..', and '..
	rg1:random(100)..' and '..rg2:random(100)..'!)\n\n'

	s = s .. 'These numbers are the same:\n'..
	rg1:random()..'\n'..
	rg2:random()..'\n\nAnd '..
	rg1:random(100, 200)..' is the same number as '..
	rg2:random(100, 200)
end

function love.draw()
	love.graphics.print(s, 15, 15)
end
randomnormal.png
randomnormal.png (1.55 KiB) Viewed 2468 times

Code: Select all

function love.load()
	width = 300
	height = 200

	love.window.setMode(width, height)

	imagedata = love.image.newImageData(width, height)

	image = love.graphics.newImage(imagedata)

	color = {255, 0, 255}
end

function do_thing()
	r = love.math.randomnormal(50)

	a = math.floor(r) + width/2

	for i = imagedata:getHeight()-1, 0, -1 do
		if a >= 0 and a <= width-1 then

			if imagedata:getPixel(a, i) == 0 then

				-- ImageData:setPixel now accepts a table with optional alpha.
				imagedata:setPixel(a, i, color)
				break
			end
		end
	end
end

function love.update(dt)
	do_thing()
	do_thing()
	do_thing()
	do_thing()
	do_thing()

	-- Image:refresh reloads an Image using the ImageData that created it.
	image:refresh()
end

function love.draw()
	love.graphics.draw(image)
end
love.timer.getAverageDelta!
averagedelta.png
averagedelta.png (16.5 KiB) Viewed 2461 times
Inspired by http://sol.gfxile.net/gp/ch02.html

Code: Select all

function love.load()
	height = 100
	width = 200
	love.window.setMode(width, height)
	oh = love.image.newImageData(width, height)
	yes = love.graphics.newImage(oh)
end

function love.update()
	time = love.timer.getTime() * 100
	oh:mapPixel(function(x, y) return decimal_to_rgb(y * y + x * x + time) end)
	yes:refresh()
end

function love.draw()
	love.graphics.draw(yes)
	love.graphics.print(
		'Average delta:\n' ..
		love.timer.getAverageDelta() * 1000 .. ' ms', 10, 35)
end

function decimal_to_rgb(n)
	local r = math.floor(n / (256*256))
	local g = math.floor((n - (r * (256*256))) / 256)
	local b = n - (r * 256*256) - (g * 256)

	return r, g, b
end

Re: Testing the new things in 0.9.0

Posted: Sun Jun 30, 2013 2:35 am
by Ref
Well, Shaders seem to be well & happy.

Re: Testing the new things in 0.9.0

Posted: Sun Jun 30, 2013 1:20 pm
by Santos
Font filtering and love.graphics.printf!

Code: Select all

function love.load()
	love.window.setMode(650, 100)

	font = love.graphics.getFont()
end

function love.draw()
	-- The filter style of Fonts can be set.
	-- When setFilter is given one argument, it is used when the object is either magnified or minified.

	font:setFilter('nearest')

	-- love.graphics.printf has "justify" align mode and transformation parameters.

	love.graphics.printf(
		'This is a test!',
		10, 10, -- position
		200, -- width
		'justify', -- align mode
		0, -- rotation
		3, nil, -- x and y axis scale (y axis defaults to x axis)
		0, 0, -- offset
		-0.3, 0 -- x and y axis shear
		)

	font:setFilter('linear')

	love.graphics.printf(
		'This is a test!',
		10, 50, -- position
		200, -- width
		'left', -- align mode
		0, -- rotation
		3, nil, -- x and y axis scale (y axis defaults to x axis)
		0, 0, -- offset
		-0.3, 0 -- x and y axis shear
		)
end

Re: Testing the new things in 0.9.0

Posted: Sun Jun 30, 2013 6:06 pm
by slime
FYI the 'justify' AlignMode is pretty broken right now. It needs major fixing/rewriting before it'll match real justified alignment.

Re: Testing the new things in 0.9.0

Posted: Mon Jul 01, 2013 4:35 pm
by Ref
[quote="Santos"]So I thought it would be cool to have a thread when 0.9.0 is released to talk about and show examples of the new functionality, but then I thought, why wait, it could be useful to talk about what's new now so it can be documented and tested with the nightly builds.
quote]
Just wondering where you live - that the nights are so long.
The last 'nightly build' was on June 24.

Re: Testing the new things in 0.9.0

Posted: Mon Jul 01, 2013 4:44 pm
by mickeyjm
Ref wrote:
Santos wrote:So I thought it would be cool to have a thread when 0.9.0 is released to talk about and show examples of the new functionality, but then I thought, why wait, it could be useful to talk about what's new now so it can be documented and tested with the nightly builds.
Just wondering where you live - that the nights are so long.
The last 'nightly build' was on June 24.
I'd guess Valve HQ

Re: Testing the new things in 0.9.0

Posted: Mon Jul 01, 2013 6:11 pm
by slime
Boolsheet's nightly builds for Windows are more up to date:

https://bitbucket.org/Boolsheet/love_wi ... ev-x64.zip
https://bitbucket.org/Boolsheet/love_wi ... ev-x86.zip

You can see when they were last updated by clicking on the 'branches' section here: https://bitbucket.org/Boolsheet/love_winbin/downloads

Re: Testing the new things in 0.9.0

Posted: Thu Sep 19, 2013 4:28 am
by Santos
Cursors!

This uses:
love.mouse.newCursor
love.mouse.setCursor
love.mouse.getCursor
[wiki]Cursor:getType[/wiki]

Click or scroll to change cursors.

Code: Select all

function love.load()

	watermelon = love.image.newImageData(love.filesystem.newFileData('iVBORw0KGgoAAAANSUhEUgAAABAAAAAdCAMAAACUsxyNAAAAG1BMVEUAAAD//8xm/2YAZgAAiAAAAAD/AJkAVQAAuwCd2kQ+AAAAAXRSTlMAQObYZgAAAHBJREFUeF6F0EEKQyEAA1GT/Nre/8QVDYNQoC4fE0E9kmRcJ5Z8SzSnKkAFeCEUFYCGCQ0TGqANExoKmgISJmsgtaBPUtBWAfIBF+RUNnhvxQvzed4JCfD8gHVPxgJLzn5dFi84JR8JIP+glzeonMEXBYEFSfnXZfkAAAAASUVORK5CYII=', '', 'base64'))

	cursors = {
		love.mouse.newCursor('arrow'),
		love.mouse.newCursor('ibeam'),
		love.mouse.newCursor('wait'),
		love.mouse.newCursor('waitarrow'),
		love.mouse.newCursor('crosshair'),
		love.mouse.newCursor('sizenwse'),
		love.mouse.newCursor('sizenesw'),
		love.mouse.newCursor('sizewe'),
		love.mouse.newCursor('sizens'),
		love.mouse.newCursor('sizeall'),
		love.mouse.newCursor('no'),
		love.mouse.newCursor('hand'),
		love.mouse.newCursor(watermelon, 0, 0)
	}

	i = 1

end


function love.draw()

	local cursor = love.mouse.getCursor()

	if cursor then
		love.graphics.print('Current cursor: ' .. cursor:getType(), 0, 0)
	else
		love.graphics.print('Current cursor: default', 0, 0)
	end

end


function love.mousepressed(x, y, b)

	if b == 'l' or b == 'wu' then

		i = i - 1
		if i < 1 then
			i = #cursors
		end

	elseif b == 'r' or b == 'wd' then

		i = i + 1
		if i > #cursors then
			i = 1
		end

	end

	love.mouse.setCursor(cursors[i])

end
cursortest.love
(775 Bytes) Downloaded 90 times
I'm wondering, why do new Cursors have to be created from CursorTypes rather than passing the CursorType to setCursor, since only one style of Cursor can be made from each CursorType? Something like this doesn't seem to make sense:

Code: Select all

cursor1 = love.mouse.newCursor('arrow')
cursor2 = love.mouse.newCursor('arrow')