Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clouds

  • Loading branch information...
commit 65bab9054700f57e066cb4b03a556c2e75fe2e6a 1 parent 1c50355
@luizgustavolino luizgustavolino authored
View
8 Classes/GameScene.js
@@ -4,6 +4,7 @@ var GameScene = cc.Layer.extend({
waves: null,
wavesBG: null,
sky: null,
+ clouds: null,
boat: null,
init:function () {
@@ -16,8 +17,13 @@ var GameScene = cc.Layer.extend({
this.sky.setPosition(cc.ccp(0, 30));
this.addChild(this.sky);
+ this.clouds = new Clouds();
+ this.clouds.setAnchorPoint(cc.ccp(0, 1));
+ this.clouds.setPosition(cc.ccp(0, size.height+16));
+ this.addChild(this.clouds);
+
this.wavesBG = new WaterBG();
- this.wavesBG.setPosition(cc.ccp(0, -12));
+ this.wavesBG.setPosition(cc.ccp(0, -16));
this.addChild(this.wavesBG);
this.boat = new Boat();
View
10 Classes/SpriteUtils.js
@@ -19,8 +19,7 @@ var RepeatXSprite = cc.Node.extend({
});
-
-var setupSpriteAnimation = function(imageName, frames){
+var setupSpriteAnimationWithCustomDelay = function(imageName, frames, perFrameDelay){
var animFrames = [];
var str = "";
@@ -30,7 +29,7 @@ var setupSpriteAnimation = function(imageName, frames){
animFrames.push(frame);
}
- var animation = cc.Animation.create(animFrames, 0.15);
+ var animation = cc.Animation.create(animFrames, perFrameDelay);
cc.AnimationCache.sharedAnimationCache().addAnimation(animation, imageName);
// RUN ANIMATION
@@ -42,3 +41,8 @@ var setupSpriteAnimation = function(imageName, frames){
};
+
+var setupSpriteAnimation = function(imageName, frames){
+ return setupSpriteAnimationWithCustomDelay(imageName, frames, .15);
+};
+
View
66 Classes/World.js
@@ -1,3 +1,67 @@
+// CLOUDS
+var Clouds = function(){
+
+ var size = cc.Director.sharedDirector().getWinSize();
+ var node = new cc.Node();
+ var tileSizeW = 80;
+ var tileSizeH = 60;
+ var cloudsPattern = [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
+ [3,2,3,0,0,0,0,3,2,2,3,0,0,0,0,3,2,2,0,3,2,0,0,0,0,2,0,0,2,3,2,0,0,3,2,0,3,0,2,2,3,0,0,0,3,0,2,0,2,2,0,3,0,0,2,3,3,2,0,2,3,2,3,0,3,0,2,3,3,0,0,0,0,2,0,0,3,0,0,2,0,0,0,0,0]];
+
+ var maxi = cloudsPattern.length;
+ var maxj = cloudsPattern[0].length;
+
+ for(var i = 0; i < maxi; i++){
+
+ var cloudNode = new cc.Node();
+
+ for(var j = 0; j < maxj; j++){
+ var tileState = cloudsPattern[i][j];
+ if(tileState){
+
+ // CLOUD
+ var cloudFrame = cc.SpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("cloud0"+tileState+".png");
+ var aCloud = new cc.Sprite();
+ aCloud.initWithSpriteFrame(cloudFrame);
+ aCloud.setPosition(cc.ccp(j*tileSizeW,0));
+ aCloud.setAnchorPoint(cc.ccp(0, 1));
+ cloudNode.addChild(aCloud);
+
+ }
+ }
+
+ cloudNode.setContentSize(cc.SizeMake(maxj*tileSizeW, tileSizeH));
+ cloudNode.setPosition(cc.ccp(0,maxi*tileSizeH-i*tileSizeH));
+ cloudNode.setAnchorPoint(cc.ccp(0, 0));
+
+
+ var moveAction = cc.RepeatForever.create(
+ cc.Sequence.create(
+ cc.MoveBy.create(maxj*(1.2*(i+1)), cc.ccp((maxj*tileSizeW+size.width)*-1, 0)),
+ cc.CallFunc.create(this, function(){
+ cloudNode.setPosition(cc.ccp(size.width,cloudNode._position.y));
+ })
+ )
+ );
+
+ cloudNode.runAction(moveAction);
+ node.addChild(cloudNode);
+
+ }
+
+ node.setContentSize(cc.SizeMake(maxj*tileSizeW, maxi*tileSizeH));
+
+ return node;
+
+}
+
+
// BOAT
var Boat = function(){
@@ -131,7 +195,7 @@ var WaterBG = function(){
var WaterTileBG = cc.Sprite.extend({
init: function(){
this._super();
- var animationAction = setupSpriteAnimation("background_wave", 6);
+ var animationAction = setupSpriteAnimationWithCustomDelay("background_wave", 6, .22);
this.runAction(animationAction);
}
});
View
8 index.html
@@ -22,5 +22,11 @@
<canvas id="gameCanvas" width="640" height="480" style="margin: 10px; background: #000;"></canvas>
</div>
</body>
+
+ <script src="cocos2d.js"></script>
+ <script type="text/javascript">
+ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-31766030-1']); _gaq.push(['_trackPageview']);
+ (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();
+ </script>
</html>
-<script src="cocos2d.js"></script>
+
Please sign in to comment.
Something went wrong with that request. Please try again.