public void renderScreenShot() { var size = CCDirector.SharedDirector.WinSize; var texture = new CCRenderTexture((int)size.Width, (int)size.Height); //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 = CCTypes.CCGreen; sprite.RunAction( CCSequence.FromActions( new CCFadeTo(2, 0), new CCHide() ) ); }
public override void OnEnter() { base.OnEnter(); var windowSize = Layer.VisibleBoundsWorldspace.Size; CCRenderTexture text = new CCRenderTexture(windowSize, windowSize); AddChild(text, 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(); }
protected override void InitialiseScenes() { base.InitialiseScenes(); var bounds = Layer.VisibleBoundsWorldspace; CCRect viewportRect = Viewport.ViewportInPixels; CCRenderTexture outTexture = new CCRenderTexture(bounds.Size, viewportRect.Size); CCSprite outTexSprite = outTexture.Sprite; var worldTransform = Layer.AffineWorldTransform; outTexture.BeginWithClear(0, 0, 0, 0); OutSceneNodeContainer.Visit(ref worldTransform); outTexture.End(); outTexSprite.AnchorPoint = CCPoint.AnchorMiddle; outTexSprite.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2); outTexSprite.BlendFunc = CCBlendFunc.NonPremultiplied; outTexSprite.Opacity = 255; CCAction layerAction = new CCSequence(new CCFadeTo(Duration, 0), new CCCallFunc((Finish))); outTexSprite.RunAction(layerAction); Layer.AddChild(outTexture.Sprite, 3); InSceneNodeContainer.Visible = true; OutSceneNodeContainer.Visible = false; }
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; }
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.Begin(); // 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.Position = new CCPoint(windowSize.Width / 2 + 16, windowSize.Height / 2); AddChild(spriteNonpremulti); AddChild(spritePremulti); AddChild(rend); }
void OnCapture(object sender) { RemoveChildByTag(childTag); var windowSize = 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 = windowSize.Center; target.Sprite.AnchorPoint = CCPoint.AnchorMiddle; // begin drawing to the render texture target.BeginWithClear(CCColor4B.Blue); Layer.Visit(); // finish drawing and return context back to the screen target.End(); AddChild(target.Sprite, 0, childTag); target.Sprite.Scale = 0.25f; }
public void renderScreenShot() { var size = Layer.VisibleBoundsWorldspace.Size; var texture = new CCRenderTexture(size, size); CCAffineTransform worldTransform = AffineWorldTransform; texture.Sprite.AnchorPoint = new CCPoint(0, 0); texture.BeginWithClear(CCColor4B.Transparent); Visit(ref worldTransform); 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() ) ); }
public Button(CCSprite sprite, CCLabel label) : this() { this.ContentSize = sprite.ScaledContentSize; sprite.AnchorPoint = CCPoint.AnchorLowerLeft; label.Position = sprite.ContentSize.Center; // Create the render texture to draw to. It will be the size of the button background sprite var render = new CCRenderTexture(sprite.ContentSize, sprite.ContentSize); // Clear it to any background color you want render.BeginWithClear(CCColor4B.Transparent); // Render the background sprite to the render texture sprite.Visit(); // Render the label to the render texture label.Visit(); // End the rendering render.End(); // Add the button sprite to this node so it can be rendered buttonSprite = render.Sprite; buttonSprite.AnchorPoint = CCPoint.AnchorMiddle; AddChild(this.buttonSprite); }
public CCTexture2D CreateCharacterTexture() { const int width = 490; const int height = 278; var centerPoint = new CCPoint(width / 2, height / 2); var characterTexture = new CCRenderTexture(width, height); 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 RenderTextureTestDepthStencil() { CCSize s = CCDirector.SharedDirector.WinSize; CCSprite sprite = new CCSprite("Images/fire"); sprite.Position = new CCPoint(s.Width * 0.25f, 0); sprite.Scale = 10; CCRenderTexture rend = new CCRenderTexture((int)s.Width, (int)s.Height, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, RenderTargetUsage.DiscardContents); rend.BeginWithClear(0, 0, 0, 0, 0); var save = CCDrawManager.DepthStencilState; CCDrawManager.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.DepthStencilState = new DepthStencilState() { DepthBufferEnable = false, StencilEnable = true, StencilFunction = CompareFunction.NotEqual, StencilPass = StencilOperation.Keep, ReferenceStencil = 1 }; // GL_SRC_ALPHA CCDrawManager.BlendFunc(new CCBlendFunc(OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA)); //! move sprite half width and height, and draw only where not marked sprite.Position = sprite.Position + new CCPoint(sprite.ContentSize.Width * sprite.Scale, sprite.ContentSize.Height * sprite.Scale) * 0.5f; sprite.Visit(); CCDrawManager.DepthStencilState = save; rend.End(); rend.Position = new CCPoint(s.Width * 0.5f, s.Height * 0.5f); AddChild(rend); }
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.Position = new CCPoint(windowSize.Width * 0.5f, windowSize.Height * 0.5f); AddChild(rend); }
private void SwitchToRenderTexture() { bool areVisualComponentsAlreadyAdded = this.Children != null && this.Children.Contains(visualComponents[0]); var oldPosition = this.Position; 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 pixelResolution = background.ContentSize * 2; var unitResolution = background.ContentSize; renderTexture = new CCRenderTexture(unitResolution, pixelResolution); //renderTexture.Sprite.Scale = .5f; } // We don't want the render target to be a child of this when we update it: if (this.Children != null && this.Children.Contains(renderTexture.Sprite)) { this.Children.Remove(renderTexture.Sprite); } // Move this instance back to the origin so it is rendered inside the render target: this.Position = CCPoint.Zero; renderTexture.BeginWithClear(CCColor4B.Transparent); this.Visit(); renderTexture.End(); // We no longer want the individual components to be drawn, so remove them: foreach (var component in visualComponents) { this.RemoveChild(component); } // Move this back to its original position: this.Position = oldPosition; // add the render target sprite to this: renderTexture.Sprite.AnchorPoint = CCPoint.Zero; this.AddChild(renderTexture.Sprite); }
public RenderTextureIssue937() { /* * 1 2 * A: A1 A2 * * B: B1 B2 * * A1: premulti sprite * A2: premulti render * * B1: non-premulti sprite * B2: non-premulti render */ CCLayerColor background = new CCLayerColor(new CCColor4B(200, 200, 200, 255)); AddChild(background); CCSprite spr_premulti = new CCSprite("Images/fire"); spr_premulti.Position = new CCPoint(16, 48); CCSprite spr_nonpremulti = new CCSprite("Images/fire"); spr_nonpremulti.Position = new CCPoint(16, 16); /* A2 & B2 setup */ CCRenderTexture rend = new CCRenderTexture(32, 64); // 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.Begin(); // A2 spr_premulti.Visit(); // B2 spr_nonpremulti.Visit(); rend.End(); CCSize s = CCDirector.SharedDirector.WinSize; /* A1: setup */ spr_premulti.Position = new CCPoint(s.Width / 2 - 16, s.Height / 2 + 16); /* B1: setup */ spr_nonpremulti.Position = new CCPoint(s.Width / 2 - 16, s.Height / 2 - 16); rend.Position = new CCPoint(s.Width / 2 + 16, s.Height / 2); AddChild(spr_nonpremulti); AddChild(spr_premulti); AddChild(rend); }
void OnTouchesMoved(List <CCTouch> touches, CCEvent touchEvent) { CCAffineTransform worldTransform = AffineWorldTransform; CCTouch touch = touches[0]; CCPoint start = touch.Location; CCPoint end = touch.PreviousLocation; // begin drawing to the render texture target.Begin(); // for extra points, we'll draw this smoothly from the last position and vary the sprite's // scale/rotation/offset float distance = CCPoint.Distance(start, end); if (distance > 1) { var d = (int)distance; for (int i = 0; i < d; i++) { float difx = end.X - start.X; float dify = end.Y - start.Y; float delta = i / distance; brush.Position = new CCPoint(start.X + (difx * delta), start.Y + (dify * delta)); brush.Rotation = CCRandom.Next() % 360; float r = (CCRandom.Next() % 50 / 50f) + 0.25f; brush.Scale = r; // Comment out the following line to show just the initial red color set brush.Color = new CCColor3B((byte)(CCRandom.Next() % 127 + 128), 255, 255); // Call visit to draw the brush, don't call draw.. brush.Visit(ref worldTransform); } } // finish drawing and return context back to the screen target.End(); }
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 AddChild(texture); // Render outScene to its texturebuffer texture.BeginWithClear(0, 0, 0, 1); SceneNodeContainerToBeModified.Visit(); texture.End(); // 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); }
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);; }
public override void Visit() { if ((_Texture == null || _Texture.IsDisposed || _Texture.XNATexture == null) && _Rect != null && _Render != null) { CCSize s = ContentSize; if (s.Width >= 1f && s.Height >= 1f) { _Render.Clear(0, 0, 0, 255); _Render.Begin(); _Rect.Visit(); _Render.End(); _Texture = _Render.Sprite.Texture; InitWithTexture(_Texture); } } base.Visit(); }
public GameplayLayer() : base(CCColor4B.Black) { Animations.Init(); renderTexture = new CCRenderTexture(VisibleBoundsWorldspace.Size, VisibleBoundsWorldspace.Size * 2); background = new SpaceBackground(); background.Position = new CCPoint(0, 0); player = new Player(); player.Position = GameParameters.PLAYER_INITIAL_POSITION; player.RocketLaunched += NewRocketHandler; playerCannotMove = false; playerTakesNoDamage = false; playersRocketList = new List <Rocket>(); alienInvadersRocketList = new List <Rocket>(); alienAttackMillis = 0; alienHive = new AlienHive(this.ContentSize, NewRocketHandler); playerLifeHpDisplay = new PlayerLifeHpDisplayNode(ref player); playerLifeHpDisplay.Position = new CCPoint(VisibleBoundsWorldspace.Size.Width, VisibleBoundsWorldspace.Size.Height); renderTexture.BeginWithClear(CCColor4B.Transparent); this.Visit(); renderTexture.End(); this.AddChild(renderTexture.Sprite); renderTexture.Sprite.AddChild(background); renderTexture.Sprite.AddChild(player); foreach (AlienInvader enemy in alienHive.AlienInvadersList) { renderTexture.Sprite.AddChild(enemy); } renderTexture.Sprite.AddChild(playerLifeHpDisplay); Schedule(GameLoop, GameParameters.ANIMATION_FRAME_CHANGE_INTERVAL_SECONDS); }
public override void OnEnter() { base.OnEnter(); SetupTransition(); // create a transparent color layer // in which we are going to add our rendertextures CCSize size = CCDirector.SharedDirector.WinSize; // create the second render texture for outScene CCRenderTexture texture = new CCRenderTexture((int)size.Width, (int)size.Height); texture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); texture.Position = new CCPoint(size.Width / 2, size.Height / 2); texture.AnchorPoint = new CCPoint(0.5f, 0.5f); // render outScene to its texturebuffer texture.Clear(0, 0, 0, 1); texture.Begin(); m_pSceneToBeModified.Visit(); texture.End(); // Since we've passed the outScene to the texture we don't need it. if (m_pSceneToBeModified == m_pOutScene) { HideOutShowIn(); } // We need the texture in RenderTexture. CCProgressTimer node = ProgressTimerNodeWithRenderTexture(texture); // create the blend action CCSequence layerAction = CCSequence.FromActions( new CCProgressFromTo(m_fDuration, m_fFrom, m_fTo), new CCCallFunc(Finish) ); // run the blend action node.RunAction(layerAction); // add the layer (which contains our two rendertextures) to the scene AddChild(node, 2, kCCSceneRadial); }
public override void OnEnter() { base.OnEnter(); SetupTransition(); // create a transparent color layer // in which we are going to add our rendertextures CCSize size = CCDirector.SharedDirector.WinSize; // create the second render texture for outScene CCRenderTexture texture = new CCRenderTexture((int) size.Width, (int) size.Height); texture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); texture.Position = new CCPoint(size.Width / 2, size.Height / 2); texture.AnchorPoint = new CCPoint(0.5f, 0.5f); // render outScene to its texturebuffer texture.Clear(0, 0, 0, 1); texture.Begin(); m_pSceneToBeModified.Visit(); texture.End(); // Since we've passed the outScene to the texture we don't need it. if (m_pSceneToBeModified == m_pOutScene) { HideOutShowIn(); } // We need the texture in RenderTexture. CCProgressTimer node = ProgressTimerNodeWithRenderTexture(texture); // create the blend action CCSequence layerAction = new CCSequence( new CCProgressFromTo(m_fDuration, m_fFrom, m_fTo), new CCCallFunc(Finish) ); // run the blend action node.RunAction(layerAction); // add the layer (which contains our two rendertextures) to the scene AddChild(node, 2, kCCSceneRadial); }
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(); rtm.Position = VisibleBoundsWorldspace.Center; rtm.AnchorPoint = CCPoint.AnchorMiddle; AddChild(rtm); }
public DrawPrimitivesWithRenderTextureTest() { CCSize s = CCDirector.SharedDirector.WinSize; CCRenderTexture text = new CCRenderTexture((int)s.Width, (int)s.Height); CCDrawNode draw = new CCDrawNode(); text.AddChild(draw, 10); text.Begin(); // Draw polygons CCPoint[] points = new CCPoint[] { new CCPoint(s.Height / 4, 0), new CCPoint(s.Width, s.Height / 5), new CCPoint(s.Width / 3 * 2, s.Height) }; draw.DrawPolygon(points, points.Length, new CCColor4F(1, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1)); text.End(); AddChild(text, 24); }
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);; }
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); }
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); }
void Init() { var gesture = CCEventListenerGesture.Create(); gesture.SetSwipeThreshouldDistance(80); gesture.OnSwipeEnded = (swipe) => { isSwiped = false; switch (swipe) { case CCEventListenerGesture.SwipeDirection.NONE: break; case CCEventListenerGesture.SwipeDirection.UP: case CCEventListenerGesture.SwipeDirection.DOWN: case CCEventListenerGesture.SwipeDirection.LEFT: //ふぉーるするー case CCEventListenerGesture.SwipeDirection.RIGHT: CCLog.Log($"[OreOreLog]:{nameof(TestLayer)}{this.ZOrder}"); var goGame = new CCMenuItemLabel(new CCLabel("ゲームであそぶ", "Arial", 40), _ => { ChangeScene(new Loading(new GameAssetsLoader(new GameAssets()))); var dig = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog; dig.Close(); }); var goTitle = new CCMenuItemLabel(new CCLabel("タイトルにもどる", "Arial", 40), _ => { ChangeScene(new Loading(new TitleAssetsLoader())); var dig = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog; dig.Close(); }); var cancel = new CCMenuItemLabel(new CCLabel("キャンセル", "Arial", 40), _ => { var dig = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog; dig.Close(); RemoveChild(dig); isSwiped = false; }); var sns_share = new CCMenuItemLabel(new CCLabel("ランキングのシェア", "Arial", 40), _ => { var dig = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog; dig.Close(); RemoveChild(dig); void Share(CCLayer layer) { CCRenderTexture rt = new CCRenderTexture(VisibleBoundsWorldspace.Size, VisibleBoundsWorldspace.Size, CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8); rt.BeginWithClear(CCColor4B.Black); layer.Visit(); rt.End(); rt.Sprite.Position = VisibleBoundsWorldspace.Center; CCRenderCommand shareCommand = new CCCustomCommand( () => { using (MemoryStream ms = new MemoryStream()) { //rt.Texture.SaveAsPng(ms, (int)layer.VisibleBoundsWorldspace.Size.Width, (int)layer.VisibleBoundsWorldspace.Size.Height); //ShareControl.ShareImage(ms); rt.SaveToStream(ms, CCImageFormat.Png); var _share = Xamarin.Forms.DependencyService.Get <IShareSNS>(); string text = ""; if (_rankingData.IsRankinCurrentPlayData) { int score = _rankingData.Ranks[_rankingData.RankinIndex].Score; if (_rankingData.RankinIndex == 0) { text = $"わたしのスコア:{score}点" + $"\n" + $"ハイスコア更新しました!"; } else { text = $"わたしのスコア:{score}点" + $"\n" + $"ランキング更新しました!"; } } else { text = "今のランキングです!"; } string hashTag = "#撃ち続けろ"; text = text + "\n" + hashTag; _share.Post(text, ms); } }); Renderer.AddCommand(shareCommand); } Share(this); isSwiped = false; return; }); var menuItems = new[] { goGame, goTitle, sns_share, cancel }; var menu = new ModalMenu(menuItems) { Position = new CCPoint(GlobalGameData.Window_Center_X, GlobalGameData.Window_Center_Y - 30), }; menu.AlignItemsVertically(30); var dialog = new ModalMenuDialog(menu); AddChild(dialog, 1, ModalMenuDialog.TAG); isSwiped = true; break; default: break; } }; AddEventListener(gesture, this.Point.First()); var touch = new CCEventListenerTouchOneByOne(); touch.OnTouchBegan = (_, __) => { foreach (var label in _rankPointsLabel) { if (label.Label.BoundingBoxTransformedToWorld.ContainsPoint(_.Location)) { selectedMenuItem = label; label.Selected = true; return(true); } } return(false); }; touch.OnTouchMoved = (_, __) => { CCMenuItem current = null; foreach (var label in _rankPointsLabel) { if (label.Label.BoundingBoxTransformedToWorld.ContainsPoint(_.Location)) { current = label; break; } } if (current != selectedMenuItem) { if (selectedMenuItem != null) { selectedMenuItem.Selected = false; } if (current != null) { current.Selected = true; } selectedMenuItem = current; } }; touch.OnTouchEnded = /*EventListener_TouchEnded*/ (_, __) => { if (selectedMenuItem != null) { selectedMenuItem.Selected = false; selectedMenuItem.Activate(); } }; AddEventListener(touch, this); if (_rankingData.CurrentPlayData != null) { var currentScoreLabel = new CCLabel($"あなたのスコア:{_rankingData.CurrentPlayData.Score}点", "arial", 20) { Position = new CCPoint(20, GlobalGameData.Window_Height - 20), AnchorPoint = CCPoint.AnchorMiddleLeft }; AddChild(currentScoreLabel); if (_rankingData.IsRankinCurrentPlayData) { var omedetoLabel = new CCLabel("ランクインおめでとう!", "arial", 20) { Position = new CCPoint(380, GlobalGameData.Window_Height - 20) }; AddChild(omedetoLabel); } } systemLabel = new CCLabel("スワイプ:メニューを開く スコアを選ぶ:リプレイ", "arial", 20) { Position = new CCPoint(20, 20), AnchorPoint = CCPoint.AnchorMiddleLeft, Visible = false }; AddChild(systemLabel); }
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; }
/// <summary> /// Render all sprites, execute this method when all objects are added /// </summary> /// <returns></returns> public bool RenderGraphics() { try { var actualPosition = new CCPoint(0, 0); int highestY = 0; foreach (var keyAndDrawNode in _drawNodes) { var drawNode = keyAndDrawNode.Value; //new line if ((actualPosition.X + drawNode.BoundingBox.Size.Width) > RenderTextureMaxWidthAndHeight) { actualPosition.X = 0; actualPosition.Y = highestY; } //remember highest y, to avoid intersection if ((actualPosition.Y + drawNode.BoundingBox.Size.Height) > highestY) { highestY = (int)(actualPosition.Y + drawNode.BoundingBox.Size.Height + 1); } var rectPosition = new CCRect(actualPosition.X, actualPosition.Y, drawNode.BoundingBox.Size.Width, drawNode.BoundingBox.Size.Height); drawNode.Position = new CCPoint(rectPosition.MinX, rectPosition.MinY); _rectsForSprites.Add(keyAndDrawNode.Key, rectPosition); actualPosition.X += (drawNode.BoundingBox.Size.Width + 1); } foreach (var keyAndLabel in _labels) { var label = keyAndLabel.Value; //new line if ((actualPosition.X + label.BoundingBox.Size.Width) > RenderTextureMaxWidthAndHeight) { actualPosition.X = 0; actualPosition.Y = highestY; } //remember highest y, to avoid intersection if ((actualPosition.Y + label.BoundingBox.Size.Height) > highestY) { highestY = (int)(actualPosition.Y + label.BoundingBox.Size.Height + 1); } var rectPosition = new CCRect(actualPosition.X, actualPosition.Y, label.BoundingBox.Size.Width, label.BoundingBox.Size.Height); label.Position = rectPosition.Center; _rectsForSprites.Add(keyAndLabel.Key, rectPosition); actualPosition.X += (label.BoundingBox.Size.Width + 1); } //render the drawn graphic in one big texture _renderTexture = new CCRenderTexture(new CCSize(RenderTextureMaxWidthAndHeight, highestY), new CCSize(RenderTextureMaxWidthAndHeight, highestY)); _renderTexture.Begin(); foreach (var keyAndDrawNode in _drawNodes) { keyAndDrawNode.Value.Visit(); } foreach (var keyAndLabel in _labels) { keyAndLabel.Value.Visit(); } _renderTexture.End(); //mirror all cordinates vertical...nessecary as the texture use another coordinate system Dictionary <object, CCRect> verticalMirrorCoordsDrawNode = new Dictionary <object, CCRect>(); foreach (var keyAndDrawRect in _rectsForSprites) { CCRect spriteRect = new CCRect(keyAndDrawRect.Value.MinX, highestY - keyAndDrawRect.Value.MaxY, keyAndDrawRect.Value.Size.Width, keyAndDrawRect.Value.Size.Height); verticalMirrorCoordsDrawNode.Add(keyAndDrawRect.Key, spriteRect); } _rectsForSprites = verticalMirrorCoordsDrawNode; } catch (Exception e) { Debug.WriteLine(e); return(false); } _successfullyRendered = true; return(true); }
public override void OnEnter() { base.OnEnter(); // create a transparent color layer // in which we are going to add our rendertextures var color = new CCColor4B(0, 0, 0, 0); CCSize size = CCDirector.SharedDirector.WinSize; CCLayerColor layer = new CCLayerColor(color); // create the first render texture for inScene CCRenderTexture inTexture = new CCRenderTexture((int) size.Width, (int) size.Height); if (null == inTexture) { return; } inTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); inTexture.Position = new CCPoint(size.Width / 2, size.Height / 2); inTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); // render inScene to its texturebuffer inTexture.Begin(); m_pInScene.Visit(); inTexture.End(); // create the second render texture for outScene CCRenderTexture outTexture = new CCRenderTexture((int) size.Width, (int) size.Height); outTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); outTexture.Position = new CCPoint(size.Width / 2, size.Height / 2); outTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); // render outScene to its texturebuffer outTexture.Begin(); m_pOutScene.Visit(); outTexture.End(); // create blend functions var blend1 = new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE); // inScene will lay on background and will not be used with alpha var blend2 = CCBlendFunc.NonPremultiplied; // we are going to blend outScene via alpha // set blendfunctions inTexture.Sprite.BlendFunc = blend1; outTexture.Sprite.BlendFunc = blend2; // add render textures to the layer layer.AddChild(inTexture); layer.AddChild(outTexture); // initial opacity: inTexture.Sprite.Opacity = 255; outTexture.Sprite.Opacity = 255; // create the blend action CCAction layerAction = CCSequence.FromActions ( new CCFadeTo (m_fDuration, 0), new CCCallFunc((HideOutShowIn)), new CCCallFunc((Finish)) ); //// run the blend action outTexture.Sprite.RunAction(layerAction); // add the layer (which contains our two rendertextures) to the scene AddChild(layer, 2, kSceneFade); }
protected override void InitialiseScenes() { base.InitialiseScenes(); // create a transparent color layer // in which we are going to add our rendertextures var color = new CCColor4B(0, 0, 0, 0); var bounds = Layer.VisibleBoundsWorldspace; CCRect viewportRect = Viewport.ViewportInPixels; // create the first render texture for inScene CCRenderTexture inTexture = new CCRenderTexture(bounds.Size, viewportRect.Size); if (null == inTexture) { return; } inTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); inTexture.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2); inTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); AddChild(inTexture); // render inScene to its texturebuffer inTexture.Begin(); InSceneNodeContainer.Visit(); inTexture.End(); // create the second render texture for outScene CCRenderTexture outTexture = new CCRenderTexture(bounds.Size, viewportRect.Size); outTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); outTexture.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2); outTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); AddChild(outTexture); // render outScene to its texturebuffer outTexture.Begin(); OutSceneNodeContainer.Visit(); outTexture.End(); // create blend functions var blend1 = new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE); // inScene will lay on background and will not be used with alpha var blend2 = CCBlendFunc.NonPremultiplied; // we are going to blend outScene via alpha inTexture.Sprite.BlendFunc = blend1; outTexture.Sprite.BlendFunc = blend2; inTexture.Sprite.Opacity = 255; outTexture.Sprite.Opacity = 255; CCAction layerAction = new CCSequence ( new CCFadeTo (Duration, 0), new CCCallFunc((Finish)) ); outTexture.Sprite.RunAction(layerAction); InSceneNodeContainer.Visible = false; OutSceneNodeContainer.Visible = false; }
public override void OnEnter() { base.OnEnter(); // create a transparent color layer // in which we are going to add our rendertextures var color = new CCColor4B(0, 0, 0, 0); CCSize size = CCDirector.SharedDirector.WinSize; CCLayerColor layer = new CCLayerColor(color); // create the first render texture for inScene CCRenderTexture inTexture = new CCRenderTexture((int)size.Width, (int)size.Height); if (null == inTexture) { return; } inTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); inTexture.Position = new CCPoint(size.Width / 2, size.Height / 2); inTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); // render inScene to its texturebuffer inTexture.Begin(); m_pInScene.Visit(); inTexture.End(); // create the second render texture for outScene CCRenderTexture outTexture = new CCRenderTexture((int)size.Width, (int)size.Height); outTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); outTexture.Position = new CCPoint(size.Width / 2, size.Height / 2); outTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); // render outScene to its texturebuffer outTexture.Begin(); m_pOutScene.Visit(); outTexture.End(); // create blend functions var blend1 = new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE); // inScene will lay on background and will not be used with alpha var blend2 = new CCBlendFunc(CCMacros.CCDefaultSourceBlending, CCMacros.CCDefaultDestinationBlending); // OGLES.GL_SRC_ALPHA, OGLES.GL_ONE_MINUS_SRC_ALPHA); // we are going to blend outScene via alpha // set blendfunctions inTexture.Sprite.BlendFunc = blend1; outTexture.Sprite.BlendFunc = blend2; // add render textures to the layer layer.AddChild(inTexture); layer.AddChild(outTexture); // initial opacity: inTexture.Sprite.Opacity = 255; outTexture.Sprite.Opacity = 255; // create the blend action CCAction layerAction = CCSequence.FromActions ( new CCFadeTo(m_fDuration, 0), new CCCallFunc((HideOutShowIn)), new CCCallFunc((Finish)) ); //// run the blend action outTexture.Sprite.RunAction(layerAction); // add the layer (which contains our two rendertextures) to the scene AddChild(layer, 2, kSceneFade); }
protected override void InitialiseScenes() { base.InitialiseScenes(); // create a transparent color layer // in which we are going to add our rendertextures var color = new CCColor4B(0, 0, 0, 0); var bounds = Layer.VisibleBoundsWorldspace; CCRect viewportRect = Viewport.ViewportInPixels; // create the first render texture for inScene CCRenderTexture inTexture = new CCRenderTexture(bounds.Size, viewportRect.Size); if (null == inTexture) { return; } inTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); inTexture.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2); inTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); AddChild(inTexture); // render inScene to its texturebuffer inTexture.Begin(); InSceneNodeContainer.Visit(); inTexture.End(); // create the second render texture for outScene CCRenderTexture outTexture = new CCRenderTexture(bounds.Size, viewportRect.Size); outTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); outTexture.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2); outTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); AddChild(outTexture); // render outScene to its texturebuffer outTexture.Begin(); OutSceneNodeContainer.Visit(); outTexture.End(); // create blend functions var blend1 = new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE); // inScene will lay on background and will not be used with alpha var blend2 = CCBlendFunc.NonPremultiplied; // we are going to blend outScene via alpha inTexture.Sprite.BlendFunc = blend1; outTexture.Sprite.BlendFunc = blend2; inTexture.Sprite.Opacity = 255; outTexture.Sprite.Opacity = 255; CCAction layerAction = new CCSequence ( new CCFadeTo(Duration, 0), new CCCallFunc((Finish)) ); outTexture.Sprite.RunAction(layerAction); InSceneNodeContainer.Visible = false; OutSceneNodeContainer.Visible = false; }