wrapper class that holds in instance of a Batcher and helpers so that it can be passed around and draw anything.
Ejemplo n.º 1
0
		public override void render( Graphics graphics )
		{
			Core.graphicsDevice.setRenderTarget( null );
			graphics.batcher.begin( BlendState.NonPremultiplied, Core.defaultSamplerState, DepthStencilState.None, null, _windEffect );
			graphics.batcher.draw( previousSceneRender, _destinationRect, Color.White );
			graphics.batcher.end();
		}
Ejemplo n.º 2
0
 public override void render( Graphics graphics )
 {
     Core.graphicsDevice.setRenderTarget( null );
     graphics.batcher.begin( BlendState.NonPremultiplied, Core.defaultSamplerState, DepthStencilState.None, null );
     graphics.batcher.draw( previousSceneRender, Vector2.Zero, _color );
     graphics.batcher.end();
 }
Ejemplo n.º 3
0
		public override void debugRender( Graphics graphics )
		{
			graphics.batcher.drawHollowRect( bounds, Debug.Colors.colliderBounds, Debug.Size.lineSizeMultiplier );
			graphics.batcher.drawCircle( shape.position, ( (Circle)shape ).radius, Debug.Colors.colliderEdge, Debug.Size.lineSizeMultiplier );
			graphics.batcher.drawPixel( entity.transform.position, Debug.Colors.colliderPosition, 4 * Debug.Size.lineSizeMultiplier );
			graphics.batcher.drawPixel( shape.position, Debug.Colors.colliderCenter, 2 * Debug.Size.lineSizeMultiplier );
		}
Ejemplo n.º 4
0
 public override void render(Nez.Graphics graphics, Camera camera)
 {
     if (debugRenderEnabled)
     {
         graphics.batcher.drawCircle(_position, 10f, Color.DarkRed);
     }
 }
Ejemplo n.º 5
0
 public override void debugRender( Graphics graphics )
 {
     if( _cameraStyle == CameraStyle.LockOn )
         graphics.batcher.drawHollowRect( _worldSpaceDeadzone.x - 5, _worldSpaceDeadzone.y - 5, _worldSpaceDeadzone.width, _worldSpaceDeadzone.height, Color.DarkRed );
     else
         graphics.batcher.drawHollowRect( _worldSpaceDeadzone, Color.DarkRed );
 }
Ejemplo n.º 6
0
        public override void render( Graphics graphics, Camera camera )
        {
            // we need to send the top of of the plane to the Effect
            var screenSpaceTop = entity.scene.camera.worldToScreenPoint( entity.transform.position );
            ( material as WaterReflectionMaterial ).effect.screenSpaceVerticalOffset = screenSpaceTop.Y / entity.scene.sceneRenderTargetSize.Y;

            graphics.batcher.draw( _texture, bounds, new Rectangle( 0, 0, 1, 1 ), color );
        }
Ejemplo n.º 7
0
        public override void render(Nez.Graphics graphics, Nez.Camera camera)
        {
            if (Core.debugRenderEnabled)
            {
                graphics.batcher.drawCircle(camera.screenToWorldPoint(_midSize), 10f, Color.Beige);
                graphics.batcher.drawCircle(_targetPos, 10f, Color.Orchid);

                graphics.batcher.drawCircle(_targetPos, 10f, Color.Green);
            }
        }
Ejemplo n.º 8
0
        public override void debugRender( Graphics graphics )
        {
            foreach( var group in tiledMap.objectGroups )
                renderObjectGroup( group, graphics );

            if( _colliders != null )
            {
                foreach( var collider in _colliders )
                    collider.debugRender( graphics );
            }
        }
Ejemplo n.º 9
0
        public override void render(Nez.Graphics graphics, Nez.Camera camera)
        {
            // TODO figure out the height of the target dynamically.
            var barPos = entity.position + _targetOffset;
            var health = entity.getComponent <Health>();

            if (health != null)
            {
                var healthWidth = (float)health.Hp / health.MaxHp * BarWidth;

                graphics.batcher.drawRect(barPos, BarWidth, BarHeight, Color.Red);
                graphics.batcher.drawRect(barPos, healthWidth, BarHeight, Color.Chartreuse);
            }
        }
Ejemplo n.º 10
0
		public override void render( Graphics graphics, Camera camera )
		{
			if( _destRectsDirty )
			{
				subtexture.generateNinePatchRects( _finalRenderRect, _destRects, subtexture.top, subtexture.bottom, subtexture.right, subtexture.left );
				_destRectsDirty = false;
			}

			var pos = ( entity.transform.position + _localOffset ).ToPoint();

			for( var i = 0; i < 9; i++ )
			{
				// shift our destination rect over to our position
				var dest = _destRects[i];
				dest.X += pos.X;
				dest.Y += pos.Y;
				graphics.batcher.draw( subtexture, dest, subtexture.ninePatchRects[i], color );
			}
		}
Ejemplo n.º 11
0
		public override void render( Graphics graphics, Camera camera )
		{
			// flush the 2D batch so we render appropriately depth-wise
			graphics.batcher.flushBatch();

			Core.graphicsDevice.BlendState = BlendState.Opaque;
			Core.graphicsDevice.DepthStencilState = DepthStencilState.Default;

			for( var i = 0; i < _model.Meshes.Count; i++ )
			{
				var mesh = _model.Meshes[i];
				for( var j = 0; j < mesh.Effects.Count; j++ )
				{
					var effect = mesh.Effects[j] as BasicEffect;
					effect.World = worldMatrix;
					effect.View = camera.viewMatrix3D;
					effect.Projection = camera.projectionMatrix3D;
				}
				mesh.Draw();
			}
		}
Ejemplo n.º 12
0
		public override void debugRender( Graphics graphics )
		{
			var poly = shape as Polygon;
			graphics.batcher.drawHollowRect( bounds, Debug.Colors.colliderBounds, Debug.Size.lineSizeMultiplier );
			graphics.batcher.drawPolygon( shape.position, poly.points, Debug.Colors.colliderEdge, true, Debug.Size.lineSizeMultiplier );
			graphics.batcher.drawPixel( entity.transform.position, Debug.Colors.colliderPosition, 4 * Debug.Size.lineSizeMultiplier );
			graphics.batcher.drawPixel( shape.position, Debug.Colors.colliderCenter, 2 * Debug.Size.lineSizeMultiplier );

			// Normal debug code
			//for( var i = 0; i < poly.points.Length; i++ )
			//{
			//	Vector2 p2;
			//	var p1 = poly.points[i];
			//	if( i + 1 >= poly.points.Length )
			//		p2 = poly.points[0];
			//	else
			//		p2 = poly.points[i + 1];
			//	var perp = Vector2Ext.perpendicular( ref p1, ref p2 );
			//	Vector2Ext.normalize( ref perp );
			//	var mp = Vector2.Lerp( p1, p2, 0.5f ) + poly.position;
			//	graphics.batcher.drawLine( mp, mp + perp * 10, Color.White );
			//}
		}
Ejemplo n.º 13
0
		public override void debugRender( Graphics graphics )
		{
			stage.getRoot().debugRender( graphics );
		}
Ejemplo n.º 14
0
		public override void render( Graphics graphics, Camera camera )
		{
			stage.render( graphics, camera );
		}
Ejemplo n.º 15
0
        void renderObjectGroup( TiledObjectGroup group, Graphics graphics )
        {
            var renderPosition = entity.transform.position + _localOffset;

            foreach( var obj in group.objects )
            {
                if( !obj.visible )
                    continue;

                switch( obj.tiledObjectType )
                {
                    case TiledObject.TiledObjectType.Ellipse:
                        graphics.batcher.drawCircle( new Vector2( renderPosition.X + obj.x + obj.width * 0.5f, renderPosition.Y + obj.y + obj.height * 0.5f ), obj.width * 0.5f, group.color );
                        break;
                    case TiledObject.TiledObjectType.Image:
                        throw new NotImplementedException( "Image layers are not yet supported" );
                    case TiledObject.TiledObjectType.Polygon:
                        graphics.batcher.drawPoints( renderPosition, obj.polyPoints, group.color, true );
                        break;
                    case TiledObject.TiledObjectType.Polyline:
                        graphics.batcher.drawPoints( renderPosition, obj.polyPoints, group.color, false );
                        break;
                    case TiledObject.TiledObjectType.None:
                        graphics.batcher.drawHollowRect( renderPosition.X + obj.x, renderPosition.Y + obj.y, obj.width, obj.height, group.color );
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }
        }
Ejemplo n.º 16
0
 public override void render(Nez.Graphics graphics, Camera camera)
 {
     graphics.batcher.draw(_subtexture, entity.transform.position + localOffset, color, entity.transform.rotation, origin, entity.transform.scale * _scale, spriteEffects, _layerDepth);
 }
Ejemplo n.º 17
0
 public override void debugRender( Graphics graphics )
 {
     graphics.batcher.drawHollowRect( shape.bounds, Color.Black );
     graphics.batcher.drawPolygon( absolutePosition, ((shape as Polygon).points), Color.DarkRed, true );
     graphics.batcher.drawPixel( absolutePosition, Color.Yellow, 4 );
 }
Ejemplo n.º 18
0
		public override void render( Graphics graphics, Camera camera )
		{
			// First we draw all the trail nodes using the border color. we need to draw them slightly larger, so the border is left visible
			// when we draw the actual nodes

			// adjust the startScale and endScale to take into consideration the border
			var borderStartScale = startScale + borderSize / _cursorTexture.Width;
			var borderEndScale = endScale + borderSize / _cursorTexture.Width;

			// draw all nodes with the new scales
			for( var i = 0; i < _trailNodeCount; i++ )
			{
				var node = _trailNodes[i];
				var lerpFactor = (float)i / (float)( _trailNodeCount - 1 );
				lerpFactor = Mathf.pow( lerpFactor, lerpExponent );
				var scale = MathHelper.Lerp( borderStartScale, borderEndScale, lerpFactor );

				// draw using the border Color
				graphics.batcher.draw( _cursorTexture, node.position, null, borderColor, 0.0f, _textureCenter, scale, SpriteEffects.None, 0.0f );
			}

			// Next, we draw all the nodes normally, using the fill Color because before we drew them larger, after we draw them at
			// their normal size, a border will remain visible.
			for( var i = 0; i < _trailNodeCount; i++ )
			{
				var node = _trailNodes[i];
				var lerpFactor = (float)i / (float)( _trailNodeCount - 1 );
				lerpFactor = Mathf.pow( lerpFactor, lerpExponent );
				var scale = MathHelper.Lerp( startScale, endScale, lerpFactor );

				// draw using the fill color
				graphics.batcher.draw( _cursorTexture, node.position, null, fillColor, 0.0f, _textureCenter, scale, SpriteEffects.None, 0.0f );
			}
		}
Ejemplo n.º 19
0
        public override void render( Graphics graphics, Camera camera )
        {
            calculateVertices();
            _basicEffect.Projection = camera.projectionMatrix;
            _basicEffect.View = camera.transformMatrix;
            _basicEffect.CurrentTechnique.Passes[0].Apply();

            Core.graphicsDevice.DrawUserPrimitives( PrimitiveType.TriangleStrip, _vertices, 0, _ribbonLength * 2 + 1 );
        }
Ejemplo n.º 20
0
		public override void render( Graphics graphics )
		{
			Core.graphicsDevice.setRenderTarget( null );
			graphics.batcher.begin( BlendState.NonPremultiplied, Core.defaultSamplerState, DepthStencilState.None, null );

			// we only render the previousSceneRender while fading to _color. It will be null after that.
			if( !_isNewSceneLoaded )
				graphics.batcher.draw( previousSceneRender, _destinationRect, Color.White );
			
			graphics.batcher.draw( _overlayTexture, new Rectangle( 0, 0, Screen.width, Screen.height ), _color );
			
			graphics.batcher.end();
		}
Ejemplo n.º 21
0
		public override void render( Graphics graphics )
		{
			Core.graphicsDevice.setRenderTarget( null );
			graphics.batcher.begin( BlendState.AlphaBlend, Core.defaultSamplerState, DepthStencilState.None, null, _textureWipeEffect );

			// we only render the previousSceneRender while populating the squares
			if( !_isNewSceneLoaded )
				graphics.batcher.draw( previousSceneRender, _destinationRect, Color.White );
			else
				graphics.batcher.draw( _overlayTexture, new Rectangle( 0, 0, Screen.width, Screen.height ), Color.Transparent );

			graphics.batcher.end();
		}
Ejemplo n.º 22
0
 public override void render( Graphics graphics, Camera camera )
 {
     _sprite.drawOutline( graphics, camera, outlineColor, outlineWidth );
     _sprite.render( graphics, camera );
 }
Ejemplo n.º 23
0
 public override void render( Graphics graphics, Camera camera )
 {
     graphics.batcher.draw( subtexture, entity.transform.position + _localOffset, _sourceRect, color, entity.transform.rotation, origin, entity.transform.scale, spriteEffects, _layerDepth );
 }
Ejemplo n.º 24
0
 public override void render( Graphics graphics, Camera camera )
 {
     // we override render and use position instead of entityPosition. this keeps the text in place even if the entity moves
     graphics.batcher.drawString( _font, _text, localOffset, color, entity.transform.rotation, origin, entity.transform.scale, spriteEffects, layerDepth );
 }
Ejemplo n.º 25
0
		/// <summary>
		/// returns true if we are done with this debug draw item
		/// </summary>
		public bool draw( Graphics graphics )
		{
			switch( drawType )
			{
				case DebugDrawType.Line:
					graphics.batcher.drawLine( start, end, color );
					break;
				case DebugDrawType.HollowRectangle:
					graphics.batcher.drawHollowRect( rectangle, color );
					break;
				case DebugDrawType.Pixel:
					graphics.batcher.drawPixel( x, y, color, size );
					break;
				case DebugDrawType.BitmapFontText:
					graphics.batcher.drawString( bitmapFont, text, position, color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f );
					break;
				case DebugDrawType.SpriteFontText:
					graphics.batcher.drawString( spriteFont, text, position, color, 0f, Vector2.Zero, new Vector2( scale ), SpriteEffects.None, 0f );
					break;
				case DebugDrawType.ConsoleText:
					graphics.batcher.drawString( bitmapFont, text, position, color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f );
					break;
			}

			duration -= Time.deltaTime;

			return duration < 0f;
		}
Ejemplo n.º 26
0
		public override void render( Graphics graphics, Camera camera )
		{
			// flush the 2D batch so we render appropriately depth-wise
			graphics.batcher.flushBatch();

			Core.graphicsDevice.BlendState = BlendState.Opaque;
			Core.graphicsDevice.DepthStencilState = DepthStencilState.Default;

			// Set BasicEffect parameters.
			_basicEffect.World = worldMatrix;
			_basicEffect.View = camera.viewMatrix3D;
			_basicEffect.Projection = camera.projectionMatrix3D;
			_basicEffect.DiffuseColor = color.ToVector3();

			// Set our vertex declaration, vertex buffer, and index buffer.
			Core.graphicsDevice.SetVertexBuffer( _vertexBuffer );
			Core.graphicsDevice.Indices = _indexBuffer;

			_basicEffect.CurrentTechnique.Passes[0].Apply();
			var primitiveCount = _indices.Count / 3;
			Core.graphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, primitiveCount );
		}
Ejemplo n.º 27
0
		public override void render( Graphics graphics )
		{
			Core.graphicsDevice.setRenderTarget( null );

			// if we are scaling out we dont need to render the previous scene anymore since we want the new scene to be visible
			if( !_isNewSceneLoaded )
			{
				graphics.batcher.begin( BlendState.Opaque, Core.defaultSamplerState, DepthStencilState.None, null );
				graphics.batcher.draw( previousSceneRender, Vector2.Zero, Color.White );
				graphics.batcher.end();
			}

			graphics.batcher.begin( _blendState, Core.defaultSamplerState, DepthStencilState.None, null );
			graphics.batcher.draw( _maskRenderTarget, Vector2.Zero, Color.White );
			graphics.batcher.end();
		}
Ejemplo n.º 28
0
 public override void debugRender( Graphics graphics )
 {
     // due to the override of position in render we have to do the same here
     var rect = bounds;
     rect.location = localOffset;
     graphics.batcher.drawHollowRect( rect, Color.Yellow );
 }
Ejemplo n.º 29
0
		public override void render( Graphics graphics, Camera camera )
		{
			// TODO: make culling smarter and only render the lines that are actually on the screen rather than all or nothing
			var width = _points.GetLength( 0 );
			var height = _points.GetLength( 1 );

			for( var y = 1; y < height; y++ )
			{
				for( var x = 1; x < width; x++ )
				{
					var left = new Vector2();
					var up = new Vector2();
					var p = projectToVector2( _points[x, y].position );

					if( x > 1 )
					{
						float thickness;
						Color gridColor;
						if( y % gridMajorPeriodY == 1 )
						{
							thickness = gridMajorThickness;
							gridColor = gridMajorColor;
						}
						else
						{
							thickness = gridMinorThickness;
							gridColor = gridMinorColor;
						}


						// use Catmull-Rom interpolation to help smooth bends in the grid
						left = projectToVector2( _points[x - 1, y].position );
						var clampedX = Math.Min( x + 1, width - 1 );
						var mid = Vector2.CatmullRom( projectToVector2( _points[x - 2, y].position ), left, p, projectToVector2( _points[clampedX, y].position ), 0.5f );

						// If the grid is very straight here, draw a single straight line. Otherwise, draw lines to our new interpolated midpoint
						if( Vector2.DistanceSquared( mid, ( left + p ) / 2 ) > 1 )
						{
							drawLine( graphics.batcher, left, mid, gridColor, thickness );
							drawLine( graphics.batcher, mid, p, gridColor, thickness );
						}
						else
						{
							drawLine( graphics.batcher, left, p, gridColor, thickness );
						}
					}

					if( y > 1 )
					{
						float thickness;
						Color gridColor;
						if( x % gridMajorPeriodX == 1 )
						{
							thickness = gridMajorThickness;
							gridColor = gridMajorColor;
						}
						else
						{
							thickness = gridMinorThickness;
							gridColor = gridMinorColor;
						}

						up = projectToVector2( _points[x, y - 1].position );
						var clampedY = Math.Min( y + 1, height - 1 );
						var mid = Vector2.CatmullRom( projectToVector2( _points[x, y - 2].position ), up, p, projectToVector2( _points[x, clampedY].position ), 0.5f );

						if( Vector2.DistanceSquared( mid, ( up + p ) / 2 ) > 1 )
						{
							drawLine( graphics.batcher, up, mid, gridColor, thickness );
							drawLine( graphics.batcher, mid, p, gridColor, thickness );
						}
						else
						{
							drawLine( graphics.batcher, up, p, gridColor, thickness );
						}
					}

					// Add interpolated lines halfway between our point masses. This makes the grid look
					// denser without the cost of simulating more springs and point masses.
					if( x > 1 && y > 1 )
					{
						var upLeft = projectToVector2( _points[x - 1, y - 1].position );
						drawLine( graphics.batcher, 0.5f * ( upLeft + up ), 0.5f * ( left + p ), gridMinorColor, gridMinorThickness );  // vertical line
						drawLine( graphics.batcher, 0.5f * ( upLeft + left ), 0.5f * ( up + p ), gridMinorColor, gridMinorThickness );  // horizontal line
					}
				}
			}
		}
Ejemplo n.º 30
0
 public override void debugRender( Graphics graphics )
 {
     graphics.batcher.drawCircle( bounds.center, ((Circle)shape).radius, Color.IndianRed );
     graphics.batcher.drawPixel( bounds.center, Color.IndianRed, 4 );
 }
Ejemplo n.º 31
0
		public override void preRender( Graphics graphics )
		{
			Core.graphicsDevice.setRenderTarget( _maskRenderTarget );
			graphics.batcher.begin( BlendState.AlphaBlend, Core.defaultSamplerState, DepthStencilState.None, null );
			graphics.batcher.draw( _maskTexture, _maskPosition, null, Color.White, _renderRotation, _maskOrigin, _renderScale, SpriteEffects.None, 0 );
			graphics.batcher.end();
			Core.graphicsDevice.setRenderTarget( null );
		}
Ejemplo n.º 32
0
		public override void render( Graphics graphics, Camera camera )
		{
			var topLeft = entity.transform.position + _localOffset;
			var destinationRect = RectangleExt.fromFloats( topLeft.X, topLeft.Y, _sourceRect.Width * entity.transform.scale.X * textureScale.X, _sourceRect.Height * entity.transform.scale.Y * textureScale.Y );

			graphics.batcher.draw( subtexture, destinationRect, _sourceRect, color, entity.transform.rotation, origin * _inverseTexScale, spriteEffects, _layerDepth );
		}
Ejemplo n.º 33
0
		public override void render( Graphics graphics, Camera camera )
		{
			var pos = ( entity.transform.position - ( origin * entity.transform.localScale ) + localOffset );
			var size = new Point( (int)( _width * entity.transform.localScale.X ), (int)( _height * entity.transform.localScale.Y ) );
			var destRect = new Rectangle( (int)pos.X, (int)pos.Y, size.X, size.Y );
			graphics.batcher.draw( subtexture, destRect, subtexture.sourceRect, color, entity.transform.rotation, SpriteEffects.None, layerDepth, _skewTopX, _skewBottomX, _skewLeftY, _skewRightY );
		}
Ejemplo n.º 34
0
        public override void render( Graphics graphics, Camera camera )
        {
            _basicEffect.Projection = camera.projectionMatrix;
            _basicEffect.View = camera.transformMatrix;
            _basicEffect.CurrentTechnique.Passes[0].Apply();

            // TODO: set the _basicEffect.World = entity.transform.localToWorldTransform instead of manualy mucking with verts and a local matrix
            // see the deferred lighting PolygonMesh class for details.

            Core.graphicsDevice.SamplerStates[0] = SamplerState.AnisotropicClamp;
            Core.graphicsDevice.DrawUserPrimitives( PrimitiveType.TriangleList, _verts, 0, _points.Length - 2, VertexPositionColor.VertexDeclaration );
        }