You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
implSketchforFoo{// the only required fnfnsetup(app:&mutApp) -> Self{// gives back a canvas id. useful when// there are multiple canvases
app.create_canvas(720,400);// load audio. the first app.audio() call// initializes audio subsystemlet song = app.load_sound("piano.ogg");let img = app.load_image("trees.png");Foo{ song, img }}// only called if a canvas exists. then, it is// called for every existing canvas on every// window redraw event regardless of whether// this method is implemented.fndraw(&mutself,c:&mutCanvas){
c.background(Rgba::BLACK);
c.stroke(c!("blue"));
c.line(v![0,0],v![20,40]);
c.fill(c![0x23,0xff,0x12,0xff]);
c.triangle(v![20,50],v![1,2],v![50,80]);
c.ellipse(v![70,70],v![10,99]);
c.image(&self.img,v![400,200]);}// update the sketch state [and app]. called// on every main events clear event.fnupdate(&mutself,app:&mutApp){
app.time().dt();// delta time
app.keys().pressed(btn!("a"));// pressed this frame?
app.keys().down(btn!("b"));// pressed at all?
app.mouse().down(btn!("rmb"));// same deal as keys
app.mouse().x();// position in pixelsif app.keys().pressed(Key::Space){matchself.song.is_playing(){false => song.play(),true => song.pause(),}}}// called exactly when a key is pressed.// alternatively, just check these in update// using `app.keys().pressed(/**/)` to check if// that key has been pressed this frame.fnkey_pressed(&mutself,key:Key){// *might not make it to final api*}}