void Awake() { this.parallaxLayer = this.transform.parent.gameObject.GetComponent<ParallaxLayer>(); this.sprite0 = this.transform.FindChild("Sprite0").GetComponent<tk2dSprite>(); this.sprite1 = this.transform.FindChild("Sprite1").GetComponent<tk2dSprite>(); //this.sprite0.transform.position = this.parallaxLayer.transform.position; this.sprite1.transform.position = this.sprite0.transform.position + new Vector3(this.sprite0.GetBounds().extents.x + this.sprite0.GetBounds().center.x + this.sprite1.GetBounds().extents.x - this.sprite1.GetBounds().center.x, 0, 0); }
private void RenderParallax(Map map, ParallaxLayer parallax) { batch.Begin(); int width = parallax.Texture.Width; int height = parallax.Texture.Height; float mapCenterX = map.Width / 2.0f; float mapCenterY = map.Height / 2.0f; float dpX = mapCenterX + engine.Camera.CameraX; float dpY = mapCenterY + engine.Camera.CameraY; float sdpX = mapCenterX + (dpX * parallax.Speed) + parallax.FixedOffsetX; float sdpY = mapCenterY + (dpY * parallax.Speed) + parallax.FixedOffsetY; engine.Camera.MapToScreen(sdpX, sdpY, out int sX, out int sY); int centerX = sX - width / 2; int centerY = sY - height / 2; int drawPosX = centerX - (int)(Math.Ceiling((engine.Graphics.ViewWidth / 2.0f + centerX) / width)) * width; int drawPosY = centerY - (int)(Math.Ceiling((engine.Graphics.ViewHeight / 2.0f + centerY) / height)) * height; int startX = drawPosX; int startY = drawPosY; while (startX > 0) { startX -= width; } while (startY > 0) { startY -= height; } int x = startX; while (x < engine.Graphics.ViewWidth) { int y = startY; while (y < engine.Graphics.ViewHeight) { engine.Graphics.Render(parallax.Texture, x, y); y += height; } x += width; } batch.End(); }
private const int NUM_LAYERS = 2; // Number of layers to instantiate. /** Set up the ParallaxManager's functionality. * Set the Singleton design pattern, make the layers list, and instantiate all of the * parallax layers. */ private void Awake() { if (instance == null) // Set up the Singleton design pattern. { instance = this; } layers = new List <ParallaxLayer>(); Vector3 layerPos = Vector3.zero; for (int i = 0; i < NUM_LAYERS; i++) { ParallaxLayer pl = Instantiate(bg, layerPos, Quaternion.identity); ParallaxLayer plA = Instantiate(back, layerPos, Quaternion.identity); ParallaxLayer plB = Instantiate(front, layerPos, Quaternion.identity); layers.Add(pl); layers.Add(plA); layers.Add(plB); layerPos = new Vector3(layerPos.x + back.GetComponent <SpriteRenderer>().bounds.size.x, 0, 0); } }
// Start is called before the first frame update void Start() { float cpos = Camera.main.transform.position.x; float screenwidth = 2 * Camera.main.orthographicSize * Camera.main.aspect; float rightEdge = cpos + screenwidth / 2; // spawn the initial parallax objects for (int i = 0; i < layers.Count; ++i) { ParallaxLayer p = layers[i]; lastPositions[p] = 1; float spriteWidth = p.sprite.bounds.max.x - p.sprite.bounds.min.x - p.overlap; int numSprites = (int)Mathf.Ceil(screenwidth / spriteWidth); for (int j = 0; j < numSprites + 2; ++j) { SpawnLayerAt(rightEdge + spriteWidth * 1.5f - j * spriteWidth, i, p); } } }
// Update is called once per frame void Update() { float cpos = Camera.main.transform.position.x; float screenwidth = 2 * Camera.main.orthographicSize * Camera.main.aspect; float rightEdge = cpos + screenwidth / 2; for (int i = 0; i < layers.Count; ++i) { ParallaxLayer p = layers[i]; float spriteWidth = p.sprite.bounds.max.x - p.sprite.bounds.min.x - p.overlap; float absPos = p.movementFactor * cpos; float offset = absPos % spriteWidth; offset -= spriteWidth / 2; if (lastPositions[p] > 0 && offset < 0) { SpawnLayerAt(rightEdge + spriteWidth * 1.5f, i, p); } lastPositions[p] = offset; } }
private void initializeLayers(bool layersVisible) { this.m_parallaxLayers.Clear(); for (int i = 0; i < base.transform.childCount; i++) { ParallaxLayer component = base.transform.GetChild(i).GetComponent <ParallaxLayer>(); if (component != null) { if (!layersVisible) { component.gameObject.SetActive(false); } else { component.gameObject.SetActive(true); component.initialize(); this.m_parallaxLayers.Add(component); } } } }
void SpawnLayerAt(float x, int index, ParallaxLayer p) { // Spawn a new sprite GameObject newObject = new GameObject("ParalaxLayer"); newObject.transform.SetParent(gameObject.transform); newObject.transform.position = new Vector3(x, p.yPos, 0); newObject.transform.localScale = new Vector3(1, p.yStretch, 1); newObject.transform.parent = transform; newObject.AddComponent <SpriteRenderer>(); SpriteRenderer renderer = newObject.GetComponent <SpriteRenderer>(); renderer.sprite = p.sprite; renderer.sortingOrder = -41 - (layers.Count - index); newObject.AddComponent <ParallaxObject>(); ParallaxObject po = newObject.GetComponent <ParallaxObject>(); po.movementFactor = p.movementFactor; po.sprite = p.sprite; }
Vector2Int GetValidKeyInView(ParallaxLayer layer) { var camBounds = _viewBoundary.GetBounds(); var bounds = layer.GetBounds(); switch (_repeat) { case LayerRepeatType.XAxis: var vertYMin = WorldToAxisKey(bounds, new Vector2(camBounds.center.x, camBounds.min.y)); return(new Vector2Int(vertYMin.x, Y_ORIGIN)); case LayerRepeatType.YAxis: var vertXMin = WorldToAxisKey(bounds, new Vector2(camBounds.min.x, camBounds.center.y)); return(new Vector2Int(X_ORIGIN, vertXMin.y)); case LayerRepeatType.Both: return(WorldToAxisKey(layer.GetBounds(), _viewBoundary.GetBounds().center)); default: throw new ArgumentOutOfRangeException(); } }
private void OldRenderParallax(Map map, ParallaxLayer parallax) { batch.Begin(); int width = parallax.Texture.Width; int height = parallax.Texture.Height; float mapCenterX = map.Width / 2; float mapCenterY = map.Height / 2; float dpX = mapCenterX + (mapCenterX * parallax.Speed) + parallax.FixedOffsetX; float dpY = mapCenterY + (mapCenterY * parallax.Speed) + parallax.FixedOffsetY; engine.Camera.MapToScreen(dpX, dpY, out int sX, out int sY); float cX = sX - width / 2.0f; float cY = sY - height / 2.0f; int startX = (int)(cX - (int)(Math.Ceiling(engine.Graphics.ViewWidth / 2.0f + cX) / (float)width) * width); int startY = (int)(cY - (int)(Math.Ceiling(engine.Graphics.ViewHeight / 2.0f + cY) / (float)height) * height); while (startX > 0) { startX -= width; } while (startY > 0) { startY -= height; } int x = startX; while (x < engine.Graphics.ViewWidth) { int y = startY; while (y < engine.Graphics.ViewHeight) { engine.Graphics.Render(parallax.Texture, x, y); y += height; } x += width; } batch.End(); }
public void LoadContent(ContentManager content) { message.LoadContent(content); enemyHealth.LoadContent(content); enemyGauge.LoadContent(content); forestLayer = new ParallaxLayer(game); float offset = 200; for (int i = 0; i < 10; i++) { BasicEnemy forestEnemy = new BasicEnemy(game, GameState.Forest, new Vector2(300 + offset, 500)); forestEnemy.LoadContent(content); forestLayer.Sprites.Add(forestEnemy); forestEnemies.Add(forestEnemy); offset += random.Next(200, 300); } forestBoss = new EnemyBoss(game, GameState.Forest, new Vector2(3500, 420)); forestBoss.LoadContent(content); forestLayer.Sprites.Add(forestBoss); forestEnemies.Add(forestBoss); ActiveEnemy = forestEnemies[0]; ActiveEnemy.IsActive = true; foreach (IEnemy e in forestEnemies) { System.Diagnostics.Debug.WriteLine($"{e.IsActive} activity"); } game.Components.Add(forestLayer); forestLayer.DrawOrder = 2; forestT = new TrackingPlayer(game.player, 1.0f); forestLayer.ScrollController = forestT; }
public static float ParallaxLayerToMoveSpeed(ParallaxLayer parallaxLayer) { switch (parallaxLayer) { case ParallaxLayer.ONE: return(5f); case ParallaxLayer.TWO: return(3.5f); case ParallaxLayer.THREE: return(2f); case ParallaxLayer.FOUR: return(1f); case ParallaxLayer.FIVE: return(0.5f); default: return(0f); } }
public void Setup(ParallaxLayer layer) { OnSetup(layer); }
public void Remove(ParallaxLayer layer) { layer.Unlink(); _layers.Remove(layer); }
public override void _Ready() { this.Stand = this.GetNode <ParallaxLayer>("Stand"); }
/// <summary> /// Triggered each frame after a layer has been moved with the camera /// </summary> /// <param name="layer"></param> protected virtual void OnUpdateModule(ParallaxLayer layer) { }
/// <summary> /// ADD a parallaxLayer to the list. /// </summary> /// <param name="layer"></param> public void AddLayer(ParallaxLayer layer) { layers.Add(layer); }
/// <summary> /// REMOVE the current layer to the list. /// </summary> /// <param name="layer"></param> public void RemoveLayer(ParallaxLayer layer) { layers.Remove(layer); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here Texture2D spritesheet = Content.Load <Texture2D>("helicopter"); Texture2D backgroundTexture = Content.Load <Texture2D>("background"); StaticSprite backgroundSprite = new StaticSprite(backgroundTexture); ParallaxLayer backgroundLayer = new ParallaxLayer(this); ParallaxLayer playerLayer = new ParallaxLayer(this); List <Texture2D> midgroundTextures = new List <Texture2D> { Content.Load <Texture2D>("midground1"), Content.Load <Texture2D>("midground2") }; List <StaticSprite> midgroundSprites = new List <StaticSprite> { new StaticSprite(midgroundTextures[0]), new StaticSprite(midgroundTextures[1], new Vector2(3500, 0)) }; ParallaxLayer midgroundLayer = new ParallaxLayer(this); List <Texture2D> foregroundTextures = new List <Texture2D>() { Content.Load <Texture2D>("foreground1"), Content.Load <Texture2D>("foreground2"), Content.Load <Texture2D>("foreground3"), Content.Load <Texture2D>("foreground4") }; List <StaticSprite> foregroundSprites = new List <StaticSprite>(); for (int i = 0; i < foregroundTextures.Count; i++) { Vector2 position = new Vector2(i * 3500, 0); StaticSprite sprite = new StaticSprite(foregroundTextures[i], position); foregroundSprites.Add(sprite); } ParallaxLayer foregroundLayer = new ParallaxLayer(this); player = new Player(spritesheet); backgroundLayer.Sprites.Add(backgroundSprite); backgroundLayer.DrawOrder = 0; midgroundLayer.Sprites.AddRange(midgroundSprites); midgroundLayer.DrawOrder = 1; playerLayer.Sprites.Add(player); playerLayer.DrawOrder = 2; foreach (StaticSprite sprite in foregroundSprites) { foregroundLayer.Sprites.Add(sprite); } foregroundLayer.DrawOrder = 4; backgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.1f); midgroundLayer.ScrollController = new PlayerTrackingScrollController(player, 0.4f); playerLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f); foregroundLayer.ScrollController = new PlayerTrackingScrollController(player, 1.0f); Components.Add(backgroundLayer); Components.Add(midgroundLayer); Components.Add(playerLayer); Components.Add(foregroundLayer); // Particle Systems _particleTexture = Content.Load <Texture2D>("particle"); _fireParticleSystem = new ParticleSystem(GraphicsDevice, 1000, _particleTexture, this) { Emitter = new Vector2(100, 100), SpawnPerFrame = 4, // Set the SpawnParticle method SpawnParticle = (ref Particle particle) => { if (_isFireOn) { MouseState mouse = Mouse.GetState(); Random random = new Random(); particle.Position = new Vector2(player.Position.X, player.Position.Y); particle.Velocity = new Vector2( MathHelper.Lerp(-50, 50, (float)random.NextDouble()), // X between -50 and 50 MathHelper.Lerp(0, 100, (float)random.NextDouble()) // Y between 0 and 100 ); particle.Acceleration = 0.1f * new Vector2(0, (float)-random.NextDouble()); particle.Color = Color.Gold; particle.Scale = 1f; particle.Life = 1.0f; } }, // Set the UpdateParticle method UpdateParticle = (float deltaT, ref Particle particle) => { particle.Velocity += deltaT * particle.Acceleration; particle.Position += deltaT * particle.Velocity; particle.Scale -= deltaT; particle.Life -= deltaT; } }; _grassParticleSystem = new ParticleSystem(GraphicsDevice, 1000, _particleTexture, this) { Emitter = new Vector2(100, 100), SpawnPerFrame = 4, // Set the SpawnParticle method SpawnParticle = (ref Particle particle) => { if (_isGrassOn) { MouseState mouse = Mouse.GetState(); Random random = new Random(); particle.Position = new Vector2(player.Position.X, 500); particle.Velocity = new Vector2( MathHelper.Lerp(-50, 50, (float)random.NextDouble()), // X between -50 and 50 MathHelper.Lerp(0, 100, (float)random.NextDouble()) // Y between 0 and 100 ); particle.Acceleration = 0.1f * new Vector2(0, (float)-random.NextDouble()); particle.Color = Color.White; particle.Scale = 1f; particle.Life = 1.0f; } }, // Set the UpdateParticle method UpdateParticle = (float deltaT, ref Particle particle) => { particle.Velocity += deltaT * particle.Acceleration; particle.Position += deltaT * particle.Velocity; particle.Scale -= deltaT; particle.Life -= deltaT; } }; _rainParticleSystem = new ParticleSystem(GraphicsDevice, 1000, _particleTexture, this) { Emitter = new Vector2(100, 100), SpawnPerFrame = 4, // Set the SpawnParticle method SpawnParticle = (ref Particle particle) => { if (_isRainOn) { MouseState mouse = Mouse.GetState(); Random random = new Random(); particle.Position = new Vector2( MathHelper.Lerp(0, graphics.GraphicsDevice.Viewport.Width, (float)random.NextDouble()), 0 ); particle.Velocity = new Vector2( 0, //MathHelper.Lerp(0, 100, (float)random.NextDouble()) // Y between 0 and 100 1000 ); particle.Acceleration = 0.1f * new Vector2(0, -1.0f); particle.Color = Color.LightBlue; particle.Scale = 0.5f; particle.Life = 2.0f; } }, // Set the UpdateParticle method UpdateParticle = (float deltaT, ref Particle particle) => { particle.Velocity += deltaT * particle.Acceleration; particle.Position += deltaT * particle.Velocity; particle.Scale -= deltaT; particle.Life -= deltaT; } }; Components.Add(_fireParticleSystem); Components.Add(_grassParticleSystem); Components.Add(_rainParticleSystem); }
public override void _Ready() { parallaxLayer = GetNode <ParallaxLayer>("ParallaxLayer"); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here font = Content.Load <SpriteFont>("font"); var playerSheet = Content.Load <Texture2D>("playerSheet"); SpriteSheet playerSprites = new SpriteSheet(playerSheet, 64, 64); player = new Player(this); player.spritesheet = playerSheet; var l = (from index in Enumerable.Range(4, 8) select playerSprites[index]).ToList(); l.AddRange((from index in Enumerable.Range(41, 6) select playerSprites[index]).ToList()); player.sprites = l.ToArray(); var testPixel = Content.Load <Texture2D>("bricksx64"); obstacle = new Obstacle(this); obstacle.spritesheet = testPixel; frontLayer = new ParallaxLayer(this); frontLayer.Sprites.Add(player); frontLayer.Sprites.Add(obstacle); frontLayer.DrawOrder = 8; frontLayer.ScrollController = new AutoScrollController(0.0f); Components.Add(frontLayer); var backgroundTextures = new Texture2D[] { Content.Load <Texture2D>("layer_08"), Content.Load <Texture2D>("layer_07_1") }; var backgroundSprites = new StaticSprite[] { new StaticSprite(backgroundTextures[0]), new StaticSprite(backgroundTextures[1]) }; var backgroundLayer = new ParallaxLayer(this); backgroundLayer.Sprites.AddRange(backgroundSprites); backgroundLayer.DrawOrder = 1; Components.Add(backgroundLayer); var cloudLayerTexture = Content.Load <Texture2D>("layer_07_2"); var cloudLayerSprite = new StaticSprite(cloudLayerTexture); var cloudLayer = new ParallaxLayer(this); cloudLayer.Sprites.Add(cloudLayerSprite); cloudLayer.DrawOrder = 2; cloudLayer.ScrollController = new AutoScrollController(10f); Components.Add(cloudLayer); var midSkylineTexture1 = Content.Load <Texture2D>("layer_06"); var midSkylineSprite1 = new StaticSprite(midSkylineTexture1); var midSkylineLayer1 = new ParallaxLayer(this); midSkylineLayer1.Sprites.Add(midSkylineSprite1); midSkylineLayer1.DrawOrder = 3; midSkylineLayer1.ScrollController = new AutoScrollController(10f); Components.Add(midSkylineLayer1); var midSkylineTexture2 = Content.Load <Texture2D>("layer_05"); var midSkylineSprite2 = new StaticSprite(midSkylineTexture2); var midSkylineLayer2 = new ParallaxLayer(this); midSkylineLayer2.Sprites.Add(midSkylineSprite2); midSkylineLayer2.DrawOrder = 4; midSkylineLayer2.ScrollController = new AutoScrollController(10f); Components.Add(midSkylineLayer2); var midSkylineTexture3 = Content.Load <Texture2D>("layer_04"); var midSkylineSprite3 = new StaticSprite(midSkylineTexture3); var midSkylineLayer3 = new ParallaxLayer(this); midSkylineLayer3.Sprites.Add(midSkylineSprite3); midSkylineLayer3.DrawOrder = 5; midSkylineLayer3.ScrollController = new AutoScrollController(10f); Components.Add(midSkylineLayer3); var midSkylineTexture4 = Content.Load <Texture2D>("layer_03"); var midSkylineSprite4 = new StaticSprite(midSkylineTexture4); var midSkylineLayer4 = new ParallaxLayer(this); midSkylineLayer4.Sprites.Add(midSkylineSprite4); midSkylineLayer4.DrawOrder = 6; midSkylineLayer4.ScrollController = new AutoScrollController(10f); Components.Add(midSkylineLayer4); var foregroundTextures = new Texture2D[] { Content.Load <Texture2D>("layer_02"), Content.Load <Texture2D>("layer_01") }; var foregroundSprites = new StaticSprite[] { new StaticSprite(foregroundTextures[0]), new StaticSprite(foregroundTextures[1]) }; var foregroundLayer = new ParallaxLayer(this); foregroundLayer.Sprites.AddRange(foregroundSprites); foregroundLayer.DrawOrder = 7; Components.Add(foregroundLayer); midSkylineLayer1.ScrollController = new AutoScrollController(15); midSkylineLayer2.ScrollController = new AutoScrollController(20); midSkylineLayer3.ScrollController = new AutoScrollController(25); midSkylineLayer4.ScrollController = new AutoScrollController(35); foregroundLayer.ScrollController = new AutoScrollController(100); }
/// <summary> /// Triggered once when a layer is initially setup /// </summary> /// <param name="layer"></param> protected virtual void OnSetup(ParallaxLayer layer) { }
public void SetLayer(ParallaxLayer _layer) { layer = _layer; }
public void UpdateModule(ParallaxLayer layer) { OnUpdateModule(layer); }
//////////////////////////////////////////////////////////////// void UpdateParallaxLayerPositions() { // Parallax Layers tile in X Direction, but not in Y Direction. // Example: // Area 1 is about 21 screens x 6 screens. // The backlayer of the parallax should span about 10.5 screens x 3 screens. // The layer itself is made out of a single texture that spans 2 screens x 3 screens. CameraManager cameraManager = CameraManager.Get(); Camera camera = cameraManager.GetCamera(); Vector2 cameraSize = cameraManager.GetCameraColliderSize(); //////////////////////////////////////////////////////////////// // DEBUG DRAWNG AREA OUTLINES //DebugDrawingInterface.DrawPersistentLine(m_CurrentAreaRootWS, m_CurrentAreaRootWS + Vector2.right * m_CurrentAreaDimensionsWS, Color.magenta, 1); //DebugDrawingInterface.DrawPersistentLine(m_CurrentAreaRootWS, m_CurrentAreaRootWS + Vector2.up * m_CurrentAreaDimensionsWS, Color.magenta, 1); //DebugDrawingInterface.DrawPersistentLine(m_CurrentAreaRootWS + m_CurrentAreaDimensionsWS, m_CurrentAreaRootWS + Vector2.right * m_CurrentAreaDimensionsWS, Color.magenta, 1); //DebugDrawingInterface.DrawPersistentLine(m_CurrentAreaRootWS + m_CurrentAreaDimensionsWS, m_CurrentAreaRootWS + Vector2.up * m_CurrentAreaDimensionsWS, Color.magenta, 1); //////////////////////////////////////////////////////////////// for (int i = 0; i < m_ParallaxLayers.Count; i++) { ParallaxLayer layer = m_ParallaxLayers[i]; if (layer.DimensionsWS.magnitude == 0.0f) { continue; } Vector2 cameraToRootOffset = camera.transform.position.xy() - m_CurrentAreaRootWS; // Find progress in this area between [0, 1] float progressX = (cameraToRootOffset.x) / (m_CurrentAreaDimensionsWS.x); float progressY = (cameraToRootOffset.y) / (m_CurrentAreaDimensionsWS.y); // Offset parallax layer by [0, 1] * layer.Dimensions float layerPositionX = cameraToRootOffset.x - (layer.DimensionsWS.x - cameraSize.x) * progressX; float layerPositionY = cameraToRootOffset.y - (layer.DimensionsWS.y - cameraSize.y) * progressY; //DebugDrawingInterface.DrawPersistentSSText("AreaDimensions: " + m_CurrentAreaDimensionsWS.x + ", " + m_CurrentAreaDimensionsWS.y, new Vector2(150, 25), Color.white, 1); //DebugDrawingInterface.DrawPersistentSSText("CameraToRootOffset: " + cameraToRootOffset.x + ", " + cameraToRootOffset.y, new Vector2(150, 65), Color.white, 1); //DebugDrawingInterface.DrawPersistentSSText("LayerPosition: " + layerPositionX + ", " + layerPositionY, new Vector2(150, 105), Color.white, 1); Vector2 rendererOriginInArea = m_CurrentAreaRootWS + (layer.DimensionsWS) / 2.0f - cameraSize / 2.0f; //////////////////////////////////////////////////////////////// // DEBUG DRAWING LAYER OUTLINES //DebugDrawingInterface.DrawPersistentPointBox(rendererOriginInArea, 0.2f, Color.magenta, 1); //Vector2 rendererSpan = layer.Renderer.size * layer.Renderer.transform.localScale.y; //Vector2 rendererOrigin = layer.Renderer.transform.position.xy() - rendererSpan / 2.0f; //DebugDrawingInterface.DrawPersistentLine(rendererOrigin, rendererOrigin + Vector2.right * rendererSpan, Color.magenta, 1); //DebugDrawingInterface.DrawPersistentLine(rendererOrigin, rendererOrigin + Vector2.up * rendererSpan, Color.magenta, 1); //DebugDrawingInterface.DrawPersistentLine(rendererOrigin + rendererSpan, rendererOrigin + Vector2.right * rendererSpan, Color.magenta, 1); //DebugDrawingInterface.DrawPersistentLine(rendererOrigin + rendererSpan, rendererOrigin + Vector2.up * rendererSpan, Color.magenta, 1); //////////////////////////////////////////////////////////////// layer.Renderer.transform.position = rendererOriginInArea + new Vector2(layerPositionX, layerPositionY); } }
public void Add(ParallaxLayer layer) { _layers.Add(layer); layer.Link(this); }
public void Awake() { parallaxComp = GetComponent <ParallaxLayer>(); material = new Material(Shader.Find("Unlit/Color")); }
public override void _Ready() { cloudLayer = GetNode <ParallaxLayer>("clouds"); cloudSprite = cloudLayer.GetNode <Sprite>("Sprite"); }
public void AddNewTileToLayers(ParallaxLayer layer) { parallaxLayers.Add(layer); }
public void AddLayerToList(ParallaxLayer layer) { backgrounds.Add(layer); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); componentsBatch = new SpriteBatch(GraphicsDevice); wizardHealth.LoadContent(Content); wizardGauge.LoadContent(Content); menu.LoadContent(Content); music.LoadContent(Content); narrator.LoadContent(Content); // Player Layer player = new Player(this, Color.White); player.LoadContent(Content); playerLayer = new ParallaxLayer(this); playerLayer.Sprites.Add(player); playerLayer.DrawOrder = 2; Components.Add(playerLayer); dungeonLevel = new DungeonLevel(this); caveLevel = new CaveLevel(this); forestLevel = new ForestLevel(this); dungeonLevel.LoadContent(Content); caveLevel.LoadContent(Content); forestLevel.LoadContent(Content); levelsLayer = new ParallaxLayer(this); // Levels Layer - Can just add to to them for other levels var levelTextures = new List <Texture2D>() { Content.Load <Texture2D>("forest1"), Content.Load <Texture2D>("forest2"), Content.Load <Texture2D>("forest1"), // 4167 Content.Load <Texture2D>("cave1"), Content.Load <Texture2D>("cave2"), Content.Load <Texture2D>("cave1"), Content.Load <Texture2D>("dungeon2"), Content.Load <Texture2D>("dungeon2"), Content.Load <Texture2D>("dungeon2") }; var levelSprites = new List <StaticSprite>(); for (int i = 0; i < levelTextures.Count; i++) { var position = new Vector2((i * 1389) - 50, 0); var sprite = new StaticSprite(levelTextures[i], position); levelSprites.Add(sprite); } foreach (var sprite in levelSprites) { levelsLayer.Sprites.Add(sprite); } levelsLayer.DrawOrder = 1; Components.Add(levelsLayer); playerT = new TrackingPlayer(player, 1.0f); levelsT = new TrackingPlayer(player, 1.0f); playerLayer.ScrollController = playerT; levelsLayer.ScrollController = levelsT; GameState = GameState.MainMenu; //add for loop for enemies when we get texture files //Add Enemies to Components with DrawOrder so they appear on top of layers }