Hi all! - Various questions on 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
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Hi all! - Various questions on Love2d

Post by micha »

Sorry, I haven't used any of the libraries myself. Someone else has to help out here. But I think both of them are fine. Just have a look at the documentation and take the one you like more.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Hi all! - Various questions on Love2d

Post by T-Bone »

It sounds to me like Löve is quite unlike other tools you've been using in the past. That's fine, but it's a good thing to be aware of. Löve doesn't force you to code in a specific way, it's much more open. It provides functions for drawing graphics, playings sounds and managing input (from keyboards, mice, gamepads etc). The rest is up to you, so you decide how you want to model your game objects, scenes etc. Sure, there are plenty of libraries that can help you with various tasks but you'll still be coding a lot on your own (probably). I personally consider this a great feature; game engines that force me to code in a specific way and follow templates and what not drive me nuts, but many game developers prefer the help they give.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Hi all! - Various questions on Love2d

Post by Roland_Yonaba »

Both of those two libraries are great, and quite easy to use if you are a beginner. Actually, consider that most of popular LÖVE libs (if not , all of them) are designed by people who consider first the criteria of "simplicity" when designing their libs.
My opinion would be, chose depending on what you need: AnAL handles basic animations operations nicely. Just take a look at its API, see what functions are provided (their names are pretty much self-explanatory). If you need simple stuff, go ahead with it.
Anim8 handles the basics, and provides some other things on the top, yet with minimal code. Same advice here, take a look at its API, and figure out for yourself. :)
User avatar
Lacotemale
Citizen
Posts: 75
Joined: Sat Mar 08, 2014 9:01 pm

Re: Hi all! - Various questions on Love2d

Post by Lacotemale »

It sounds to me like Löve is quite unlike other tools you've been using in the past.
Yeah that is very true. Im used to having more of a workflow. Doing stuff like adding objects, pictures to that object, animations and adding physics was all done the same way for everything. Custom functions I wrote in C programming. It was all great until I saw the development of the tool has stopped and well it doesn't seem to be that easy to write save functionality as it had trouble with some standard C stuff. :?

I tried to integrate Anal with STI (wow that sounds really wrong xD) but im not having any luck. I have to admit I don't know what im doing and im still trying to find my feet in Love2D. The draw line is failing but I only used the example code, so I dunno where to proceed from here.

Code: Select all

local sti = require "libs.STI"
require("AnAL")

function love.load()
	print(sti.version)
	
	i		= 1
	speed	= 256
	
	-- Load multiple maps
	maps = {
		sti.new("assets/maps/map01")
	}
	
	col = {}
	
	for k=1, #maps do
		local layer = 2
		local sprite = "jake"
		
		-- Add a Custom Layer
		maps[k]:addCustomLayer("Sprite Layer", layer)
		
		local spriteLayer = maps[k].layers["Sprite Layer"]
		local image = love.graphics.newImage("assets/sprites/"..sprite..".png")
		anim = newAnimation(image, 96, 96, 0.1, 0)


		-- Add Custom Data
		spriteLayer.sprite = {
			--image = love.graphics.newImage("assets/sprites/"..sprite..".png"),  this draws the whole spritesheet, not what I need
			x = 495,
			y = 462,
			r = 0,
		}
		
		-- Override Update callback
		function spriteLayer:update(dt)
			--custom animation goes here(walking?)
		end
		
		-- Override Draw callback
		function spriteLayer:draw()
			local image = self.sprite.image
			local x = math.floor(self.sprite.x)
			local y = math.floor(self.sprite.y)
			local r = self.sprite.r
			love.graphics.draw(image, x, y, r)
		end
		
		col[k] = maps[k]:getCollisionMap(1)
	end
end

function love.update(dt)
	-- Cap speed
	if speed < 128	then speed = 128 end
	if speed > 512	then speed = 512 end
	
	-- Update sprite's coordinates
	local sprite = maps[i].layers["Sprite Layer"].sprite
	local down = love.keyboard.isDown
	
	if down("w") or down("up")	then sprite.y = sprite.y - speed * dt end
	if down("s") or down("down")	then sprite.y = sprite.y + speed * dt end
	if down("a") or down("left")	then sprite.x = sprite.x - speed * dt end
	if down("d") or down("right")	then sprite.x = sprite.x + speed * dt end
	
	for _, map in pairs(maps) do
		map:update(dt)
	end
	anim:update(dt) 
end

function love.draw()
	local sprite = maps[i].layers["Sprite Layer"].sprite
	local ww = love.graphics.getWidth()
	local wh = love.graphics.getHeight()
	local tx = math.floor(-sprite.x + ww / 2 - 16)
	local ty = math.floor(-sprite.y + wh / 2 - 16)
	
	-- Draw sprite in centre of screen
	love.graphics.push()
	love.graphics.translate(tx, ty)
	maps[i]:setDrawRange(tx, ty, ww, wh)
	maps[i]:draw()
	--maps[i]:drawCollisionMap(col[i])
	love.graphics.pop()
	anim:draw(100, 100)  --fail here
end

function love.keypressed(key, isrepeat)
--	if key == "lctrl"	then speed = speed - 64 end
--	if key == "lalt"	then speed = speed + 64 end
end

function love.resize(w, h)
	for k=1, #maps do
		maps[k]:resize(w, h)
	end
end

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Hi all! - Various questions on Love2d

Post by bartbes »

What actually happens when it "fails"? And what do you expect would happen?
User avatar
Lacotemale
Citizen
Posts: 75
Joined: Sat Mar 08, 2014 9:01 pm

Re: Hi all! - Various questions on Love2d

Post by Lacotemale »

Expected drawable got nil
That kinda message appeared. It should have an image to draw though. Unless its just a case of image being a local var.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Hi all! - Various questions on Love2d

Post by bartbes »

That is weird, if image (which is stored within the animation) is nil, it should error on creation, are you sure there's no other code somewhere that's interacting with the 'anim' global variable?
User avatar
Lacotemale
Citizen
Posts: 75
Joined: Sat Mar 08, 2014 9:01 pm

Re: Hi all! - Various questions on Love2d

Post by Lacotemale »

I will play around with it tonight but I already posted all my current code. :S
User avatar
Lacotemale
Citizen
Posts: 75
Joined: Sat Mar 08, 2014 9:01 pm

Re: Hi all! - Various questions on Love2d

Post by Lacotemale »

Found out this was actually the line failing. Whoops.
love.graphics.draw(image, x, y, r)
I have this project attached. So its working now (kinda) but can someone advise me how to have the sprite centered like the way STI did it?
Attachments
WhiteGuardian.L2D.zip
(1017.95 KiB) Downloaded 92 times
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Hi all! - Various questions on Love2d

Post by bobbyjones »

Hey most people on here don't like .zip generally its recommended to attach a .love instead.

Edit: If you need help making a .love the wiki tells you how to. Sorry I don't a specific link.
Post Reply

Who is online

Users browsing this forum: No registered users and 58 guests