/// <summary> /// Check if any star element collides with the specified collider. /// </summary> /// <param name="collider">The collider.</param> /// <returns></returns> public bool CheckStarCollision(Collider2D collider) { var collision = this.CheckCollectionCollision(collider, this.stars); if(collision != null) { collision.Owner.IsVisible = false; return true; } return false; }
/// <summary> /// Resolves the dependencies needed for this instance to work. /// </summary> protected override void ResolveDependencies() { base.ResolveDependencies(); this.visibleBlocks = new List<RocksBlock>(); this.avaibleBlocks = this.Owner.ChildEntities.Select(c => c.FindComponent<RocksBlock>()).ToList(); var squid = this.EntityManager.Find("Squid"); if (squid != null) { this.squidCollider = squid.FindComponent<Collider2D>(false); } var gamePlayEntity = this.EntityManager.Find("GamePlayManager"); if (gamePlayEntity != null) { this.gamePlayManager = gamePlayEntity.FindComponent<GamePlayManager>(); } }
// Update is called once per frame void Update() { if (Input.GetMouseButton(0)) { touchPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); collide2dObj = Physics2D.OverlapPoint(touchPosition); if (scrollStartFlg == false && collide2dObj) { // タッチ位置にオブジェクトがあったらそのオブジェクトを取得する // スクロール移動とオブジェクトタッチの処理を区別するために記載しました GameObject obj = collide2dObj.transform.gameObject; Debug.Log(obj.name); }else{ // タッチした場所に何もない場合、スクロールフラグをtrueに scrollStartFlg = true; if(scrollStartPos.x == 0.0f){ // スクロール開始位置を取得 scrollStartPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); }else{ Vector2 touchMovePos = touchPosition; if(scrollStartPos.x != touchMovePos.x){ // 直前のタッチ位置との差を取得する float diffPos = SCROLL_DISTANCE_CORRECTION * (touchMovePos.x - scrollStartPos.x); Vector2 pos = this.transform.position; pos.x -= diffPos; // スクロールが制限を超過する場合、処理を止める if(pos.x > SCROLL_END_RIGHT || pos.x < SCROLL_END_LEFT){ return; } this.transform.position = pos; scrollStartPos = touchMovePos; } } } }else{ // タッチを離したらフラグを落とし、スクロール開始位置も初期化する scrollStartFlg = false; scrollStartPos = new Vector2(); } }
public StarFish(Vector2 position) { float sizeRandom = WaveServices.Random.Next(0, 5) /10f; this.entity = new Entity() .AddComponent(new Transform2D() { Origin = Vector2.Center, X = position.X, Y = position.Y, XScale = 0.6f + sizeRandom, YScale = 0.6f + sizeRandom, }) .AddComponent(new CircleCollider()) .AddComponent(new Sprite(Directories.TexturePath + "starfish.wpk")) .AddComponent(new SpriteRenderer(DefaultLayers.Alpha)); // Cached this.collider = this.entity.FindComponent<CircleCollider>(); this.Transform2D = this.entity.FindComponent<Transform2D>(); }
/// <summary> /// Checks the kite collision. /// </summary> /// <param name="kiteCollider2D">The kite collider2D.</param> /// <returns></returns> public KiteCollisionTypes CheckKiteCollision(Collider2D kiteCollider2D) { var collisionResult = KiteCollisionTypes.None; //Check if the kite is crossing this obstacle if (this.obstaclePairCollider.Intersects(kiteCollider2D)) { //If collides with any of the obstacles inside the pair the games ends if (this.topCollider.Intersects(kiteCollider2D) || this.bottomCollider.Intersects(kiteCollider2D)) { collisionResult = KiteCollisionTypes.Obstacle; } else if (this.StarAvaible && this.starCollider.Intersects(kiteCollider2D)) { collisionResult = KiteCollisionTypes.Star; } } return collisionResult; }
void OnTriggerExit2D(Collider2D collider2d) { otherPresent = null; otherCollider = null; }
protected virtual void Start() { _itemPicker = this.gameObject.GetComponent <ItemPicker> (); _renderer = this.gameObject.GetComponent <Renderer>(); _collider = this.gameObject.GetComponent <Collider2D>(); }
void OnTriggerEnter2D(Collider2D hitInfo) //Метод, который срабатывает при попадании { Explode(); }
void OnTriggerEnter2D(Collider2D other) { if (GameManager.gameManager.TargetPlanet.name == gameObject.transform.name && other.tag == "Player") { em.hitTarget(); } }
void OnTriggerExit2D(Collider2D other) { if (!OnTriggerExit2dActivated) return; AudioSubscription sub = FindSubscriptionForEvent(AudioSourceStandardEvent.OnTriggerExit2D); if(sub == null) return; if(sub.filterLayers && (sub.layerMask & 1 << other.gameObject.layer) != 0) return; if(sub.filterTags && !sub.tags.Contains(other.gameObject.tag)) return; if(sub.filterNames && !sub.names.Contains(other.gameObject.name)) return; PlaySoundInternal(AudioSourceStandardEvent.OnTriggerExit2D); }
private void InitEnd() { var endEntity = this.Scene.EntityManager.Find("End"); if (endEntity != null) { this.endCollider = endEntity.FindComponent<Collider2D>(false); } }
private void OnTriggerEnter2D(Collider2D other) { Debug.Log("OnTriggerEnter2D"); isWin = true; }
private void OnTriggerEnter2D(Collider2D collision) { AddScore(); }
private void OnTriggerEnter2D(Collider2D collision) { StartGame(); }
void OnTriggerEnter2D(Collider2D other) { }
void OnTriggerExit2D(Collider2D other) { Destroy(other.gameObject); StartCoroutine(Spawn(Random.Range(1, 2))); }
void OnTriggerEnter2D(Collider2D other) { player.transform.position = respawnPoint.transform.position; }
private void OnTriggerEnter2D(Collider2D collision) { if(collision.gameObject == Player.GetGameObject()) { Player.GetHealth().TakeDamage(Damage); } }
/// <summary> /// Resolves the dependencies needed for this instance to work. /// </summary> protected override void ResolveDependencies() { base.ResolveDependencies(); this.squidCollider = this.EntityManager.Find("SquidEntity").FindComponent<Collider2D>(false); }
/// <summary> /// Check if any jellyfish element collides with the specified collider. /// </summary> /// <param name="collider">The collider.</param> /// <returns></returns> public bool CheckJellyFishCollision(Collider2D collider) { return this.CheckCollectionCollision(collider, this.jellyFish) != null; }
void OnTriggerEnter2D(Collider2D collision) { boss.HeadTriggerEnter(collision); }
/// <summary> /// Check if any jelly element collides with the specified collider. /// </summary> /// <param name="collider">The collider.</param> /// <returns></returns> public bool CheckJellyCollision(Collider2D collider) { bool collision = false; foreach (JellyFish jellyFish in this.jellyFishs) { if (collider.Intersects(jellyFish.Collider)) { collision = true; break; } } return collision; }
void OnTriggerEnter2D(Collider2D collision) { playerController.Die(); }
private void InitEnd() { this.endCollider = this.Scene.EntityManager.Find("End").FindComponent<Collider2D>(false); }
private void OnTriggerExit2D(Collider2D collider) { //TODO: Add condition for the exit player = null; }
private void OnTriggerStay2D(Collider2D collision) { collision.GetComponent <Player>()?.GetDamaged(1); }
void OnTriggerEnter2D(Collider2D col) { tree = col.gameObject; }
private void OnTriggerEnter2D(Collider2D collision) { score.ScoreUp(1); }
void OnTriggerExit2D(Collider2D col) { tree = null; }
//Returns vertices of any 2DCollider public static Vector2[] GetVertices(Collider2D collider) { List <Vector2> vertices = new List <Vector2>(); //EdgeCollider2D if (collider is EdgeCollider2D) { EdgeCollider2D edgeCollider = (EdgeCollider2D)collider; vertices = new List <Vector2>(edgeCollider.points); } //PolygonCollider2D if (collider is PolygonCollider2D) { PolygonCollider2D polygonCollider = (PolygonCollider2D)collider; vertices = new List <Vector2>(polygonCollider.points); } //BoxCollider2D if (collider is BoxCollider2D) { BoxCollider2D boxCollider = (BoxCollider2D)collider; float top = boxCollider.offset.y + (boxCollider.size.y / 2f); float btm = boxCollider.offset.y - (boxCollider.size.y / 2f); float left = boxCollider.offset.x - (boxCollider.size.x / 2f); float right = boxCollider.offset.x + (boxCollider.size.x / 2f); Vector3 topLeft = new Vector3(left, top, 0f); Vector3 topRight = new Vector3(right, top, 0f); Vector3 btmLeft = new Vector3(left, btm, 0f); Vector3 btmRight = new Vector3(right, btm, 0f); vertices.Add(topLeft); vertices.Add(topRight); vertices.Add(btmRight); vertices.Add(btmLeft); } //CircleCollider2D if (collider is CircleCollider2D) { CircleCollider2D circleCollider = (CircleCollider2D)collider; Vector2 center = circleCollider.bounds.center; float radius = circleCollider.radius; int shapeCount = circleCollider.shapeCount; float angleStep = 360f / shapeCount; Quaternion quaternion = Quaternion.Euler(0.0f, 0.0f, angleStep); for (int i = 0; i < shapeCount; i++) { float x = radius * Mathf.Sin((2 * Mathf.PI * i) / shapeCount); float y = radius * Mathf.Cos((2 * Mathf.PI * i) / shapeCount); Vector2 vertex = center + new Vector2(x, y); vertices.Add(vertex); } } return(vertices.ToArray()); }
void OnTriggerStay2D(Collider2D other) { callIfExist(idOnTriggerStay2D, other); }
/// <summary> /// Initializes a new instance of the <see cref="Rock" /> class. /// </summary> /// <param name="rockType">Type of the rock.</param> public Rock(RockType rockType, Vector2 position) { this.entity = new Entity() .AddComponent(new Transform2D() { X = position.X, Y = position.Y, DrawOrder = 0.2f, }) .AddComponent(new SpriteRenderer(DefaultLayers.Alpha)); string textureName; Vector2 rockOrigin, seaweedsPosition; switch (rockType) { case RockType.Center: textureName = "centralRock"; rockOrigin = Vector2.Center; seaweedsPosition = Vector2.Zero; break; case RockType.Left: textureName = "leftRock"; rockOrigin = Vector2.Zero; seaweedsPosition = new Vector2(225,135); break; case RockType.Right: textureName = "rightRock"; rockOrigin = Vector2.UnitX; seaweedsPosition = new Vector2(-170, 100); break; default: textureName = "centralRock"; rockOrigin = Vector2.Zero; seaweedsPosition = Vector2.Zero; break; } this.entity.AddComponent(new Sprite(Directories.TexturePath + string.Format("{0}.wpk", textureName)) { IsGlobalAsset = true}); this.entity.AddComponent(new PerPixelCollider(Directories.TexturePath + string.Format("{0}Collider.wpk", textureName), 0.5f) { IsGlobalAsset = true}); this.entity.FindComponent<Transform2D>().Origin = rockOrigin; // Seaweeds Entity seaweeds = new Entity() .AddComponent(new Transform2D() { Origin = new Vector2(0.5f, 1), X = seaweedsPosition.X, Y = seaweedsPosition.Y, DrawOrder = 0.1f, }) .AddComponent(new Sprite(Directories.TexturePath + "seaweedsSpriteSheet.wpk") { IsGlobalAsset = true}) .AddComponent(Animation2D.Create<TexturePackerGenericXml>(Directories.TexturePath + "seaweedsSpriteSheet.xml") .Add("wave", new SpriteSheetAnimationSequence() { First = 1, Length = 80, FramesPerSecond = 20 })) .AddComponent(new AnimatedSpriteRenderer(DefaultLayers.Alpha)); this.entity.AddChild(seaweeds); seaweeds.FindComponent<Animation2D>().Play(true); this.Collider = this.entity.FindComponent<Collider2D>(false); }
/// <summary> /// Checks if any collider in the specified collection collides with the spiecified collider. /// </summary> /// <param name="collider">The collider.</param> /// <param name="collection">The collider collection</param> /// <returns></returns> private Collider2D CheckCollectionCollision(Collider2D collider, List<Collider2D> collection) { Collider2D collided = null; foreach (Collider2D colliderB in collection) { if (colliderB.Owner.IsVisible && collider.Intersects(colliderB)) { collided = colliderB; break; } } return collided; }
private void showScorePlusText(Collider2D col) { if (combo >= 2) { if (combo % 10 == 0) { deltaScore += 10 + (combo - 1) + 100; } else { deltaScore = 10 + (combo - 1); } } else { if (col.gameObject.tag == "favScoreObject") { deltaScore = 10; } else if (col.gameObject.tag == "notScoreObject") { if (score > 20) { deltaScore = -20; } else { deltaScore = 0; } } else if (col.gameObject.tag == "scoreObject") { deltaScore = 1; } } if (scorePlusGo == null) { scorePlusGo = new GameObject("scorePlusText"); scorePlusGo.tag = "scorePlusText"; scorePlusGo.transform.SetParent(GameObject.Find("Canvas").transform); rectTrans = scorePlusGo.AddComponent <RectTransform>(); scorePlusGo.AddComponent <ContentSizeFitter>(); } Vector2 pos = col.gameObject.transform.position; Vector2 posWorld = Camera.main.WorldToScreenPoint(pos); rectTrans.anchorMin = posWorld; rectTrans.anchorMax = posWorld; rectTrans.sizeDelta = new Vector2(200f * (Screen.dpi / 70f), 200f * (Screen.dpi / 70f)); // rectTrans.position = viewportPoint; if (scorePlusText == null) { scorePlusText = scorePlusGo.AddComponent <Text>(); } if (combo < 2) { if (deltaScore != 0) { scorePlusText.text = deltaScore > 0 ? "+" + deltaScore : "-" + deltaScore; scorePlusText.color = deltaScore > 0 ? Color.black : Color.red; scorePlusText.fontSize = 23 * (int)(Screen.dpi / 70f); } } else if (combo >= 2) { scorePlusText.text = combo + "Combo !\n+" + deltaScore; scorePlusText.color = Color.blue; if (combo % 10 == 0) { scorePlusText.fontSize = 23 * (int)(Screen.dpi / 70f); scorePlusText.color = new Color(75, 0, 130); } else { scorePlusText.fontSize = 23 * (int)(Screen.dpi / 70f); } } scorePlusText.font = arcade; scorePlusText.fontStyle = FontStyle.Bold; scorePlusText.alignment = TextAnchor.MiddleCenter; rectTrans.position = Camera.main.WorldToScreenPoint(this.gameObject.transform.position); }
public void OnTriggerEnter2D (Collider2D collision) { }
/// <summary> /// Check if any rock element collides with the specified collider. /// </summary> /// <param name="collider">The collider.</param> /// <returns></returns> public bool CheckRockCollision(Collider2D collider) { return this.CheckCollectionCollision(collider, this.rocks) != null; }
void OnTriggerStay2D(Collider2D other) { if (other.gameObject.tag == "hookShot") { for (int i = 0; i < 5; i++) { if (other.gameObject.GetComponent<Collider2D>().name == Player.collisionNames[i]) { shooting = false; player.GetComponent<Rigidbody2D>().velocity = Vector2.zero; hitSomething = false; Player.freeze = false; missedHook = false; Player.goingRight = false; Player.goingLeft = false; Player.goingUp = false; Player.goingDown = false; for (int a = 0; a < numChains; a++) { if (middleChains[a] != null) { Destroy(middleChains[a]); } } Destroy(this.gameObject); } } } }
void OnTriggerStay2D(Collider2D other) { Debug.Log("staying in ground"); }
public void checkTouch(Vector3 pos) { Vector3 wp = Camera.main.ScreenToWorldPoint(pos); Vector3 touchPos = new Vector3(wp.x, wp.y, wp.z); Collider2D hit = Physics2D.OverlapPoint(touchPos); if (hit != null) { //Debug.Log(hit.transform.gameObject.name); //hit.transform.gameObject.SendMessage("Clicked", touchPos, SendMessageOptions.RequireReceiver); BaseUnit unit = hit.GetComponent <BaseUnit>(); if (unit != null) { setChooseUnit(unit); if (mChooseUnit != null) { UnitControlPanel linkedControlPanel = mChooseUnit.getLinkControlPanel(); if (linkedControlPanel != null) { setChooseControlPanel(linkedControlPanel); } return; } } UnitControlPanel controlPanel = hit.GetComponent <UnitControlPanel>(); //TODO: fix this hack if (controlPanel != null && controlPanel.getPanelObject() == null) { controlPanel.setPanelObject(myUnits[0], 10); } if (controlPanel != null) { setChooseControlPanel(controlPanel); if (mChooseUnitControlPanel != null) { Object controlObject = mChooseUnitControlPanel.getControlObject(); if (controlObject is BaseUnit && mChooseUnitControlPanel.Select) { setChooseUnit((BaseUnit)controlObject); } else { setChooseUnit(null); } } return; } Logger.controlPanel("hit != null {0}", hit); } else { if (mChooseUnit != null) { moveUnit(touchPos); } else if (mChooseUnitControlPanel != null) { Object panelObject = mChooseUnitControlPanel.getPanelObject(); Logger.controlPanel("control panelObject {0}", panelObject); if (mChooseUnitControlPanel.CooldownReady && panelObject is GameObject && ((GameObject)panelObject).GetComponent <BaseUnit>() != null) { createUnit((GameObject)panelObject, getSpawnlocation(), touchPos, mChooseUnitControlPanel); mChooseUnitControlPanel.consumeCooldownReady(); //setChooseControlPanel(null); } } else { Logger.controlPanel("clear choose"); setChooseUnit(null); setChooseControlPanel(null); } Logger.controlPanel("hit == null {0}, {1}", mChooseUnit, mChooseUnitControlPanel); } }
public void OnTriggerStay2D (Collider2D collision) { }
void OnTriggerEnter2D(Collider2D other) { Debug.Log("touching ground"); }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "hookShot") { //hit a target you can reel in to shooting = false; missedHook = false; //fixes bug if you barely hit something GetComponent<Rigidbody2D>().velocity = Vector2.zero; hitSomething = true; AudioSource.PlayClipAtPoint(hitSound, transform.position,Player.volume); } if (other.gameObject.tag == "lever" || other.gameObject.tag == "leverUp" || other.gameObject.tag == "leverLeftFlip" || other.gameObject.tag == "leverDownFlip") { if (!missedHook) { if (!dontDouble2) { AudioSource.PlayClipAtPoint(hitSound, transform.position,Player.volume); dontDouble = true; } //hit up position lever shooting = false; missedHook = true; Transform leverFlipT = other.gameObject.transform.Find("leverFlip"); var leverScript = leverFlipT.GetComponent<Lever>(); if (!leverScript.hitLeverFlip && !leverScript.retractBridge) { Lever lever = other.GetComponent<Lever>(); lever.hitLever = true; } } } if (other.gameObject.tag == "leverFlip" || other.gameObject.tag == "leverFlipUp" || other.gameObject.tag == "leverLeft" || other.gameObject.tag == "leverDown") { if (!missedHook) { if (!dontDouble) { AudioSource.PlayClipAtPoint(hitSound, transform.position,Player.volume); dontDouble2 = true; } //hit down position lever shooting = false; missedHook = true; Transform lever = other.gameObject.transform.parent; var leverScript = lever.GetComponent<Lever>(); if (!leverScript.hitLever && !leverScript.extendBridge) { Lever leverF = other.GetComponent<Lever>(); leverF.hitLeverFlip = true; } } } if (other.gameObject.tag == "barrel") { Destroy(other.gameObject); } }
void OnTriggerExit2D(Collider2D other) { Debug.Log("exiting ground"); }
/// <summary> /// Check if any rock element collides with the specified collider. /// </summary> /// <param name="collider">The collider.</param> /// <returns></returns> public bool CheckRockCollision(Collider2D collider) { bool collision = false; foreach (Rock rock in this.rocks) { if (collider.Intersects(rock.Collider)) { collision = true; break; } } return collision; }
private void OnTriggerStay2D(Collider2D collision) { if (collision.CompareTag("Unit") && collision.GetComponent <Unit>().Cur == Cur) { if (collision.GetComponent <Unit>().Master == Master) //우리팀이랑 만났을떄 { if (collision.GetComponent <Unit>().Amount > Amount) { collision.GetComponent <Unit>().Amount += Amount; CharMerge.Remove(this.gameObject); Destroy(this.gameObject); } else if (collision.GetComponent <Unit>().Amount == Amount) { if (collision.GetComponent <Unit>().UnitState > UnitState) { collision.GetComponent <Unit>().Amount += Amount; CharMerge.Remove(this.gameObject); Destroy(this.gameObject); } else if (collision.GetComponent <Unit>().UnitState == UnitState) { if (collision.transform.position.y < transform.position.y) { collision.GetComponent <Unit>().Amount += Amount; CharMerge.Remove(this.gameObject); Destroy(this.gameObject); } } } } else //상대팀과 만났을떄 { if (UnitState != (int)ActState.attack && collision.GetComponent <Unit>().Cur == Cur) { StopAllCoroutines(); //멈추고 _ani.SetBool("Run", false); _ani.SetBool("Attack", true); Enemy = collision.gameObject; Enemy.GetComponent <Animator>().SetFloat("DirX", transform.position.x - Enemy.transform.position.x); Enemy.GetComponent <Animator>().SetFloat("DirY", transform.position.y - Enemy.transform.position.y); UnitState = (int)ActState.attack; } } } if (collision.CompareTag("Node") && collision.GetComponent <Node>().Pos == Next) { if (collision.GetComponent <Node>().Master != Master) //만났는데 다른 팀 배럭이면 { if (UnitState != (int)ActState.attack) { StopAllCoroutines(); //멈추고 _ani.SetBool("Run", false); _ani.SetBool("Attack", true); Enemy = collision.gameObject; UnitState = (int)ActState.attack; } } } if (collision.CompareTag("Node") && collision.GetComponent <Node>().Master == Master) { if (collision.GetComponent <Node>().Pos == Next || collision.GetComponent <Node>().Pos == Cur) { IsOnBarrack = true; } else { IsOnBarrack = false; } } if (collision.CompareTag("TreeAndBush") && collision.GetComponent <TreeAndBush>().Pos == Next) { if (UnitState != (int)ActState.attack /*&& Amount>10*/) { StopAllCoroutines(); //멈추고 _ani.SetBool("Run", false); _ani.SetBool("Attack", true); Enemy = collision.gameObject; UnitState = (int)ActState.attack; } } }
/// <summary> /// Check if any star element collides with the specified collider. /// </summary> /// <param name="collider">The collider.</param> /// <returns></returns> public bool CheckStarCollision(Collider2D collider) { bool collision = false; foreach (StarFish star in this.stars) { if (star.IsVisible && collider.Intersects(star.collider)) { star.IsVisible = false; collision = true; } } return collision; }
private void OnTriggerEnter2D(Collider2D collision) { transform.Rotate(0, 0, 180); }
private void OnTriggerEnter2D(Collider2D collision) { switch (collision.tag) { } }
private void OnTriggerEnter2D(Collider2D collision) { g_ScoreMgr.GetComponent <C_ScoreMgrScript>().m_increaseScore(); }
/// <summary> /// Sets the collision flag as true if a collision above a platform occured /// </summary> void OnTriggerStay2D(Collider2D col) { if(col.tag == Tags.Platform.ToString()) _isColliding = this.isAbove(col.transform); }
private void OnTriggerEnter2D(Collider2D collider) { if (scenes != null) { scenes.GetGameOverScene(); } }
public JellyFish(JellyFishType type, Vector2 position, bool rightAnimation = true) { this.entity = new Entity() .AddComponent(new Transform2D() { Origin = Vector2.Center, X = position.X, Y = position.Y, DrawOrder = 0.3f, }) .AddComponent(new AnimationUI()); // Cached this.animation = this.entity.FindComponent<AnimationUI>(); string textureName, colliderName; switch (type) { case JellyFishType.Big: textureName = "jellyFishSpriteSheet"; colliderName = "jellyFishCollider.wpk"; break; case JellyFishType.Little: textureName = "jellyFishLittleSpriteSheet"; colliderName = "jellyFishLittleCollider.wpk"; break; default: textureName = "jellyFishSpriteSheet"; colliderName = "jellyFishCollider.wpk"; break; } this.entity.AddComponent(new PerPixelCollider(Directories.TexturePath + colliderName, 0.5f) { IsGlobalAsset = true}); this.entity.AddComponent(new Sprite(Directories.TexturePath + string.Format("{0}.wpk", textureName)) { IsGlobalAsset = true}); this.entity.AddComponent(Animation2D.Create<TexturePackerGenericXml>(Directories.TexturePath + string.Format("{0}.xml", textureName)) .Add("swim", new SpriteSheetAnimationSequence() { First = 1, Length = 40, FramesPerSecond = 30 })); this.entity.AddComponent(new AnimatedSpriteRenderer(DefaultLayers.Alpha)); this.entity.FindComponent<Animation2D>().Play(true); // Animations float offset = 80; this.leftAnim = new SingleAnimation(position.X + offset, position.X, TimeSpan.FromSeconds(3)); this.leftAnim.Completed += (s, o) => { this.animation.BeginAnimation(Transform2D.XProperty, this.rightAnim); }; this.rightAnim = new SingleAnimation(position.X, position.X + offset, TimeSpan.FromSeconds(3)); this.rightAnim.Completed += (s, o) => { this.animation.BeginAnimation(Transform2D.XProperty, this.leftAnim); }; if (rightAnimation) { this.animation.BeginAnimation(Transform2D.XProperty, this.rightAnim); } else { this.animation.BeginAnimation(Transform2D.XProperty, this.leftAnim); } this.Collider = this.entity.FindComponent<Collider2D>(false); }
protected override void ResolveDependencies() { base.ResolveDependencies(); this.virtualScreenManager = this.Owner.Scene.VirtualScreenManager; this.starEntity = this.Owner.FindChild("star"); this.starParticles = this.Owner.FindChild("starParticles"); this.topCollider = this.Owner.FindChild("top") .FindComponent<Collider2D>(isExactType: false); this.bottomCollider = this.Owner.FindChild("bottom") .FindComponent<Collider2D>(isExactType: false); this.starCollider = this.Owner.FindChild("star") .FindComponent<Collider2D>(isExactType: false); this.scrollBehavior.OnEntityOutOfScreen += (sender, entity) => { this.transform2D.X += REAPPEARANCE_X; this.transform2D.Y = this.GetRandomY(); this.StarAvaible = true; }; }