Hi guys, my problem is that I'm trying to update only the pixels on the screen that need updating, and I can't get it to work.
I'm not really making a game, so that's why it's a bit unusual. If I loop over every single pixel and redraw every single one of them and if I have a window of say size 500x500 then that's 250,000 individual pixel updates. It can't seem to quite handle that
So what I've tried at the moment is keeping a table of the pixels that need to be updated and what they need to be updated to, and then only drawing those pixels in the draw method. I seem to remember in SDL (if I did it a certain way, it's been a while so I don't remember) this having the effect of just drawing over the top of what was already there, but LOVE seems to paste a big black rectangle over the top of everything and then I'm just redrawing over the top of that, except I'm not drawing anymore because my code thinks it doesn't need to do any more redraws till something gets updated (which nothing does yet, I haven't implemented that part). I assumed this big black rectangle was the background colour, so I did love.graphics.setBackgroundColor(0, 0, 0, 0) in love.load() but that didn't work.
If something's unclear let me know and I'll clarify, and if you want to see code ask me and I'll PM you or paste it here; it's only 80 lines (which I'd trim a bit anyway).
Help? Thanks in advance.
Controlling love.draw updates (another problem: canvases)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Controlling love.draw updates (another problem: canvases)
Last edited by Jepcats on Fri Sep 19, 2014 2:35 pm, edited 1 time in total.
Re: Controlling love.draw updates
Not sure if I understood your problem / question correctly, but you could draw all the things you need to a canvas and then only update the pixels on the canvas that need to be updated. This should give you the effect you need I think.
If you attach a .love file it would be easier to help you
P.S.: If I had to guess, I'd say that you are maybe coding a paint editor?
If you attach a .love file it would be easier to help you
P.S.: If I had to guess, I'd say that you are maybe coding a paint editor?
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Controlling love.draw updates
You can try modifying the love.run function, just leave out the love.graphics.clear call.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Controlling love.draw updates
That doesn't always work well.DaedalusYoung wrote:You can try modifying the love.run function, just leave out the love.graphics.clear call.
A better suggestion would be to draw everything to a [wiki]Canvas[/wiki] and then draw that Canvas to the screen.
Help us help you: attach a .love.
Re: Controlling love.draw updates
Thanks! A canvas was exactly what I needed.
@rmcode Ah, sorry, I'll do that in future if I need help again. Nah it's a cellular automaton, but maybe it'll have some painting features at some point
@rmcode Ah, sorry, I'll do that in future if I need help again. Nah it's a cellular automaton, but maybe it'll have some painting features at some point
Re: Controlling love.draw updates
I'm writing this in a separate post as it's unrelated to the previous and I would want people that have already read the previous to read this too. Or would it be more right to edit the previous post? Let me know
Anyway, I'm having some trouble using canvases. I'm getting a weird flashing effect and I'm not sure why. I've created and attached a minimal .love example to show what I mean (perhaps it won't even flash for you if the problem lies with the computer I'm using).
Edit: You have to wait a few seconds before it starts flashing.
Anyway, I'm having some trouble using canvases. I'm getting a weird flashing effect and I'm not sure why. I've created and attached a minimal .love example to show what I mean (perhaps it won't even flash for you if the problem lies with the computer I'm using).
Edit: You have to wait a few seconds before it starts flashing.
- Attachments
-
- Test.love
- (556 Bytes) Downloaded 122 times
Re: Controlling love.draw updates (another problem: canvases
Ah - common trap.
Try adding love.graphics.setColor(255,255,255) before love.graphics.draw(canvas).
[Suggestion: Really should put non-drawing operations in love.updata and drawing operations in love.draw.]
Try adding love.graphics.setColor(255,255,255) before love.graphics.draw(canvas).
[Suggestion: Really should put non-drawing operations in love.updata and drawing operations in love.draw.]
Re: Controlling love.draw updates (another problem: canvases
Ah interesting. So the last colour set before you draw the canvas acts as a sort of filter. Should have probably guessed but that wasn't obvious to me, would probably be a good small point to mention on the Canvas wiki page.
And ah, I guess drawing to the canvas as opposed to the actual window doesn't come under a drawing operation then? Fair enough, I'll move it.
Thanks a lot
EDIT: This is making things I want to look black look grey. How do I draw the canvas without this?
And ah, I guess drawing to the canvas as opposed to the actual window doesn't come under a drawing operation then? Fair enough, I'll move it.
Thanks a lot
EDIT: This is making things I want to look black look grey. How do I draw the canvas without this?
Re: Controlling love.draw updates (another problem: canvases
Well I got it to work, just not in a very nice way:
I still don't fully understand the role of the setColor(white). Replace felt like the right thing to use, and alpha was the default thing being used, so I just sort of intuitively thought drawing the canvas on mode replace then the text stuff on the default mode (it doesn't work otherwise) would work. Not quite, but changing it to replace again after the text worked (which I don't really understand). I don't fully understand what I've done, and if someone could explain it I would appreciate it. Other than that, I think this'll be the last call for help from me in this thread. Thanks guys
Edit: Someone coming across this at a later date might notice the first canvas drawn is still a bit weird (at least with the way my code is). I've settled with that and haven't bothered to fix it. If you know a way/better way to do it PM me (if this thread is old).
Code: Select all
love.graphics.setColor(255, 255, 255)
love.graphics.setBlendMode("replace")
love.graphics.draw(canvas)
love.graphics.setBlendMode("alpha")
drawText("FPS: " .. love.timer.getFPS(), 0, 0)
drawText("Iteration: " .. iteration, 0, windowH - font:getHeight())
love.graphics.setBlendMode("replace")
Edit: Someone coming across this at a later date might notice the first canvas drawn is still a bit weird (at least with the way my code is). I've settled with that and haven't bothered to fix it. If you know a way/better way to do it PM me (if this thread is old).
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot] and 3 guests