"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 »

Plu wrote:You can't, not really. You'll have to delay it manually:

Code: Select all

maxTime = 0.2
curTime = 0

function love.update( dt )
  curTime = curTime + dt
  if curTime > maxTime then
    -- go to the next step of your animation
    curTime = curTime - maxTime -- for smoothness, don't just go back to 0
  end
end
Incidentally, this is exactly what anal and anim8 also do.
I'm not able to get this to work well. The code I tried writing is

Code: Select all

maxTime = 0.2
curTime = 0
function love.update(dt)
curTime = curTime + dt
world:update(dt)

	if (curTime > maxTime) then
		if playerimage == love.graphics.newImage("KnightRunRight1.png") then
			playerimage = love.graphics.newImage("KnightTesting.png")
			curTime = curTime - maxTime
		end
		if playerimage == love.graphics.newImage("KnightRunRight2.png") then
			playerimage = love.graphics.newImage("KnightTesting.png")
			curTime = curTime - maxTime
		end
		if playerimage == love.graphics.newImage("KnightDamaged.gif") then
			playerimage = love.graphics.newImage("KnightTesting.gif")
			curTime = curTime - maxTime
		end
	end
if health < 1 then
playerimage = love.graphics.newImage("KnightTesting.gif")
end

if love.keyboard.isDown("right") then
        player.b:applyForce(500, 0)
		playerimage = love.graphics.newImage("KnightRunRight1.png")
    elseif love.keyboard.isDown("left") then
        player.b:applyForce(-500, 0)
		playerimage = love.graphics.newImage("KnightRunRight1.png")
    end
    if love.keyboard.isDown("up") then
        player.b:applyForce(0, -100)
		enemy.b:applyForce(0, -100)
		playerimage = love.graphics.newImage("KnightJump.gif")
    elseif love.keyboard.isDown("down") then
        player.b:applyForce(0, 50)
		playerimage = love.graphics.newImage("KnightIdle.gif")
    end
	if love.keyboard.isDown("x") then
		playerimage = love.graphics.newImage("KnightStab.gif")
	end
	
I don't really know why it won't work, but no matter how long I hold down the keys that should make it change (i.e. holding down the right arrow key moves the player and changes to the initial changed image, but doesn't change to the test sprite when it should.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin »

Bya wrote:I'm not able to get this to work well. The code I tried writing is
It's important to know what [wiki]love.graphics.newImage[/wiki] does: it loads an image from your hard drive and creates a new object. In this case, three times per frame once curTime > maxTime.

Okay, so why isn't love.graphics.newImage("KnightTesting.png") == love.graphics.newImage("KnightTesting.png") true? Because Images don't store their filename on the object, so you can't check that, and you don't want it to compare every pixel in the image, that would be slow. So an image only == another image if it is the same object, where they both came from the same call to love.graphics.newImage.

Warning: untested suggestion:

Code: Select all

maxTime = 0.2
curTime = 0
images = {
    run_right = love.graphics.newImage("KnightRunRight1.png"),
    testing = love.graphics.newImage("KnightTesting.png"),
    run_right2 = love.graphics.newImage("KnightRunRight2.png"),
    damaged = love.graphics.newImage("KnightDamaged.gif"),
    jump = love.graphics.newImage("KnightJump.gif"),
    idle = love.graphics.newImage("KnightIdle.gif"),
    stab = love.graphics.newImage("KnightStab.gif"),
}
function love.update(dt)
	curTime = curTime + dt
	world:update(dt)
	if (curTime > maxTime) then
		if playerimage == images.run_right then
			playerimage = images.testing
			curTime = curTime - maxTime
		elseif playerimage == images.run_right2 then
			playerimage = images.testing
			curTime = curTime - maxTime
		elseif playerimage == images.damaged then
			playerimage = images.testing
			curTime = curTime - maxTime
		end
	end
	if health < 1 then
		playerimage = image.testing
	end

	if love.keyboard.isDown("right") then
		player.b:applyForce(500, 0)
		playerimage = images.run_right
	elseif love.keyboard.isDown("left") then
		player.b:applyForce(-500, 0)
		playerimage = images.run_right
	end
	if love.keyboard.isDown("up") then
		player.b:applyForce(0, -100)
		enemy.b:applyForce(0, -100)
		playerimage = images.jump
	elseif love.keyboard.isDown("down") then
		player.b:applyForce(0, 50)
		playerimage = images.idle
	end
	if love.keyboard.isDown("x") then
		playerimage = images.stab
	end	
end
You had some inconsistent indentation there, which makes it harder to read the code.
Help us help you: attach a .love.
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 »

Is there a way to get the amount of memory a system has? If there is not, could you guys add a function for that in 0.9.2? It'd be very useful for what I have in mind.
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 »

What would you want to do with that information? The total amount of memory on a system is used by lots of things, and you have no idea what other processes are using (or are going to use) chunks of it, so the amount of available memory can't really be determined.
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

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

Post by Zilarrezko »

Whatthefuck wrote:Is there a way to get the amount of memory a system has? If there is not, could you guys add a function for that in 0.9.2? It'd be very useful for what I have in mind.
I asked a very similar question, and everyone says "Why would you want to?" or "Doesn't seem possible.". Yet I see rainmeter find that out, and even the swap memory. I'm sure it's possible, It just seems that everyone we encounter doesn't know how to do it.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post by bartbes »

Of course it's possible, but is it sane to do so? Similarly, the mere existence of tools that can tell you the amount of available memory doesn't constitute a use case. Lastly, let's not forget that love doesn't just use ram, but also vram, so any numbers you get can be misleading if not done exactly right.
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

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

Post by Zilarrezko »

bartbes wrote:Of course it's possible, but is it sane to do so? Similarly, the mere existence of tools that can tell you the amount of available memory doesn't constitute a use case. Lastly, let's not forget that love doesn't just use ram, but also vram, so any numbers you get can be misleading if not done exactly right.
Could be useful for a profiler, in case you don't want to pay for a half decent one, or get one of the free ones that give you readings that don't make sense.

And I'm not seeing how Löve using ram and vram would be misleading. Unless you mean people who don't understand the difference, But the worse that can happen there is about 50 people on the forums for a couple years, asking what the difference is.
bartbes wrote:but is it sane to do so?
I don't see how it's insane to do so.

But I dropped everything on the subject, because if I wanted to even implement it into Löve I don't know how. And I don't really know where to start learning to get the information.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

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

Post by rmcode »

What is the löve equivalent of "attributes" for vertex shaders? Or is it the same? I'm currently trying to learn more about shaders, but it is a bit confusing if you constantly have to look up the differences.

If I understood correctly, löve uses different terms to make sure it is also compatible with future versions of GLSL. Is that correct?

EDIT:
More specifically I'm stuck here:
https://github.com/mattdesl/lwjgl-basic ... tex-shader

EDIT 2:
Are attributes superfluous in löve's shader code because they are passed along to the fragment shader via the arguments?

Code: Select all

vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
EDIT 3:
Seems like it ... got it to work!
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

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

Post by Zilarrezko »

rmcode wrote:What is the löve equivalent of "attributes" for vertex shaders? Or is it the same? I'm currently trying to learn more about shaders, but it is a bit confusing if you constantly have to look up the differences.

If I understood correctly, löve uses different terms to make sure it is also compatible with future versions of GLSL. Is that correct?

EDIT:
More specifically I'm stuck here:
https://github.com/mattdesl/lwjgl-basic ... tex-shader

EDIT 2:
Are attributes superfluous in löve's shader code because they are passed along to the fragment shader via the arguments?

Code: Select all

vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
EDIT 3:
Seems like it ... got it to work!
Yeah, there's no mention of it in the source code

But there's a reference if you want to know the other stuff.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

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

Post by rmcode »

Zilarrezko wrote: Yeah, there's no mention of it in the source code

But there's a reference if you want to know the other stuff.
Is this the reference you mean? Or is there another one?
Locked

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 5 guests