private void SetupRenderableEntity(IEntity entity) { MeshComponent meshComponent = entity.GetComponent <MeshComponent>(); OgreEntity ogreEntity = _sceneManager.createEntity(meshComponent.MeshName); SceneNode sceneNode = _sceneManager.getRootSceneNode().createChildSceneNode(/* TODO: Name Component? */); PositionComponent transformComponent = entity.GetComponent <PositionComponent>(); sceneNode.setPosition(transformComponent.Position); if (entity.HasComponent <ScaleComponent>()) { ScaleComponent scaleComponent = entity.GetComponent <ScaleComponent>(); sceneNode.setScale(scaleComponent.Scale); } RenderableComponent renderableComponent = entity.GetComponent <RenderableComponent>(); renderableComponent.OgreEntity = ogreEntity; renderableComponent.SceneNode = sceneNode; entity.IsActive = true; }
/// <summary> /// transform.scale tween /// </summary> /// <returns>The scale to.</returns> public static ITween <Vector2> TweenTo(this ScaleComponent self, Vector2 to, float duration = 0.3f) { return(new Vector2Tween(new ScaleComponentTweenTarget(self), to, duration)); }
/// <summary> /// transform.scale tween /// </summary> /// <returns>The scale to.</returns> public static ITween <Vector2> TweenTo(this ScaleComponent self, float to, float duration = 0.3f) { return(self.TweenTo(new Vector2(to), duration)); }
public ScaleComponentTweenTarget(ScaleComponent target) { this.target = target; }
public void Update(GameTime time) { ScaleComponent.Update(time); PhysicsComponent.Update(time); }
protected override bool OnTest() { Logger.Log("Running MiEntity tests..."); if (!ComponentRegister.Manager.Register <SizeComponent>() || !ComponentRegister.Manager.Register <ScaleComponent>()) { return(Logger.LogReturn("Failed: Unable to register components.", false, LogType.Error)); } using (MiEntity ent = new() ) { if (!ent.Enabled) { return(Logger.LogReturn("Failed: New MiEntity is in disabled state.", false, LogType.Error)); } if (!ent.Visible) { return(Logger.LogReturn("Failed: New MiEntity is in invisible state.", false, LogType.Error)); } // Trying to add a new component of a given type. This will add any components // named in `RequiredComponents` too. This will fail if the entity already // contains a component named in `IncompatibleComponents`. if (!ent.AddNewComponent <ScaleComponent>()) { return(Logger.LogReturn("Failed: Unable to add ScaleComponent.", false, LogType.Error)); } // Checking if the entity contains a component of a given type. if (!ent.HasComponent <ScaleComponent>()) { return(Logger.LogReturn("Failed: Succeeded adding ScaleComponent yet it is not contained by the entity.", false, LogType.Error)); } // Checking if the entity contains a component of a given type name. if (!ent.HasComponent(nameof(SizeComponent))) { return(Logger.LogReturn("Failed: Required SizeComponent was not added with ScaleComponent.", false, LogType.Error)); } // Accessing components of different types from the entity. SizeComponent size = ent.GetComponent <SizeComponent>(); ScaleComponent scale = ent.GetComponent <ScaleComponent>(); // Ensuring the component parent is set properly. if (scale.Parent != ent) { return(Logger.LogReturn("Failed: MiEntity is not parent of directly added component.", false, LogType.Error)); } if (size.Parent != ent) { return(Logger.LogReturn("Failed: MiEntity is not parent of indirectly added component.", false, LogType.Error)); } // Manipulating component data. size.Width = 150.0f; size.Height = 200.0f; scale.Scale = 2.0f; if (scale.Width != size.Width * scale.Scale) { return(Logger.LogReturn("Failed: ScaleComponent is scaling Width incorrectly.", false, LogType.Error)); } if (scale.Height != size.Height * scale.Scale) { return(Logger.LogReturn("Failed: ScaleComponent is scaling Height incorrectly.", false, LogType.Error)); } } return(Logger.LogReturn("Success!", true)); }
public ScaleComponent(ScaleComponent c) : base(c) { Scale = c?.Scale ?? 1.0f; }