Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Canvas example? #42

Closed
bryanbraun opened this issue Feb 3, 2017 · 3 comments
Closed

Add a Canvas example? #42

bryanbraun opened this issue Feb 3, 2017 · 3 comments
Labels

Comments

@bryanbraun
Copy link
Collaborator

bryanbraun commented Feb 3, 2017

I'm a bit on the fence about this one because I picture it as being 95% the same as the "Vanilla Javascript" technique, the only difference being that the position is applied to a canvas instead of an html element.

It being so similar seems to go against the no "slight variations on existing techniques" principle in the Contribution guidelines, but I'm open to suggestions. Anybody have thoughts?

@tigt
Copy link
Contributor

tigt commented Feb 3, 2017

One change that would need to happen is "erasing" the ball's previous position. If you want to make it noticeably different, it could use the "offscreen <canvas> buffer" technique, which would be overkill for something this simple, but definitely an existing method.

@bryanbraun
Copy link
Collaborator Author

Ok, I think I'm leaning towards adding it then. Let's plan on putting together a code snippet and dropping it in this issue so I can take a look before adding it to the site.

@tigt
Copy link
Contributor

tigt commented Feb 5, 2017

Example from http://blog.bob.sh/2012/12/double-buffering-with-html-5-canvas.html

/* Prepare your canvas */
mainCanvas = $('#myCanvas');
offscreenCanvas = document.createElement('canvas');

/* Make sure your offscreen size matches your on screen 
 * size */
offscreenCanvas.width = mainCanvas.width;
offscreenCanvas.height = mainCanvas.height;

/* Do some drawing on the offscreen canvas */
ctxOffscreen = offscreenCanvas.getContext('2d');
ctxOffscreen.strokeRect(0, 0, 10, 10);

/* Now flip the offscreen canvas to the onscreen 
 * one */
ctxMain = mainCanvas.getContext('2d');
ctxMain.drawImage(offscreenCanvas, 0, 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants