protected override void OnShow(Node node, Asset asset)
		{
			node.SetScale(1f);
			ParticleEffect2D particleEffect = ResourceCache.GetParticleEffect2D(asset.RelativePathToAsset);
			if (particleEffect == null)
				return;
			
			ParticleEmitter2D particleEmitter = node.CreateComponent<ParticleEmitter2D>();
			particleEmitter.Effect = particleEffect;
			App.Viewport.SetClearColor(Color.Black);

			//TODO: remove it and let user to control position by mouse
			node.RunActions(new RepeatForever(new RotateAroundBy(0.5f, new Vector3(1, 0, 0), 0, 0, 90, TransformSpace.Parent)));
		}
Ejemplo n.º 2
0
        void CreateScene()
        {
            scene = new Scene();
            scene.CreateComponent <Octree>();

            // Create camera node
            CameraNode = scene.CreateChild("Camera");
            // Set camera's position
            CameraNode.Position = (new Vector3(0.0f, 0.0f, -10.0f));

            Camera camera = CameraNode.CreateComponent <Camera>();

            camera.Orthographic = true;

            var graphics = Graphics;

            camera.OrthoSize = (float)graphics.Height * PixelSize;
            camera.Zoom      = 1.2f * Math.Min((float)graphics.Width / 1280.0f, (float)graphics.Height / 800.0f);      // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution)

            var cache = ResourceCache;
            ParticleEffect2D particleEffect = cache.GetParticleEffect2D("Urho2D/sun.pex");

            if (particleEffect == null)
            {
                return;
            }

            particleNode = scene.CreateChild("ParticleEmitter2D");
            ParticleEmitter2D particleEmitter = particleNode.CreateComponent <ParticleEmitter2D>();

            particleEmitter.Effect = particleEffect;

            ParticleEffect2D greenSpiralEffect = cache.GetParticleEffect2D("Urho2D/greenspiral.pex");

            if (greenSpiralEffect == null)
            {
                return;
            }

            Node greenSpiralNode = scene.CreateChild("GreenSpiral");
            ParticleEmitter2D greenSpiralEmitter = greenSpiralNode.CreateComponent <ParticleEmitter2D>();

            greenSpiralEmitter.Effect = greenSpiralEffect;
        }
Ejemplo n.º 3
0
    public Vehicle CreateChassis(Vector2 colliderCenter, float colliderRadius, int massDensity, Vector3 exhaustPosition,
                                 ParticleEffect2D exhaustParticles, Sound engineSound, Sound tireSound, Sound[] suspensionSounds,
                                 int horsePower, int maxSpeedFwd, int maxSpeedBwd, int rollForce)
    {
        // We set out private fields
        _horsePower = horsePower;
        _maxSpdFwd  = maxSpeedFwd;
        _maxSpdBwd  = maxSpeedBwd;
        _rollForce  = rollForce;
        _rigidBody  = GetComponent <RigidBody2D>();

        // We add the collider (circle collider at the moment)
        var col = Racer2D.AddCollider <CollisionCircle2D>(Node, dens: massDensity, fric: 0);

        col.SetRadius(colliderRadius);
        col.SetCenter(colliderCenter);

        // We create the exhaust particle system
        var exhaustParticlesNode = Node.CreateChild();

        exhaustParticlesNode.SetPosition(exhaustPosition);
        _exhaustParticles = exhaustParticlesNode.CreateComponent <ParticleEmitter2D>();
        _exhaustParticles.SetEffect(exhaustParticles);

        // We setup the engine sound and other sound effect
        engineSound.SetLooped(true);
        _soundSource = Node.CreateComponent <SoundSource3D>();
        _soundSource.SetNearDistance(10);
        _soundSource.SetFarDistance(50);
        _accelSound            = engineSound;
        _brakeSound            = tireSound;
        _suspensionSoundSource = Node.CreateComponent <SoundSource3D>();
        _suspensionSounds      = suspensionSounds;

        // We return the Vehicle for convenience, since this function is intended to be the vehicle's init function
        return(this);
    }
Ejemplo n.º 4
0
    public Node CreateWheel(Sprite2D sprite, Vector2 relativePosition, float radius, int suspensionFrequency, float suspensionDamping,
                            ParticleEffect2D particles, float distanceToEmitParticles)
    {
        Node wheelNode = Racer2D.CreateSpriteNode(sprite);

        wheelNode.SetPosition2D(relativePosition);

        // CreateSpriteNode adds a RigidBody for us, so we get it here
        RigidBody2D wheelRigidBody = wheelNode.GetComponent <RigidBody2D>();

        // We activate CCD
        wheelRigidBody.SetBullet(true);

        Racer2D.AddCollider <CollisionCircle2D>(wheelNode).SetRadius(radius);

        // The Box2D wheel joint provides spring for simulating suspension
        ConstraintWheel2D wheelJoint = Node.CreateComponent <ConstraintWheel2D>();

        wheelJoint.SetOtherBody(wheelRigidBody);
        wheelJoint.SetAnchor(relativePosition);
        wheelJoint.SetAxis(Vector2.UnitY);
        wheelJoint.SetFrequencyHz(suspensionFrequency);
        wheelJoint.SetDampingRatio(suspensionDamping);

        // Each wheel has a particle emitter to emit particles when it's in contact with the surface
        Node particlesNode = Node.Scene.CreateChild();

        particlesNode.SetPosition(new Vector3(relativePosition.X, relativePosition.Y, 14));
        ParticleEmitter2D particleEmitter = particlesNode.CreateComponent <ParticleEmitter2D>();

        particleEmitter.SetEffect(particles);

        // We create a new Wheel struct and add to the _wheels list
        _wheels.Add(new Wheel(wheelRigidBody, wheelJoint, particleEmitter, distanceToEmitParticles));

        return(wheelNode);
    }
 public override bool TryParsePrefab(string text, out ParticleEffect2D value)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 6
0
 public override void SetUrho(ParticleEmitter2D instance, ParticleEffect2D value)
 {
     instance.Effect = value;
 }
Ejemplo n.º 7
0
 public override void SetPrefab(ParticleEmitter2DPrefab instance, ParticleEffect2D value)
 {
     instance.Effect = value;
 }