public Parallax1() { // Top Layer, a simple image CCSprite cocosImage = new CCSprite(s_Power); // scale the image (optional) cocosImage.Scale = 2.5f; // change the transform anchor point to 0,0 (optional) cocosImage.AnchorPoint = new CCPoint(0, 0); // Middle layer: a Tile map atlas CCTileMapAtlas tilemap = CCTileMapAtlas.Create(s_TilesPng, s_LevelMapTga, 16, 16); tilemap.ReleaseMap(); // change the transform anchor to 0,0 (optional) tilemap.AnchorPoint = new CCPoint(0, 0); // Anti Aliased images tilemap.Texture.SetAntiAliasTexParameters(); // background layer: another image CCSprite background = new CCSprite(TestResource.s_back); // scale the image (optional) background.Scale = 1.5f; // change the transform anchor point (optional) background.AnchorPoint = new CCPoint(0, 0); // create a void node, a parent node CCParallaxNode voidNode = new CCParallaxNode(); // NOW add the 3 layers to the 'void' node // background image is moved at a ratio of 0.4x, 0.5y voidNode.AddChild(background, -1, new CCPoint(0.4f, 0.5f), new CCPoint(0, 0)); // tiles are moved at a ratio of 2.2x, 1.0y voidNode.AddChild(tilemap, 1, new CCPoint(2.2f, 1.0f), new CCPoint(0, -200)); // top image is moved at a ratio of 3.0x, 2.5y voidNode.AddChild(cocosImage, 2, new CCPoint(3.0f, 2.5f), new CCPoint(200, 800)); // now create some actions that will move the 'void' node // and the children of the 'void' node will move at different // speed, thus, simulation the 3D environment CCMoveBy goUp = new CCMoveBy(4, new CCPoint(0, -500)); CCFiniteTimeAction goDown = goUp.Reverse(); CCMoveBy go = new CCMoveBy(8, new CCPoint(-1000, 0)); CCFiniteTimeAction goBack = go.Reverse(); CCFiniteTimeAction seq = CCSequence.FromActions(goUp, go, goDown, goBack); voidNode.RunAction(new CCRepeatForever((CCActionInterval)seq)); AddChild(voidNode, -1, kTagTileMap); }
private void MyOnGameStickUpdate(CCGameStickStatus left, CCGameStickStatus right, PlayerIndex player) { CCNode node = GetChildByTag(kTagTileMap); if (node != null) { CCParallaxNode map = (CCParallaxNode)node; if (left.Magnitude > 0f) { // use the left stick to move the map CCPoint diff = left.Direction.InvertY * left.Magnitude * 10f; CCPoint currentPos = node.Position; node.Position = currentPos + diff; } if (right.Magnitude > 0f) { float scale = (1f - right.Direction.Y * right.Magnitude); node.Scale += scale; if (node.Scale < 1f) { node.Scale = 1f; } } } }
public override void onEnter() { base.onEnter(); m_background.parent.removeChild(m_background, true); m_background = null; CCParallaxNode p = CCParallaxNode.node(); addChild(p, 5); CCSprite p1 = CCSprite.spriteWithFile(TestResource.s_back3); CCSprite p2 = CCSprite.spriteWithFile(TestResource.s_back3); p.addChild(p1, 1, new CCPoint(0.5f, 1), new CCPoint(0, 0)); p.addChild(p2, 2, new CCPoint(1.5f, 1), new CCPoint(0, 0)); m_emitter = CCParticleFlower.node(); m_emitter.Texture = CCTextureCache.sharedTextureCache().addImage(TestResource.s_fire); p1.addChild(m_emitter, 10); m_emitter.position = new CCPoint(250, 200); CCParticleSun par = CCParticleSun.node(); p2.addChild(par, 10); par.Texture = CCTextureCache.sharedTextureCache().addImage(TestResource.s_fire); CCActionInterval move = CCMoveBy.actionWithDuration(4, new CCPoint(300, 0)); CCFiniteTimeAction move_back = move.reverse(); CCFiniteTimeAction seq = CCSequence.actions(move, move_back); p.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq)); }
public Parallax2() { var listener = new CCEventListenerTouchAllAtOnce(); listener.OnTouchesMoved = onTouchesMoved; AddEventListener(listener); // Top Layer, a simple image CCSprite cocosImage = new CCSprite(s_Power); // scale the image (optional) cocosImage.Scale = 2.5f; // change the transform anchor point to 0,0 (optional) cocosImage.AnchorPoint = new CCPoint(0, 0); // Middle layer: a Tile map atlas CCTileMapAtlas tilemap = new CCTileMapAtlas(s_TilesPng, s_LevelMapTga, 16, 16); tilemap.ReleaseMap(); // change the transform anchor to 0,0 (optional) tilemap.AnchorPoint = new CCPoint(0, 0); // Anti Aliased images tilemap.IsAntialiased = true; // background layer: another image CCSprite background = new CCSprite(TestResource.s_back); // scale the image (optional) background.Scale = 1.5f; // change the transform anchor point (optional) background.AnchorPoint = new CCPoint(0, 0); // create a void node, a parent node CCParallaxNode voidNode = new CCParallaxNode(); // NOW add the 3 layers to the 'void' node // background image is moved at a ratio of 0.4x, 0.5y voidNode.AddChild(background, -1, new CCPoint(0.4f, 0.5f), new CCPoint(0, 0)); // tiles are moved at a ratio of 1.0, 1.0y voidNode.AddChild(tilemap, 1, new CCPoint(1.0f, 1.0f), new CCPoint(0, -200)); // top image is moved at a ratio of 3.0x, 2.5y voidNode.AddChild(cocosImage, 2, new CCPoint(3.0f, 2.5f), new CCPoint(200, 1000)); AddChild(voidNode, -1, (int)KTag.kTagNode); // 0, (int)KTag.kTagNode); }
private void AddBackground() { float h = VisibleBoundsWorldspace.Size.Height; parallaxBackground = new CCParallaxNode { Position = new CCPoint(0, h) }; AddChild(parallaxBackground, BACKGROUND_INDEX); var bg = new CCSprite("gameBg.png"); parallaxBackground.AddChild(bg, 0, new CCPoint(1f, 0), new CCPoint(bg.ContentSize.Width / 2, bg.ContentSize.Height / 2)); }
void AddClouds() { float h = VisibleBoundsWorldspace.Size.Height; parallaxClouds = new CCParallaxNode { Position = new CCPoint(0, h) }; AddChild(parallaxClouds); var cloud1 = new CCSprite("cloud"); var cloud2 = new CCSprite("cloud"); var cloud3 = new CCSprite("cloud"); float yRatio1 = 1.0f; float yRatio2 = 0.15f; float yRatio3 = 0.5f; parallaxClouds.AddChild(cloud1, 0, new CCPoint(1.0f, yRatio1), new CCPoint(100, -100 + h - (h * yRatio1))); parallaxClouds.AddChild(cloud2, 0, new CCPoint(1.0f, yRatio2), new CCPoint(250, -200 + h - (h * yRatio2))); parallaxClouds.AddChild(cloud3, 0, new CCPoint(1.0f, yRatio3), new CCPoint(400, -150 + h - (h * yRatio3))); }
void AddClouds() { float yRatio1 = 1.0f; float yRatio2 = 0.15f; float yRatio3 = 0.5f; var cloudOne = new CCSprite("Cloud"); var cloudTwo = new CCSprite("Cloud"); var cloudThree = new CCSprite("Cloud"); cloudsParallax = new CCParallaxNode { Position = new CCPoint(0, layerHeight) }; cloudOne.Scale = 0.5f; cloudTwo.Scale = 0.5f; cloudThree.Scale = 0.5f; AddChild(cloudsParallax); cloudsParallax.AddChild(cloudOne, 0, new CCPoint(1.0f, yRatio1), new CCPoint(100, -100 + layerHeight - (layerHeight * yRatio1))); cloudsParallax.AddChild(cloudTwo, 0, new CCPoint(1.0f, yRatio2), new CCPoint(325, -200 + layerHeight - (layerHeight * yRatio2))); cloudsParallax.AddChild(cloudThree, 0, new CCPoint(1.0f, yRatio3), new CCPoint(170, -150 + layerHeight - (layerHeight * yRatio3))); }