2014-01-28 61 views

回答

1

這現在工作:http://jsfiddle.net/whZ44/5/

var leftBorderX = 0; // set to the x value of your left border 
var newX = std1.x + std1.w; 

// if the new x value exceeds the borders (left or right) then invert the speed 
if(newX > cw || newX < leftBorderX) std1.sp *= -1; 
1
if ((std1.x + std1.w) > cw || std1.x < 0) { 
    // Invert the speed when bat reaches boundaries 
    std1.sp *= -1; 
} 

Updated fiddle