html5 - animating a shape created w/javascript/canvas -
i sort of new here , new javascript. trying learn how work javascript/html5/canvas. have been working way through several tutorials. have gone trough ones animating shape can not find 1 yet drawn shape reacts user input. mouse going on rectangle resulting in color change. or better this.
http://dan.forys.co.uk/experiments/mesmerizer/
can 1 point me tutorial achieve that? thank daniela
first clarify 1 thing, canvas doesn't know what's on it. can tell color pixel can't tell rectangle here or circle there. our purposed, consider canvas write-only. functionality exists in svg if want consider application, caveat canvas more universally supported.
knowing what's under mouse relates application is. in example posted, developer took x , y position mouse event (using jquery) , did quick math calculate row , column in. apply saying, "cell (x, y) moused over, when next redraw consider that."
canvas applications work following way:
- create environment entirely in javascript (with arrays, objects, etc).
- use rendering routine draw environment canvas.
- listen mouse events, timers, etc.
- check how event affects environment.
- apply changes environment.
- reuse rendering routine step 2 update canvas new environment.
- go step 3.
with in mind, tutorial should helpful, java, .net, android, etc. have own drawing surfaces , tutorials build on them.
in regards canvas, here's fun tutorial: http://billmill.org/static/canvastutorial/index.html
the tutorial builds breakout game listens mouse events , timer events. mouse event doesn't checking see over, timer event work check if ball exists in same space block or paddle , updates canvas , javascript environment accordingly.
Comments
Post a Comment