"Questions that don't deserve their own thread" thread

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.
Locked
Bya
Prole
Posts: 20
Joined: Sat Sep 06, 2014 4:24 am

Re: "Questions that don't deserve their own thread" thread

Post by Bya »

Trying to get collision working in my game, I've been using the PhysicsCallback tutorial. It tells me when any objects collide with each other, but I want a function that checks to see when two specific objects collide, so I coded the two functions "beginPlayerEnemyContact" and "endPlayerEnemyContact", but I can't get them to actually do anything. Any advice?

Code: Select all

function love.load()

	playerimage = love.graphics.newImage("knight.gif")
	playerrun1 = love.graphics.newImage("KnightRunRight1.png")
	playerrun2 = love.graphics.newImage("KnightRunRight2.png")
	playeridle1 = love.graphics.newImage("KnightIdle1.png")
	playeridle2 = love.graphics.newImage("KnightIdle2.png")
	
	tempenemyimage = love.graphics.newImage("fighter.gif")
	x = 50
	y = 50
	speed = 300
	health = 10
	
	--physics engine below
	love.physics.setMeter(64)
	world = love.physics.newWorld(0, 200, true)
	world:setCallbacks(beginContact, endContact, preSolve, postSolve)
	text = ""
	persisting = 0
	
	
	
	player = {}
	player.b = love.physics.newBody(world, 400, 200, "dynamic")
	player.b:setMass(10)
	player.s = love.physics.newCircleShape(10)
	player.f = love.physics.newFixture(player.b, player.s)
	player.f:setRestitution(0.4)
	player.f:setUserData("Knight")
	
	enemy = {}
	enemy.b = love.physics.newBody(world, 300, 200, "dynamic")
	enemy.b:setMass(10)
	enemy.s = love.physics.newCircleShape(10)
	enemy.f = love.physics.newFixture(enemy.b, enemy.s)
	enemy.f:setRestitution(0.4)
	enemy.f:setUserData("Enemy")
	
	static = {}
		static.b = love.physics.newBody(world, 400, 400, "static")
		static.s = love.physics.newRectangleShape(200,50)
		static.f = love.physics.newFixture(static.b, static.s)
		static.f:setUserData("Block")
	
	love.graphics.setBackgroundColor(104, 136, 248)
	love.window.setMode(650,650)
	end

function beginContact(a, b, coll)
    x,y = coll:getNormal()
    text = text.."\n"..a:getUserData().." colliding with "..b:getUserData().." with a vector normal of: "..x..", "..y
end

function beginPlayerEnemyContact(player, enemy, coll)
	x,y = coll:getNormal()
	text = "!!!!!!!"
	text = text.."\n"..a:getUserData().." uncolliding with "..b:getUserData()
end
function endPlayerEnemyContact(player, enemy, coll)
persisting = 0
text = text.."\n"..a:getUserData().." uncolliding with "..b:getUserData()
end
	
function endContact(a, b, coll)
persisting = 0
text = text.."\n"..a:getUserData().." uncolliding with "..b:getUserData()
end

function preSolve(a, b, coll)
    if persisting == 0 then    -- only say when they first start touching
        text = text.."\n"..a:getUserData().." touching "..b:getUserData()
    elseif persisting < 20 then    -- then just start counting
        text = text.." "..persisting
    end
    persisting = persisting + 1    -- keep track of how many updates they've been touching for
end

function postSolve(a, b, coll, normalimpulse1, tangentimpulse1, normalimpulse2, tangentimpulse2)
end
function love.update(dt)

world:update(dt)

if love.keyboard.isDown("right") then
        player.b:applyForce(100, 0)
    elseif love.keyboard.isDown("left") then
        player.b:applyForce(-100, 0)
    end
    if love.keyboard.isDown("up") then
        player.b:applyForce(0, -500)
    elseif love.keyboard.isDown("down") then
        player.b:applyForce(0, 100)
    end

if string.len(text) > 768 then
text = ""


end

	end
function love.draw()
	love.graphics.print(text, 10, 10)
	love.graphics.draw(playerimage, player.b:getX(),player.b:getY())
	love.graphics.draw(tempenemyimage, enemy.b:getX(),enemy.b:getY())
	love.graphics.polygon("line", static.b:getWorldPoints(static.s:getPoints()))
	
	
	
end
User avatar
Jack Dandy
Prole
Posts: 49
Joined: Mon Sep 08, 2014 4:26 pm

Re: "Questions that don't deserve their own thread" thread

Post by Jack Dandy »

Hiya! New to this whole game programming business, and I got some recommendations about LOVE.

So I'm trying to figure things out! I'll have plenty of dumb questions for you guys. Here's my first one:

I understand you can use Notepad++ to edit and launch the .lua files from inside the .love file.
But, I don't understand how to do that! The wiki and google kind of failed me. Can anyone hand me a tip? :?
User avatar
IceQB
Citizen
Posts: 67
Joined: Sat Nov 03, 2012 1:11 pm

Re: "Questions that don't deserve their own thread" thread

Post by IceQB »

Jack Dandy, it is good for start: http://www.indiedb.com/engines/love/tut ... your-games. And have fun!
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: "Questions that don't deserve their own thread" thread

Post by Zeliarden »

Trying to get collision working in my game, I've been using the PhysicsCallback tutorial. It tells me when any objects collide with each other, but I want a function that checks to see when two specific objects collide, so I coded the two functions "beginPlayerEnemyContact" and "endPlayerEnemyContact", but I can't get them to actually do anything. Any advice?
Check out http://love2d.org/wiki/World:setCallbacks for how to get them to do anything and why it wont work...
What you want to do is check if a or b (by :getUserData()) is a spcific object (PlayerEnemy)
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Re: "Questions that don't deserve their own thread" thread

Post by Whatthefuck »

After I clear a spritebatch of it's contents via :clear(), it doesn't seem to free up the RAM nor VRAM that it used, yet :getCount() after clearing returns 0. Is this a bug or is it intentional?

Edit: oh another interesting thing - if you call :bind on a spritebatch, add the sprites you need to it, then :unbind and clear, it doesn't free up RAM that the sprites in it used.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: "Questions that don't deserve their own thread" thread

Post by Plu »

Memory is only cleared when the garbagecollector runs, which might take some time if no other process needs the memory that is being held for no reason.

To force run it, do:

Code: Select all

collectgarbage()
and then check memory usage again :)
User avatar
Jack Dandy
Prole
Posts: 49
Joined: Mon Sep 08, 2014 4:26 pm

Re: "Questions that don't deserve their own thread" thread

Post by Jack Dandy »

Thanks, IceQB! I followed the instructions. This is cool as hell, and definitely explained some important concepts. ^^

But, I still don't know how to edit the LUA file AFTER I made the LOVE file with it.
Like, let's say I want to make some changes in a game, and immediately check the results.

How can I do so with notepad++?

EDIT: Oh , wait.
Is the most common way to just have the LOVE executable near the game folder and drag it to that anytime you want to check any changes?
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: "Questions that don't deserve their own thread" thread

Post by Plu »

If you want to quickly test-run changes and the like, you might want to check out a more advanced editor than Notepad++.

ZeroBrane Studio has the option to just tap the "run" icon at the top and immediately run your current code, and you don't even need to make a .love file for it :)
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Re: "Questions that don't deserve their own thread" thread

Post by Whatthefuck »

Plu, calling collectgarbage didn't help, I'm fairly sure this is a love2d bug.
User avatar
slime
Solid Snayke
Posts: 3148
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: "Questions that don't deserve their own thread" thread

Post by slime »

Whatthefuck wrote:After I clear a spritebatch of it's contents via :clear(), it doesn't seem to free up the RAM nor VRAM that it used, yet :getCount() after clearing returns 0. Is this a bug or is it intentional?

Edit: oh another interesting thing - if you call :bind on a spritebatch, add the sprites you need to it, then :unbind and clear, it doesn't free up RAM that the sprites in it used.
Whatthefuck wrote:Plu, calling collectgarbage didn't help, I'm fairly sure this is a love2d bug.
That's not a bug at all - a SpriteBatch uses a (mostly) constant amount of RAM and VRAM which is allocated when the SpriteBatch is first created (that's what the maximum sprites argument to newSpriteBatch modifies) and is deallocated when the SpriteBatch object is garbage collected.

Calling SpriteBatch:clear just makes it draw 0 sprites, and sets the next "sprite to be used" (when the next SpriteBatch:add is called) in the SpriteBatch's memory to be the first one.

Memory allocation is expensive.
Locked

Who is online

Users browsing this forum: Bing [Bot] and 2 guests