Skip to content

Commit

Permalink
add pong, hit wall and clear sound
Browse files Browse the repository at this point in the history
  • Loading branch information
basecode committed Sep 27, 2012
1 parent 4953eb7 commit 618e72f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Binary file modified example/library/movies/assets/pong.mp3
Binary file not shown.
Binary file added example/library/movies/assets/pong.ogg
Binary file not shown.
20 changes: 16 additions & 4 deletions example/library/movies/pong.js
Expand Up @@ -195,6 +195,9 @@ Pong = (function(){
newRound: function() {

if (this.ball) {

playSprite(6);

var oldBall = this.ball;
oldBall.bs.animate('.5s', {
opacity: 0
Expand All @@ -217,7 +220,7 @@ Pong = (function(){
onEnd: function() {
setTimeout(function() {
ball.start();
}, 1000)
}, 1000);
}
});

Expand Down Expand Up @@ -341,8 +344,7 @@ Pong = (function(){

if ( this.intersectsBall() ) {


audioSprite.play();
playSprite(0);

xFromPaddleCenter = (ball.x - this.x) / (this.width / 2);
xFromPaddleCenter = xFromPaddleCenter > 0 ? Math.min(1, xFromPaddleCenter) : Math.max(-1, xFromPaddleCenter);
Expand Down Expand Up @@ -429,6 +431,7 @@ Pong = (function(){
}

if ( this.isAtWall() ) {
playSprite(4);
this.deltaX = -this.deltaX;
}

Expand Down Expand Up @@ -462,14 +465,23 @@ new Text('Go!').attr({
}).addTo(popup);

// sound
var audioSprite = new Audio([
audioSprite = new Audio([
{ src: 'assets/pong.mp3' },
{ src: 'assets/pong.ogg' }
]).prepareUserEvent().addTo(stage).on('load', function() {
popup.destroy();
new Pong().start();
});

var timeoutId = null;
function playSprite(time) {
audioSprite.play(time);
clearTimeout(timeoutId);
timeoutId = setTimeout(function() {
audioSprite.pause();
}, 500);
}




7 changes: 0 additions & 7 deletions src/renderer/svg/svg.js
Expand Up @@ -661,13 +661,6 @@ define([
throw new Error('asset <' + id + '> is unknown.');
}

/*
var progressFallback = function() {
audioElement.removeEventListener('progress', progressFallback, false);
audioElement.currentTime = audioElement._time;
};
*/

if (attributes.prepareUserEvent) {
// We bind to the next touch-event and play/pause the audio to cause
// iOS devices to allow subsequent play/pause commands on the audio el.
Expand Down

0 comments on commit 618e72f

Please sign in to comment.