View this code at http://livecoding.io/3437951
Created
August 23, 2012 15:53
-
-
Save sfentress/3437951 to your computer and use it in GitHub Desktop.
created by http://livecoding.io/3437951
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"libraries":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div { | |
position: relative; | |
top: 0; | |
left: 0; | |
} | |
#wrapper { | |
background: url('http://sfentress.github.com/GGExperiment/resources/images/sky.jpg'); | |
overflow: hidden; | |
border: 5px solid #402309; | |
height: 510px; | |
} | |
#mountains { | |
background: url('http://sfentress.github.com/GGExperiment/resources/images/mountains.png'); | |
background-position: 0px 0px; | |
height: 700px; | |
width: 2000px; | |
top: -90px; | |
} | |
#grass { | |
background: url('http://sfentress.github.com/GGExperiment/resources/images/grass.png'); | |
background-position: 0px 0px; | |
height: 700px; | |
width: 2000px; | |
top: -90px; | |
position: absolute; | |
} | |
#dragon { | |
background: url('http://sfentress.github.com/GGExperiment/resources/images/drakesprite.png'); | |
background-size: 100%; | |
width: 549px; | |
height: 439px; | |
background-repeat: no-repeat; | |
position: absolute; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Flying Drake</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<div id="wrapper"> | |
<div id="mountains"></div> | |
<div id="grass"></div> | |
<div id="dragon"></div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
// extra code required because livecoding will | |
// reload all setIntervals each time... | |
if (typeof interval1 !== "undefined") clearInterval(interval1); | |
if (typeof interval2 !== "undefined") clearInterval(interval2); | |
if (typeof interval3 !== "undefined") clearInterval(interval3); | |
// end extra | |
interval1 = setInterval('animateSprite()',100); | |
interval2 = setInterval('moveSprite()', 1500); | |
interval3 = setInterval('moveBackground()', 50); | |
}); | |
var spriteFrame = 1; | |
animateSprite = function() { | |
var top = 439 * (spriteFrame % 8); | |
$('#dragon').css('backgroundPosition','-0px -'+top+'px'); | |
spriteFrame++; | |
}; | |
var moveFrame = 0; | |
var movementSequence = [[20,100], [50,80], [20,100], [60, 160], [40, 160], [60,100], [80, 70], [50, 40]]; | |
moveSprite = function() { | |
var movement = movementSequence[moveFrame % movementSequence.length]; | |
$('#dragon').animate({ | |
left: movement[0], | |
top: movement[1] | |
}, 1000); | |
moveFrame++; | |
} | |
moveBackground = function() { | |
$('#mountains').css({'backgroundPosition': '-=5px -0px'}); | |
$('#grass').css({'backgroundPosition': '-=20 -0px'}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment