Wrapper instead of porting Love2D

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Wrapper instead of porting Love2D

Post by SiENcE »

Hi,

as you may noticed, i wrote an wrapper for Codea (App to code on iPad with similar API) called LoveCodify. This way you can run Codea scripts in Love2D (so you can also develop on pc).

Now i stumbled across Corona SDK and Moai. Both support mostly mobile devices and expose a Lua API for the user like Love2D. (i know there are much more similar frameworks out there (luaplayer aso.))

What about writing a lua wrapper script to run Love2D scripts with corona or moai? This way love2D don't has to be ported (and supported) to all different mobile platforms.

What you think about?

cheers
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Wrapper instead of porting Love2D

Post by kikito »

1. It looks like quite a lot of work
2. Moai is opensource and royalty-free, so that one would be my preference.
When I write def I mean function.
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Wrapper instead of porting Love2D

Post by SiENcE »

kikito wrote:1. It looks like quite a lot of work
2. Moai is opensource and royalty-free, so that one would be my preference.
I wrote the basics of lovecodify in 2 days and not everything has to be wrapped. Stubs should mostly do it.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Wrapper instead of porting Love2D

Post by coffee »

1. Moai for opensource and royalty-free
2. CoronaSDK if need do Closed/commercial projects
Would be nice see LOVE in iOS however.
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Wrapper instead of porting Love2D

Post by SiENcE »

Here is a first working sample to run Love2D lua scripts with Moai SDK.

But there is one big problem and i don't have a solution yet!

To create an Object you have to create a texture using MOAIGfxQuad2D and afterwards you have use the texture to make an Object calling MOAIProp2D. Then you insert the object into the drawing layer.

In Moai SDK the draw operation is only an update operation. So it only updates the location of an existing object in the drawing layer.

So only one cloud is updated, just because we have only one cloud object.

Bad Idea 1:
Calling MOAIProp2D in the draw method is bad, just because everytime "love.graphics.draw" is called, an additional object is instantiated.

Idea 2
Maybe we have todo a list, to remember and check the instantiated object in the draw operation.

Any other ideas or solutions?

Moai file : "main.lua"

Code: Select all

print ( "hello, moai here is love!" )

require ("moai_love2d_wrapper")
require ("main1")

SCREEN_UNITS_X = 800
SCREEN_UNITS_Y = 600
SCREEN_WIDTH = SCREEN_UNITS_X
SCREEN_HEIGHT = SCREEN_UNITS_Y

MOAISim.openWindow ( "moai_love2d_wrapper_test", SCREEN_WIDTH, SCREEN_HEIGHT )

viewport = MOAIViewport.new ()
viewport:setScale ( SCREEN_UNITS_X, SCREEN_UNITS_Y )
viewport:setSize ( SCREEN_WIDTH, SCREEN_HEIGHT )

layer = MOAILayer2D.new ()
layer:setViewport ( viewport )
MOAISim.pushRenderPass ( layer )

love.load()

--==============================================================
-- game loop
--==============================================================
mainThread = MOAIThread.new ()

gameOver = false

mainThread:run ( 
	function ()

		local frames = 0

		while not gameOver do
		
			coroutine.yield ()
			frames = frames + 1
			
			-- call Love2D callbacks
			love.update( MOAISim.framesToTime (frames) )
			love.draw()
--			love.keypressed(k)
		end
		
	end 
)
wrapper for love2d : "moai_love2d_wrapper.lua"

Code: Select all

love = {}
love.graphics = {}
function love.graphics.newImage(file)
    local tex = MOAITexture.new ()
    tex:load ( file )
    local xtex, ytex = tex:getSize ()
	
	local gfxQuad = MOAIGfxQuad2D.new ()
	gfxQuad:setTexture ( tex )
	gfxQuad:setRect ( xtex/2*-1, ytex/2*-1, xtex/2, ytex/2 )
--	return gfxQuad

	local prop = MOAIProp2D.new ()
	prop:setDeck ( gfxQuad )
	prop:setLoc ( -1000, -1000 )	--hack to place the gfx ouside the screen
	layer:insertProp ( prop )
	return prop
end

function love.graphics.draw( prop, x, y, r, sx, sy, ox, oy )
	prop:setLoc ( x-400, y-300 )
	prop:forceUpdate ()
end

function love.graphics.setBackgroundColor() end
function love.graphics.setColor() end
function love.graphics.newImageFont() end
function love.graphics.quad() end
function love.graphics.setFont() end
function love.graphics.print() end

love.audio = {}
function love.audio.play() end
function love.audio.newSource() end

love.filesystem = {}
function love.filesystem.load() end
love2d sample "Passing Clouds Demo" : "main1.lua" <- take this from the love2d samples

Code: Select all

-------------------------------------------------
-- LOVE: Passing Clouds Demo								
-- Website: http://love.sourceforge.net			
-- Licence: ZLIB/libpng									
-- Copyright (c) 2006-2009 LOVE Development Team
-------------------------------------------------

function love.load()
	
	-- The amazing music.
	music = love.audio.newSource("prondisk.xm")
	
	-- The various images used.
	body = love.graphics.newImage("body.png")
	ear = love.graphics.newImage("ear.png")
	face = love.graphics.newImage("face.png")
	logo = love.graphics.newImage("love.png")
	cloud = love.graphics.newImage("cloud_plain.png")

	-- Set the background color to soothing pink.
	love.graphics.setBackgroundColor(0xff, 0xf1, 0xf7)
	
	-- Spawn some clouds.
	for i=1,5 do
		spawn_cloud(math.random(-100, 900), math.random(-100, 700), 80 + math.random(0, 50))
	end
	
	love.graphics.setColor(255, 255, 255, 200)
	
	love.audio.play(music, 0)
	
end

function love.update(dt)
	try_spawn_cloud(dt)
	
	nekochan:update(dt)
	
	-- Update clouds.
	for k, c in ipairs(clouds) do
		c.x = c.x + c.s * dt
	end
	
end

function love.draw()

	love.graphics.draw(logo, 400, 380, 0, 1, 1, 128, 64)
	
	for k, c in ipairs(clouds) do
		love.graphics.draw(cloud, c.x, c.y)
	end
	
	nekochan:render()
	
end

function love.keypressed(k)
	if k == "r" then
		love.filesystem.load("main.lua")()
	end
end


nekochan = {
	x = 400, 
	y = 250, 
	a = 0
}

function nekochan:update(dt)
		self.a = self.a + 10 * dt	
end

function nekochan:render()
	love.graphics.draw(body, self.x, self.y, 0, 1, 1, 64, 64)
	love.graphics.draw(face, self.x, self.y + math.sin(self.a/5) * 3, 0, 1, 1, 64, 64)
	local r = 1 + math.sin(self.a*math.pi/20)
	for i = 1,10 do
		love.graphics.draw(ear, self.x, self.y, (i * math.pi*2/10) + self.a/10, 1, 1, 16, 64+10*r)
	end
	
end

-- Holds the passing clouds.
clouds = {}

cloud_buffer = 0
cloud_interval = 1

-- Inserts a new cloud.
function try_spawn_cloud(dt)

	cloud_buffer = cloud_buffer + dt
	
	if cloud_buffer > cloud_interval then
		cloud_buffer = 0
		spawn_cloud(-512, math.random(-50, 500), 80 + math.random(0, 50))
	end
		
end

function spawn_cloud(xpos, ypos, speed)
	table.insert(clouds, { x = xpos, y = ypos, s = speed } )
end
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Wrapper instead of porting Love2D

Post by bartbes »

Perhaps you should create them on draw and cache them, so if in frame 0 there are X draw calls on the same image, X sprites are created, then if there are X draw calls on that image in frame 1, it re-uses those objects, and it should add/remove on demand. Not quite sure about how efficient it would be, but it would work.
You wouldn't even have to remove directly, but wait a few frames and put it outside of the drawing area in the mean time.
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Wrapper instead of porting Love2D

Post by SiENcE »

Yes thats exactly my Idea 2. I'm fiddling with it, but i cant get it working.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Wrapper instead of porting Love2D

Post by molul »

I'm really interested in this wrapper since yesterday that I knew about Moai. If it eventually worked, would it mean that Love2D games could be ported to iOS and Android?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Wrapper instead of porting Love2D

Post by kikito »

Is there a more convenient place to get the source code of this than in the forum post? A github project would be very nice. Other people would be able to send you changes via pull requests.
When I write def I mean function.
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Wrapper instead of porting Love2D

Post by SiENcE »

kikito wrote:Is there a more convenient place to get the source code of this than in the forum post? A github project would be very nice. Other people would be able to send you changes via pull requests.
If someone helps to find a sollution for the above mention problem, yes, i will do a github and work further on it. If not, i tend to choose a different mobile lua engine.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], nolnop and 201 guests