function attack(s)
debounce = false
bulletxpos = xpos
bulletypos = ypos
love.graphics.setColor(255,255,255)
love.timer.sleep(s * 1)
Bullet = love.graphics.draw(bullet,bulletxpos,bulletypos - less)
love.timer.sleep(s * 1)
EXP1 = love.graphics.draw(exp1,bulletxpos,bulletypos - less)
love.timer.sleep(s * 1)
EXP2 = love.graphics.draw(exp2,bulletxpos,bulletypos - less)
love.timer.sleep(s * 1)
EXP3 = love.graphics.draw(exp3,bulletxpos,bulletypos - less)
space_pressed = false
debounce = true
end
I call it with s being 1
Problem: instead of animating then waiting 1 second, then animating more, it just waits 4 seconds then zooms through the animation/
It also pauses all the scripts, not just this function
What is the problem?
I think you may have to use delta time.
If you know what to do, just please write out my script in that way and tell me which function to put it in,
I have been confused on this for days.
love.timer.sleep
Re: love.timer.sleep
Questions of this nature should be posted in the Support and Development section. Anyway, in what part of the game loop are you calling the attack(s) function? Perhaps inside the draw function? I'm not entirely sure what are you trying to accomplish, but It seems that you need to read how löve works: here's an excellent overview by the great kikito that should give insight of how the framework works and how to set-up a simple game loop.
As for the love.timer.sleep halting the current thread activity, well, it is working as intended. From the wiki: [love.timer.sleep] pauses the current thread for the specified amount of time. If you're running your code in just one thread, it will completely pause the main loop. If you're trying to animate something, an animation is usually rendered one frame per x amount of time (usually [milli]seconds) within the love.draw() function, no need to use love.timer.sleep.
Now, if you are trying to update an image's position (x and y), and generally updating the state of your simulation, that's accomplished inside the love.update(dt) function:
Next, you just render the image according to the new position (that gets updated every frame):
Please, do not forget to use the
As for the love.timer.sleep halting the current thread activity, well, it is working as intended. From the wiki: [love.timer.sleep] pauses the current thread for the specified amount of time. If you're running your code in just one thread, it will completely pause the main loop. If you're trying to animate something, an animation is usually rendered one frame per x amount of time (usually [milli]seconds) within the love.draw() function, no need to use love.timer.sleep.
Now, if you are trying to update an image's position (x and y), and generally updating the state of your simulation, that's accomplished inside the love.update(dt) function:
Code: Select all
function love.update(dt)
bullet.x = bullet.x + bullet.vx * dt -- horizontal position
bullet.y = bullet.y + bullet.vy * dt -- vertical position
end
Code: Select all
function love.draw()
love.graphics.draw(bullet.img, bullet.x, bullet.y) -- remember to load the resources first! (see love.load())
end
Code: Select all
[/b] tags next when referring to code. Even better, how about posting the complete love file?
Re: love.timer.sleep
I'm not sure how to do it using love.timer.sleep, but I have an animation utility you may use if you'd like.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: love.timer.sleep
I am calling the attack() in a draw function because it draws, anyhow,
could you show me how to add...like... .5 a wait before each animation?
I do not need it to move, just to animate, (its an explosion).
Thanks for your help, and sorry for using the wrong forum.
could you show me how to add...like... .5 a wait before each animation?
I do not need it to move, just to animate, (its an explosion).
Thanks for your help, and sorry for using the wrong forum.
Re: love.timer.sleep
Using my utility, (linked above), you do this:
Code: Select all
Animation = require( 'Animation' )
function love.load()
local BallImage = love.graphics.newImage( 'Animation.png' )
local BallImageWidth = BallImage:getWidth()
local BallImageHeight = BallImage:getHeight()
local BallQuad = {
love.graphics.newQuad( 0, 0, 82, 70, BallImageWidth, BallImageHeight ),
love.graphics.newQuad( 82, 0, 82, 70, BallImageWidth, BallImageHeight ),
love.graphics.newQuad( 164, 0, 82, 70, BallImageWidth, BallImageHeight ),
love.graphics.newQuad( 0, 82, 82, 70, BallImageWidth, BallImageHeight ),
love.graphics.newQuad( 82, 82, 82, 70, BallImageWidth, BallImageHeight ),
love.graphics.newQuad( 164, 82, 82, 70, BallImageWidth, BallImageHeight ),
}
Ball = Animation.New( BallImage, {
Bouncing = {
Delay = .5, -- This is half a second. Change it to meet your needs.
unpack( BallQuad ),
}
} )
end
function love.draw()
Ball['Bouncing']:Draw()
end
function love.update( dt )
Ball['Bouncing']:Update( dt )
end
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: love.timer.sleep
uh..... I don't see any of my explosion variables there
Re: love.timer.sleep
Code: Select all
Animation = require 'Animation'
bullet = love.graphics.newImage( 'bullet' ) -- Other picture files, etc.
-- Other pictures and other variables.
BulletShouldAnimate = false
function love.load()
Bullet = Animation.New{
exp1,
exp2,
exp3,
Delay = .5, -- Whatever the delay between pictures is.
}
end
-- Other code
function attack(s)
debounce = false
bulletxpos = xpos
bulletypos = ypos
love.graphics.setColor(255,255,255)
love.timer.sleep(s * 1)
Bullet = love.graphics.draw(bullet,bulletxpos,bulletypos - less)
love.timer.sleep(s * 1)
EXP1 = love.graphics.draw(exp1,bulletxpos,bulletypos - less)
love.timer.sleep(s * 1)
EXP2 = love.graphics.draw(exp2,bulletxpos,bulletypos - less)
love.timer.sleep(s * 1)
EXP3 = love.graphics.draw(exp3,bulletxpos,bulletypos - less)
space_pressed = false
debounce = true
expShouldAnimate = true
end
1. This would be a lot easier if you gave us the whole code.
2. No offense, but you could have actually tried to do it yourself. It's a good way to learn.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: love.timer.sleep
I belive he missunderstands what love.timer.sleep is used for... Someone should add a huge red text on the wiki saying that it is NOT used as a timer.
Re: love.timer.sleep
Jeeper wrote:I belive he missunderstands what love.timer.sleep is used for... Someone should add a huge red text on the wiki saying that it is NOT used as a timer.
Hey uh, I have another post called "Delay on Loop" and I could reallly use some help on that.. thanks
I realized .sleep stops the whole thing, so I'm going to stick with dt
Who is online
Users browsing this forum: No registered users and 2 guests