Exemplo n.º 1
0
        public override void OnEnter()
        {
            base.OnEnter(); 

            var windowSize = Layer.VisibleBoundsWorldspace.Size;
            CCRenderTexture text = new CCRenderTexture(windowSize,windowSize);
            text.Sprite.Position = windowSize.Center;
            AddChild(text.Sprite, 24);

            CCDrawNode draw = new CCDrawNode();

            // Draw polygons
            CCPoint[] points = new CCPoint[]
                {
                    new CCPoint(windowSize.Height / 4, 0),
                    new CCPoint(windowSize.Width, windowSize.Height / 5),
                    new CCPoint(windowSize.Width / 3 * 2, windowSize.Height)
                };
            draw.DrawPolygon(points, points.Length, new CCColor4F(1, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1));
            draw.AnchorPoint = CCPoint.AnchorLowerLeft;

            text.Begin();
            draw.Visit();
            text.End();        
        }
        public override void OnEnter()
        {
            base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            spritePremulti.Position = new CCPoint(16, 48);
            spriteNonpremulti.Position = new CCPoint(16, 16);

            CCSize rendSize = new CCSize(32, 64);

            /* A2 & B2 setup */
            CCRenderTexture rend = new CCRenderTexture(rendSize,rendSize);

            //  It's possible to modify the RenderTexture blending function by
            //  CCBlendFunc bf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA);
            //  rend.Sprite.BlendFunc = bf;

            rend.BeginWithClear(CCColor4B.Transparent);
            // A2
            spritePremulti.Visit();
            // B2
            spriteNonpremulti.Visit();
            rend.End();

            /* A1: setup */
            spritePremulti.Position = new CCPoint(windowSize.Width / 2 - 16, windowSize.Height / 2 + 16);
            /* B1: setup */
            spriteNonpremulti.Position = new CCPoint(windowSize.Width / 2 - 16, windowSize.Height / 2 - 16);

            rend.Sprite.Position = new CCPoint(windowSize.Width / 2 + 16, windowSize.Height / 2);

            AddChild(spriteNonpremulti);
            AddChild(spritePremulti);
            AddChild(rend.Sprite);
        }
Exemplo n.º 3
0
        public override void OnEnter()
        {
            base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            // create a render texture, this is what we are going to draw into
            target = new CCRenderTexture(windowSize, windowSize,
                CCSurfaceFormat.Color, 
                CCDepthFormat.None, CCRenderTargetUsage.PreserveContents);

            // Let's clear the rendertarget here so that we start off fresh.
            // Some platforms do not seem to be initializing the rendertarget color so this will make sure the background shows up colored instead of 
            // what looks like non initialized.  Mostly MacOSX for now.
            target.Clear(0,0,0,255);

            target.Position = new CCPoint(windowSize.Width / 2, windowSize.Height / 2);

            // It's possible to modify the RenderTexture blending function by
            //CCBlendFunc tbf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA);
            //target.Sprite.BlendFunc = tbf;

            // note that the render texture is a CCNode, and contains a sprite of its texture for convience,
            // so we can just parent it to the scene like any other CCNode
            AddChild(target, -1);

            saveImageMenu.AlignItemsVertically();
            saveImageMenu.Position = new CCPoint(windowSize.Width - 80, windowSize.Height - 30);

            // Register Touch Event
            var touchListener = new CCEventListenerTouchAllAtOnce();
            touchListener.OnTouchesMoved = OnTouchesMoved;

            AddEventListener(touchListener);
        }
Exemplo n.º 4
0
        public override void OnEnter()
        {
            base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            // create a render texture, this is what we are going to draw into
            target = new CCRenderTexture(windowSize, windowSize,
                CCSurfaceFormat.Color, 
                CCDepthFormat.None, CCRenderTargetUsage.PreserveContents);


            target.Sprite.Position = new CCPoint(windowSize.Width / 2, windowSize.Height / 2);

            target.Sprite.AnchorPoint = CCPoint.AnchorMiddle;

            // It's possible to modify the RenderTexture blending function by
            //CCBlendFunc tbf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA);
            //target.Sprite.BlendFunc = tbf;

            // note that the render texture is a CCNode, and contains a sprite of its texture for convience,
            // so we can just parent it to the scene like any other CCNode
            AddChild(target.Sprite);

            saveImageMenu.AlignItemsVertically();
            saveImageMenu.Position = new CCPoint(windowSize.Width - 80, windowSize.Height - 30);

            // Register Touch Event
            var touchListener = new CCEventListenerTouchAllAtOnce();
            touchListener.OnTouchesMoved = OnTouchesMoved;

            AddEventListener(touchListener);
        }
        public SpriteWithColor(CCColor4B bgColor, CCSize textureSizeInPixels) : base ()
        {
            // 1: Create new CCRenderTexture
            CCRenderTexture rt = new CCRenderTexture(textureSizeInPixels, textureSizeInPixels);

            // 2: Call CCRenderTexture:begin
            rt.BeginWithClear(bgColor);

            // 3: Draw into the texture
            // You'll add this later
            GenerateGradient(textureSizeInPixels);


            var noise = new CCSprite("images/Noise.png");
            noise.AnchorPoint = CCPoint.AnchorLowerLeft;
            noise.Position = CCPoint.Zero;
            noise.BlendFunc = new CCBlendFunc(CCOGLES.GL_DST_COLOR, CCOGLES.GL_ZERO);
            noise.Texture.SamplerState = Microsoft.Xna.Framework.Graphics.SamplerState.LinearWrap;

            // To get the linear wrap to work correctly we have to set the TextureRectInPixels as well as ContentSize
            noise.TextureRectInPixels = new CCRect(0, 0, textureSizeInPixels.Width, textureSizeInPixels.Height);
            noise.ContentSize = noise.TextureRectInPixels.Size;
            noise.Visit();

            // 4: Call CCRenderTexture:end
            rt.End();

            this.Texture = rt.Texture;

        }
Exemplo n.º 6
0
        protected CCGridBase(CCGridSize gridSize, CCRenderTexture renderTexture, bool flipped = false)
        {
            GridSize       = gridSize;
            RenderTexture  = renderTexture;
            textureFlipped = flipped;
            CCSize texSize = renderTexture.Texture.ContentSizeInPixels;

            Step = new CCPoint((float)Math.Ceiling(texSize.Width / GridSize.X), (float)Math.Ceiling(texSize.Height / GridSize.Y));
        }
        public override void OnEnter()
        {
            base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            CCSprite sprite = new CCSprite("Images/fire");
            sprite.Position = new CCPoint(windowSize.Width * 0.25f, 0);
            sprite.Scale = 10;

            CCRenderTexture rend = new CCRenderTexture(windowSize, windowSize,
                CCSurfaceFormat.Color, 
                CCDepthFormat.Depth24Stencil8, CCRenderTargetUsage.DiscardContents);

            rend.BeginWithClear(0, 0, 0, 0, 0);

//            var save = CCDrawManager.SharedDrawManager.DepthStencilState;
//
//            CCDrawManager.SharedDrawManager.DepthStencilState = new DepthStencilState()
//                {
//                    ReferenceStencil = 1,
//
//                    DepthBufferEnable = false,
//                    StencilEnable = true,
//                    StencilFunction = CompareFunction.Always,
//                    StencilPass = StencilOperation.Replace,
//                    
//                    TwoSidedStencilMode = true,
//                    CounterClockwiseStencilFunction = CompareFunction.Always,
//                    CounterClockwiseStencilPass = StencilOperation.Replace,
//                };

            sprite.Visit();

//            CCDrawManager.SharedDrawManager.DepthStencilState = new DepthStencilState()
//            {
//                DepthBufferEnable = false,
//                StencilEnable = true,
//                StencilFunction = CompareFunction.NotEqual,
//                StencilPass = StencilOperation.Keep,
//                ReferenceStencil = 1
//            };

//            CCDrawManager.SharedDrawManager.BlendFunc(new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE_MINUS_SRC_ALPHA));

            sprite.Position = sprite.Position 
                + new CCPoint(sprite.ContentSize.Width * sprite.ScaleX, sprite.ContentSize.Height * sprite.ScaleY) * 0.5f;

            sprite.Visit();

//            CCDrawManager.SharedDrawManager.DepthStencilState = save;

            rend.End();

            rend.Sprite.Position = new CCPoint(windowSize.Width * 0.5f, windowSize.Height * 0.5f);

            AddChild(rend.Sprite);
        }
Exemplo n.º 8
0
        protected override void InitialiseScenes()
        {
            if (Layer == null || Viewport == null)
            {
                return;
            }

            base.InitialiseScenes();

            SetupTransition();

            // create a transparent color layer
            // in which we are going to add our rendertextures
            var    bounds       = Layer.VisibleBoundsWorldspace;
            CCRect viewportRect = Viewport.ViewportInPixels;

            // create the second render texture for outScene
            CCRenderTexture texture = new CCRenderTexture(bounds.Size, viewportRect.Size);

            texture.Position    = bounds.Center;
            texture.AnchorPoint = CCPoint.AnchorMiddle;

            // Temporarily add render texture to get layer/scene properties
            Layer.AddChild(texture);
            texture.Visible = false;

            // Render outScene to its texturebuffer
            texture.BeginWithClear(0, 0, 0, 1);
            SceneNodeContainerToBeModified.Visit();
            texture.End();

            texture.Visible = true;

            // No longer want to render texture
            RemoveChild(texture);

            // Since we've passed the outScene to the texture we don't need it.
            if (SceneNodeContainerToBeModified == OutSceneNodeContainer)
            {
                HideOutShowIn();
            }

            CCProgressTimer node = ProgressTimerNodeWithRenderTexture(texture);

            // create the blend action
            var layerAction = new CCProgressFromTo(Duration, From, To);

            // add the layer (which contains our two rendertextures) to the scene
            AddChild(node, 2, SceneRadial);

            // run the blend action
            node.RunAction(layerAction);
        }
Exemplo n.º 9
0
        protected override void InitialiseScenes()
        {
            if (Layer == null || Viewport == null)
                return;

            base.InitialiseScenes();

            SetupTransition();

            // create a transparent color layer
            // in which we are going to add our rendertextures
            var bounds = Layer.VisibleBoundsWorldspace;
            CCRect viewportRect = Viewport.ViewportInPixels;

            // create the second render texture for outScene
            CCRenderTexture texture = new CCRenderTexture(bounds.Size, viewportRect.Size);
            texture.Position = bounds.Center;
            texture.AnchorPoint = CCPoint.AnchorMiddle;

            // Temporarily add render texture to get layer/scene properties
            Layer.AddChild(texture);
            texture.Visible = false;

            // Render outScene to its texturebuffer
            texture.BeginWithClear(0, 0, 0, 1);
            SceneNodeContainerToBeModified.Visit();
            texture.End();

            texture.Visible = true;

            // No longer want to render texture
            RemoveChild(texture);

            // Since we've passed the outScene to the texture we don't need it.
            if (SceneNodeContainerToBeModified == OutSceneNodeContainer)
            {
                HideOutShowIn();
            }

            CCProgressTimer node = ProgressTimerNodeWithRenderTexture(texture);

            // create the blend action
            var layerAction = new CCProgressFromTo(Duration, From, To);

            // add the layer (which contains our two rendertextures) to the scene
            AddChild(node, 2, SceneRadial);

            // run the blend action
            node.RunAction(layerAction);
        }
Exemplo n.º 10
0
        void UpdateClipping()
        {
            if (ChildClippingMode == CCClipMode.BoundsWithRenderTarget && Scene != null)
            {
                CCRect bounds       = VisibleBoundsWorldspace;
                CCRect viewportRect = Viewport.ViewportInPixels;

                renderTexture = new CCRenderTexture(bounds.Size, viewportRect.Size);
                renderTexture.Sprite.AnchorPoint = new CCPoint(0, 0);
            }
            else
            {
                renderTexture = null;
            }
        }
Exemplo n.º 11
0
        protected override void InitialiseScenes()
        {
            if (Layer == null)
            {
                return;
            }

            base.InitialiseScenes();

            SetupTransition();

            // create a transparent color layer
            // in which we are going to add our rendertextures
            var    bounds       = Layer.VisibleBoundsWorldspace;
            CCRect viewportRect = new CCRect(Viewport.Bounds);

            // create the second render texture for outScene
            CCRenderTexture texture = new CCRenderTexture(bounds.Size, viewportRect.Size);

            texture.Sprite.Position    = bounds.Center;
            texture.Sprite.AnchorPoint = CCPoint.AnchorMiddle;


            // Render outScene to its texturebuffer
            texture.BeginWithClear(0, 0, 0, 255);
            var worldTransform = SceneNodeContainerToBeModified.AffineWorldTransform;

            SceneNodeContainerToBeModified.Visit(ref worldTransform);
            texture.End();

            // Since we've passed the outScene to the texture we don't need it.
            if (SceneNodeContainerToBeModified == OutSceneNodeContainer)
            {
                HideOutShowIn();
            }

            CCProgressTimer node = ProgressTimerNodeWithRenderTexture(texture);

            // create the blend action
            var layerAction = new CCProgressFromTo(Duration, From, To);

            // add the layer (which contains our two rendertextures) to the scene
            Layer.AddChild(node, 2);

            // run the blend action
            node.RunAction(layerAction);
        }
        public void NeedsLayout()
        {
            OnSprite.Position    = new CCPoint(OnSprite.ContentSize.Width / 2 + sliderXPosition, OnSprite.ContentSize.Height / 2);
            OffSprite.Position   = new CCPoint(OnSprite.ContentSize.Width + OffSprite.ContentSize.Width / 2 + sliderXPosition, OffSprite.ContentSize.Height / 2);
            ThumbSprite.Position = new CCPoint(OnSprite.ContentSize.Width + sliderXPosition, MaskSprite.ContentSize.Height / 2);

            if (OnLabel != null)
            {
                OnLabel.Position = new CCPoint(OnSprite.Position.X - ThumbSprite.ContentSize.Width / 6, OnSprite.ContentSize.Height / 2);
            }
            if (OffLabel != null)
            {
                OffLabel.Position = new CCPoint(OffSprite.Position.X + ThumbSprite.ContentSize.Width / 6, OffSprite.ContentSize.Height / 2);
            }

            var rt = new CCRenderTexture(
                MaskSprite.TextureRectInPixels.Size,
                MaskSprite.TextureRectInPixels.Size,
                CCSurfaceFormat.Color, CCDepthFormat.None, CCRenderTargetUsage.DiscardContents
                );

            rt.BeginWithClear(0, 0, 0, 0);

            OnSprite.Visit();
            OffSprite.Visit();

            if (OnLabel != null)
            {
                OnLabel.Visit();
            }
            if (OffLabel != null)
            {
                OffLabel.Visit();
            }

            MaskSprite.AnchorPoint = new CCPoint(0, 0);
            MaskSprite.BlendFunc   = new CCBlendFunc(CCOGLES.GL_ZERO, CCOGLES.GL_SRC_ALPHA);

            MaskSprite.Visit();

            rt.End();

            Texture = rt.Sprite.Texture;

            ContentSize = MaskSprite.ContentSize;
        }
Exemplo n.º 13
0
        protected override CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture)
        {
            var bounds = Layer.VisibleBoundsWorldspace;

            CCProgressTimer node = new CCProgressTimer(texture.Sprite);

            // but it is flipped upside down so we flip the sprite
            //node.Sprite.IsFlipY = true;
            node.Type = CCProgressTimerType.Radial;

            //    Return the radial type that we want to use
            node.ReverseDirection = true;
            node.Percentage       = 100;
            node.Position         = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2);
            node.AnchorPoint      = CCPoint.AnchorMiddle;

            return(node);
        }
Exemplo n.º 14
0
        protected override CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture)
        {
            var bounds = Layer.VisibleBoundsWorldspace;

            CCProgressTimer node = new CCProgressTimer(texture.Sprite);

            // but it is flipped upside down so we flip the sprite
            //node.Sprite.IsFlipY = true;
            node.Type = CCProgressTimerType.Bar;

            node.Midpoint      = new CCPoint(0.5f, 0.5f);
            node.BarChangeRate = new CCPoint(1, 1);

            node.Percentage  = 100;
            node.Position    = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2);
            node.AnchorPoint = CCPoint.AnchorMiddle;

            return(node);
        }
        public StripeWithColor(CCColor4B c1, CCColor4B c2, CCSize textureSizeInPixels, int nStripes) : base ()
        {
            // 1: Create new CCRenderTexture
            CCRenderTexture rt = new CCRenderTexture(textureSizeInPixels, textureSizeInPixels);

            // 2: Call CCRenderTexture:begin
            rt.BeginWithClear(c1);

            // 3: Draw into the texture
            // You'll add this later
            GenerateStripes(textureSizeInPixels, c2, nStripes);

            var noise = new CCSprite("images/Noise.png");
            noise.AnchorPoint = CCPoint.AnchorLowerLeft;
            noise.BlendFunc = new CCBlendFunc(CCOGLES.GL_DST_COLOR, CCOGLES.GL_ZERO);
            noise.Visit();

            // 4: Call CCRenderTexture:end
            rt.End();

            this.Texture = rt.Texture;
        }
        public LabelSystemFontRenderTexture()
        {

            Color = new CCColor3B(200, 191, 231);
            Opacity = 255;

            label1 = new CCLabel("Visit Rendering", "fonts/MorrisRoman-Black.ttf", 30, CCLabelFormat.SystemFont)
                {
                    Color = CCColor3B.Orange,
                    AnchorPoint = CCPoint.AnchorMiddleLeft,
                    Dimensions = size,
                };
            label1.LabelFormat.Alignment = CCTextAlignment.Center;

            txtLabel = new CCRenderTexture (size, size);


            txtLabel.BeginWithClear (CCColor4B.AliceBlue);
            label1.Visit ();
            txtLabel.End ();

            AddChild(txtLabel.Sprite);

        }
Exemplo n.º 17
0
 protected abstract CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture);
Exemplo n.º 18
0
 public CCTiledGrid3D(CCGridSize gridSize, CCRenderTexture renderTexture, bool flipped = false)
     : base(gridSize, renderTexture, flipped)
 {
 }
        public CCTexture2D CreateCharacterTexture(CCDirector director)
        {
            const int width = 490;
            const int height = 278;

            CCSize rendSize = new CCSize(width, height);

            var centerPoint = new CCPoint(width / 2, height / 2);
            var characterTexture = new CCRenderTexture(rendSize, rendSize);

            characterTexture.BeginWithClear(100, 0, 0, 0);

            var bodySprite = CreateCustomisationSprite();
            bodySprite.Position = centerPoint;
            bodySprite.Visit();

            var armorSprite = CreateCustomisationSprite();
            armorSprite.Position = centerPoint;
            armorSprite.Visit();

            var eyesSprite = CreateCustomisationSprite();
            eyesSprite.Position = centerPoint;
            eyesSprite.Visit();

            var noseSprite = CreateCustomisationSprite();
            noseSprite.Position = centerPoint;
            noseSprite.Visit();

            var hairSprite = CreateCustomisationSprite();
            hairSprite.Position = centerPoint;
            hairSprite.Visit();

            var moustacheSprite = CreateCustomisationSprite();
            moustacheSprite.Position = centerPoint;
            moustacheSprite.Visit();

            var beardSprite = CreateCustomisationSprite();
            beardSprite.Position = centerPoint;
            beardSprite.Visit();

            var helmutSprite = CreateCustomisationSprite();
            helmutSprite.Position = centerPoint;
            helmutSprite.Visit();

            var weaponSprite = CreateCustomisationSprite();
            weaponSprite.Position = centerPoint;
            weaponSprite.Visit();

            characterTexture.End();

            return characterTexture.Sprite.Texture;
        }
        public void renderScreenShot()
        {
            var size = Layer.VisibleBoundsWorldspace.Size;
            var texture = new CCRenderTexture(size,size);
            //var texture = new CCRenderTexture(512, 512);

            texture.AnchorPoint = new CCPoint(0, 0);
            texture.Begin();

            Visit();

            texture.End();

            CCSprite sprite = new CCSprite(texture.Sprite.Texture);

            //sprite.Position = new CCPoint(256, 256);
            sprite.Position = new CCPoint(size.Width/2, size.Height / 2);
            sprite.Opacity = 182;
            //sprite.IsFlipY = true;
            AddChild(sprite, 999999);
            sprite.Color = CCColor3B.Green;

            sprite.RunAction(
                new CCSequence(
                    new CCFadeTo (2, 0),
                    new CCHide()
                )
            );
        }
Exemplo n.º 21
0
        protected override CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture)
        {
            var bounds = Layer.VisibleBoundsWorldspace;

            CCProgressTimer node = new CCProgressTimer(texture.Sprite);

            // but it is flipped upside down so we flip the sprite
            //node.Sprite.IsFlipY = true;
            node.Type = CCProgressTimerType.Bar;

            node.Midpoint = new CCPoint(0.5f, 0.5f);
            node.BarChangeRate = new CCPoint(1, 1);

            node.Percentage = 100;
            node.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2);
            node.AnchorPoint = CCPoint.AnchorMiddle;

            return node;
        }
        public void NeedsLayout()
        {
			OnSprite.Position = new CCPoint(OnSprite.ContentSize.Width / 2 + sliderXPosition, OnSprite.ContentSize.Height / 2);
			OffSprite.Position = new CCPoint(OnSprite.ContentSize.Width + OffSprite.ContentSize.Width / 2 + sliderXPosition, OffSprite.ContentSize.Height / 2);
			ThumbSprite.Position = new CCPoint(OnSprite.ContentSize.Width + sliderXPosition, MaskSprite.ContentSize.Height / 2);

            if (OnLabel != null)
            {
				OnLabel.Position = new CCPoint(OnSprite.Position.X - ThumbSprite.ContentSize.Width / 6, OnSprite.ContentSize.Height / 2);
            }
            if (OffLabel != null)
            {
				OffLabel.Position = new CCPoint(OffSprite.Position.X + ThumbSprite.ContentSize.Width / 6, OffSprite.ContentSize.Height / 2);
            }

            var rt = new CCRenderTexture(
                MaskSprite.TextureRectInPixels.Size,
                MaskSprite.TextureRectInPixels.Size,
				CCSurfaceFormat.Color, CCDepthFormat.None, CCRenderTargetUsage.DiscardContents
                );

            rt.BeginWithClear(0, 0, 0, 0);

            OnSprite.Visit();
            OffSprite.Visit();

            if (OnLabel != null)
            {
                OnLabel.Visit();
            }
            if (OffLabel != null)
            {
                OffLabel.Visit();
            }

            MaskSprite.AnchorPoint = new CCPoint(0, 0);
            MaskSprite.BlendFunc = new CCBlendFunc(CCOGLES.GL_ZERO, CCOGLES.GL_SRC_ALPHA);

            MaskSprite.Visit();

            rt.End();

			Texture = rt.Sprite.Texture;
            
            ContentSize = MaskSprite.ContentSize;
        }
Exemplo n.º 23
0
        private void SwitchToRenderTexture()
        {
            // The card needs to be moved to the origin (0,0) so it's rendered on the render target. 
            // After it's rendered to the CCRenderTexture, it will be moved back to its old position
            var oldPosition = this.Position;

            // Make sure visuals are part of the card so they get rendered
            bool areVisualComponentsAlreadyAdded = this.Children != null && this.Children.Contains(visualComponents[0]);
            if (!areVisualComponentsAlreadyAdded)
            {
                // Temporarily add them so we can render the object:
                foreach (var component in visualComponents)
                {
                    this.AddChild(component);
                }
            }

            // Create the render texture if it hasn't yet been made:
            if (renderTexture == null)
            {
                // Even though the game is zoomed in to create a pixellated look, we are using
                // high-resolution textures. Therefore, we want to have our canvas be 2x as big as 
                // the background so fonts don't appear pixellated
                var unitResolution = background.ContentSize;
                var pixelResolution = background.ContentSize * 2;
                renderTexture = new CCRenderTexture(unitResolution, pixelResolution);
            }

            // We don't want the render target to be a child of the card 
            // when we call Visit
            if (this.Children != null && this.Children.Contains(renderTexture.Sprite))
            {
                this.RemoveChild(renderTexture.Sprite);
            }

            // Move this instance back to the origin so it is rendered inside the render target:
            this.Position = CCPoint.Zero;

            // Clears the CCRenderTexture
            renderTexture.BeginWithClear(CCColor4B.Transparent);

            // Visit renders this object and all of its children
            this.Visit();

            // Ends the rendering, which means the CCRenderTexture's Sprite can be used
            renderTexture.End();

            // We no longer want the individual components to be drawn, so remove them:
            foreach (var component in visualComponents)
            {
                this.RemoveChild(component);
            }

            // add the render target sprite to this:
            this.AddChild(renderTexture.Sprite);

            renderTexture.Sprite.AnchorPoint = CCPoint.Zero;

            // Move this back to its original position:
            this.Position = oldPosition;

        }
Exemplo n.º 24
0
 protected abstract CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture);
Exemplo n.º 25
0
        void UpdateClipping()
        {
            if (ChildClippingMode == CCClipMode.BoundsWithRenderTarget && Scene !=null)
            {
                CCRect bounds = VisibleBoundsWorldspace;
                CCRect viewportRect = Viewport.ViewportInPixels;

                renderTexture = new CCRenderTexture(bounds.Size, viewportRect.Size);
                renderTexture.Sprite.AnchorPoint = new CCPoint(0, 0);
            }
            else
            {
                renderTexture = null;
            }
        }
Exemplo n.º 26
0
        public override void OnEnter()
        {
            base.OnEnter(); 

            CCDrawNode circle = new CCDrawNode();
            circle.DrawSolidCircle(new CCPoint(150.0f, 150.0f), 75.0f, new CCColor4B(255, 255, 255, 255));

            CCRenderTexture rtm = new CCRenderTexture(new CCSize(200.0f, 200.0f), new CCSize(200.0f, 200.0f), CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8);
            rtm.BeginWithClear(CCColor4B.Orange);
            circle.Visit(); // Draw to rendertarget
            rtm.End();

            // Create a new sprite from the render target texture
            var sprite = new CCSprite(rtm.Texture);
            sprite.Position = VisibleBoundsWorldspace.Center;


            AddChild(sprite);
        }
Exemplo n.º 27
0
        public override void OnEnter()
        {
            base.OnEnter(); 

            CCDrawNode circle = new CCDrawNode();
            circle.DrawSolidCircle(new CCPoint(150.0f, 150.0f), 75.0f, new CCColor4B(255, 255, 255, 255));

            CCRenderTexture rtm = new CCRenderTexture(new CCSize(200.0f, 200.0f), new CCSize(200.0f, 200.0f), CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8);

            rtm.BeginWithClear(CCColor4B.Orange);
            circle.Visit();
            rtm.End();

            // Make sure our children nodes get visited

            rtm.Sprite.Position = VisibleBoundsWorldspace.Center;
            rtm.Sprite.AnchorPoint = CCPoint.AnchorMiddle;


            AddChild(rtm.Sprite);
        }
Exemplo n.º 28
0
        void SaveImage(object sender)
        {
            RemoveChildByTag(spriteTag);
            var renderSize = canvasNode.BoundingRect.Size;
            var renderOrigin = canvasNode.BoundingRect.Origin;

            // here we calculate the translation of the rendering.  It should be the offset of BoundingRect Origin
            // this will then be passed to the Visit(ref CCAffineTransform) method.
            var translate = CCAffineTransform.Translate(canvasNode.AffineWorldTransform, -renderOrigin.X, -renderOrigin.Y);

            var rtm = new CCRenderTexture(renderSize, renderSize);

            rtm.BeginWithClear(CCColor4B.Green);
            canvasNode.Visit(ref translate);
            rtm.End();

            rtm.Texture.IsAntialiased = true;
            rtm.Sprite.AnchorPoint = CCPoint.AnchorLowerLeft;
            rtm.Sprite.Opacity = 127;
            AddChild(rtm.Sprite, 50, spriteTag); ;
        }
Exemplo n.º 29
0
        void SaveImage(object sender)
        {
            RemoveChildByTag(spriteTag);
            var renderSize = canvasNode.BoundingRect.Size;
            var rtm = new CCRenderTexture(renderSize, renderSize);

            rtm.BeginWithClear(CCColor4B.Green);
            canvasNode.Position -= canvasNode.BoundingRect.Origin;
            canvasNode.Visit();
            rtm.End();
            canvasNode.Position = CCPoint.Zero;

            rtm.Texture.IsAntialiased = true;
            rtm.Sprite.AnchorPoint = CCPoint.AnchorLowerLeft;
            rtm.Sprite.Opacity = 127;
            AddChild(rtm.Sprite, 50, spriteTag); ;
        }
Exemplo n.º 30
0
        protected override CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture)
        {
            var bounds = Layer.VisibleBoundsWorldspace;

            CCProgressTimer node = new CCProgressTimer(texture.Sprite);

            // but it is flipped upside down so we flip the sprite
            //node.Sprite.IsFlipY = true;
            node.Type = CCProgressTimerType.Radial;

            //    Return the radial type that we want to use
            node.ReverseDirection = false;
            node.Percentage = 100;
            node.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2);
            node.AnchorPoint = CCPoint.AnchorMiddle;

            return node;
        }