Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-15-2012, 02:41 PM   PM User | #1
Kirl
Regular Coder

 
Join Date: Jan 2006
Posts: 243
Thanks: 14
Thanked 2 Times in 2 Posts
Kirl is on a distinguished road
What's so handy about saving canvas drawing state?

Right, so I've been reading about saving canvas drawing states and I understand how it works, but I just don't get the use of it when compared to setting it manually...

Instead of writing restore(), re-writing the color value would do the same thing. And whith restore it isn't immediatly obvious what color is set, but when writing out the color it is. So obviously I'm missing what's so handy about this state saving bussiness... Can somebody please enlighten me?

Thanks!
Kirl is offline   Reply With Quote
Old 11-15-2012, 02:52 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
It's not only color. The graphics state of a canvas includes fillStyle, strokeStyle, lineWidth, and lineJoin
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
Kirl (11-16-2012)
Old 11-16-2012, 02:02 PM   PM User | #3
Kirl
Regular Coder

 
Join Date: Jan 2006
Posts: 243
Thanks: 14
Thanked 2 Times in 2 Posts
Kirl is on a distinguished road
I see, thanks! For now I guess I prefer to reset everything manually as I can quickly edit single elements like lineWidth directly where it matters.

Does it make any difference speed-wise if I use the stack or reset elements manually?
Kirl is offline   Reply With Quote
Old 11-17-2012, 12:02 AM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
you may want to try a 3000X4000 image and see if you notice a performance diff between the two.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:24 AM.


Advertisement
Log in to turn off these ads.