void OnTouchesBegan(List <CCTouch> touches, CCEvent touchEvent) { if (touches.Count <= 0) { return; } var touch = touches [0]; var bubbles = (from bubble in visibleBubbles where bubble.ContainsPoint(touch.Location) orderby bubble.Id select bubble).ToList(); if (bubbles.Count == 0) { return; } hitBubble = bubbles [0]; if (hitBubble == null) { return; } hitBubble.Freeze(0); frozenBubbles.Add(hitBubble); lastPoint = touch.Location; line.Clear(); multiplierLabel.Text = string.Empty; }
private void OnTouchesBegan(List <CCTouch> touches, CCEvent touchEvent) { if (touches.Count <= 0) { return; } CCTouch touch = touches[0]; List <Bubble> bubbles = _visibleBubbles.Where(x => x.ContainsPoint(touch.Location)) .OrderBy(x => x.Id).ToList(); if (bubbles.Count == 0) { return; } _hitBubble = bubbles[0]; if (_hitBubble == null) { return; } _hitBubble.Freeze(0); _frozenBubbles.Add(_hitBubble); _lastPoint = touch.Location; _line.Clear(); _multiplierLabel.Text = string.Empty; }
private void TouchCanceled(CCTouch touch, CCEvent e) { this.Position = this.initPosition; drawNode.Clear(); possibleMoves.Clear(); possibleSquares.Clear(); }
private void LengthSlider_ValueChanged(object sender, ValueChangedEventArgs e) { Pendulum.StringLength = e.NewValue; _pendulumRect.Size.Height = -(float)e.NewValue * _scaleFactor; _pendulumString.Clear(); _pendulumString.DrawRect(_pendulumRect); UpdateLabels(); }
/// <summary> /// Draw everything that is supposed to be drawn by the DrawNode /// </summary> private void UpdateDrawNodes() { HighDrawNode.Clear(); LowDrawNode.Clear(); DrawNodeExplosions.Clear(); // draw the projectiles foreach (var drawNodeUser in DrawNodeUsers) { drawNodeUser.UseDrawNodes(HighDrawNode, LowDrawNode); } // draw the clouds foreach (var cloudNode in ExplosionNodes) { cloudNode.UseDrawNodes(DrawNodeExplosions, DrawNodeExplosions); } // draw everything directly related to the aircrafts foreach (var aircraft in ActiveAircrafts) { aircraft.UseDrawNodes(HighDrawNode, LowDrawNode); } foreach (var aircraft in PlayerAircrafts) { aircraft.UseDrawNodes(HighDrawNode, LowDrawNode); } }
internal override void UpdateCamera() { base.UpdateCamera(); // additionally color the background and the planes according to the position of the center of the camera relative to the zones CCPoint camMid = CameraPosition + (CCPoint)CameraSize / 2; float radius = camMid.Length; var bgColor = RadiusToColor(radius, groundNotAir: true); var planeColor = RadiusToColor(radius, groundNotAir: false); // draw the bg lines DrawNode.Clear(); const float bgsize = 600000f; const int lineCount = 200; var bgLineColor = CCColor4B.Lerp(planeColor, CCColor4B.Black, 0.75f); for (int i = -lineCount; i < lineCount; i++) { DrawNode.DrawLine(new CCPoint(i * bgsize / lineCount, -bgsize), new CCPoint(i * bgsize / lineCount, bgsize), 20f, bgLineColor); DrawNode.DrawLine(new CCPoint(-bgsize, i * bgsize / lineCount), new CCPoint(bgsize, i * bgsize / lineCount), 20f, bgLineColor); } // draw the bg color DrawNodeBG.Clear(); DrawNodeBG.DrawRect(new CCRect(-999999999f, -999999999f, 999999999f * 2, 999999999f * 2), bgColor); // now the planes // only color the enemies foreach (var aircraft in ActiveAircrafts) { aircraft.ColorByPlayLayer(planeColor); } }
private void DrawGraphic(CCPoint loc) { drawNode.Clear(); drawNode.DrawRect(backgroundRect, fillColor: CCColor4B.Yellow); curLocRect = new CCRect(loc.X, 0, redBarWidth, redBarHeight); drawNode.DrawRect(curLocRect, fillColor: CCColor4B.Red); }
private void UpdateGraphics() { if (GameCoefficients.ShowCollisionAreas) { debugGrahic.Clear(); const float borderWidth = 4; debugGrahic.DrawSolidCircle( CCPoint.Zero, GameCoefficients.FruitRadius, CCColor4B.Black); debugGrahic.DrawSolidCircle( CCPoint.Zero, GameCoefficients.FruitRadius - borderWidth, fruitColor.ToCCColor()); } if (this.FruitColor == FruitColor.Yellow) { graphic.Texture = CCTextureCache.SharedTextureCache.AddImage("lemon.png"); extraPointsLabel.Color = CCColor3B.Black; extraPointsLabel.PositionY = 0; } else { graphic.Texture = CCTextureCache.SharedTextureCache.AddImage("cherry.png"); extraPointsLabel.Color = CCColor3B.White; extraPointsLabel.PositionY = -8; } }
void UpdateLine() { line.Clear(); var effectiveWidth = Math.Max(0, width); line.DrawLine(CCPoint.Zero, new CCPoint(40, 0), effectiveWidth / 2, new CCColor4F(1, 1, 0, 1)); }
/********************************************************************** *********************************************************************/ public static void ClearGrayArrow() { if (cc_arrow2 != null && cc_arrow2a != null && cc_arrow2b != null) { cc_arrow2.Clear(); cc_arrow2b.Clear(); cc_arrow2a.Clear(); } }
/********************************************************************** *********************************************************************/ public static void ClearRedArrow() { if (cc_arrow1 != null && cc_arrow1a != null && cc_arrow1b != null) { cc_arrow1.Clear(); cc_arrow1b.Clear(); cc_arrow1a.Clear(); } }
protected void RenderTouchPoint() { touchPoint.Clear(); touchPoint.Color = new CCColor3B(_touchColor.R, _touchColor.G, _touchColor.B); touchPoint.Opacity = 255; touchPoint.DrawLine(new CCPoint(0, _touchPoint.Y), new CCPoint(ContentSize.Width, _touchPoint.Y), 5); touchPoint.DrawLine(new CCPoint(_touchPoint.X, 0), new CCPoint(_touchPoint.X, ContentSize.Height), 5); touchPoint.DrawRect(_touchPoint, 30); }
private void UpdateGraphics() { if (GameCoefficients.ShowCollisionAreas) { graphic.Clear(); graphic.DrawRect( new CCRect(0, GameCoefficients.BinHeight - collisionHeight, width, collisionHeight), fillColor: fruitColor.ToCCColor()); } }
bool OnTouchBegan(CCTouch touch, CCEvent touchEvent) { var layer = tileMap.LayerNamed("grass"); var location = layer.WorldToParentspace(touch.Location); var tileCoordinates = layer.ClosestTileCoordAtNodePosition(location); var gid = layer.TileGIDAndFlags(tileCoordinates); if (gid.Gid != 1) // we only want the green grass { return(false); } // Convert the tile coordinates position to world coordinates for // our outline drawing var world = layer.TilePosition(tileCoordinates); // Calculate our width and height of the tile CCSize texToContentScaling = CCTileMapLayer.DefaultTexelToContentSizeRatios; float width = layer.TileTexelSize.Width * texToContentScaling.Width; float height = layer.TileTexelSize.Height * texToContentScaling.Height; var rect = new CCRect(world.X, world.Y, width, height); drawNode.Clear(); drawNode.Color = CCColor3B.Magenta; drawNode.Opacity = 255; var center = rect.Center; var right = center; right.X += width / 2; var top = center; top.Y += height / 2; var left = right; left.X -= width; var bottom = center; bottom.Y -= height / 2; // Hightlight our iso tile drawNode.DrawPolygon(new CCPoint[] { right, top, left, bottom }, 4, CCColor4B.Transparent, 1, new CCColor4F(CCColor4B.Magenta)); return(true); }
public override void Update(float dt) { _clearTTL -= dt; if (_clearTTL > 0 && _clearTTL < 0.3f) { IsColorModifiedByOpacity = true; IsOpacityCascaded = true; var diff = (_clearTTL / 0.3f) * 255; _recognizerCanvasNode.IsColorModifiedByOpacity = true; _recognizerCanvasNode.Opacity = (byte)(int)diff; } if (_clearTTL < 0) { _buffer.Clear(); _recognizerCanvasNode.Clear(); _canvasNode.Clear(); } base.Update(dt); }
void ClearImage(object sender) { canvasNode.Clear(); RemoveChildByTag(spriteTag); Color = new CCColor3B((byte)(CCMacros.CCRandomBetween0And1() * 255), (byte)(CCMacros.CCRandomBetween0And1() * 255), (byte)(CCMacros.CCRandomBetween0And1() * 255)); while (Opacity < 127) { Opacity = (byte)(CCMacros.CCRandomBetween0And1() * 255); } }
public void MakePlayGraphic(CCDrawNode drawNode) { drawNode.Clear(); const float playButtonHeight = 40; var verts = new CCPoint[] { new CCPoint(0, 0), new CCPoint(0, playButtonHeight), new CCPoint(22, playButtonHeight / 2.0f) }; drawNode.DrawPolygon(verts, 3, CCColor4B.Green, 1, CCColor4B.White); }
protected override void AddedToScene() { base.AddedToScene(); CCTileMapObjectGroup group = tileMap.ObjectGroupNamed("Object Layer 1"); drawNode.Color = CCColor3B.Magenta; drawNode.Opacity = 255; drawNode.Clear(); foreach (var dict in group.Objects) { int x = int.Parse(dict["x"]); int y = int.Parse(dict["y"]); ; drawNode.DrawDot(new CCPoint(x, y), 10.0f, new CCColor4F(CCColor4B.Magenta)); } }
private void ReDrawScene() { _car1DrawNode.Clear(); _car2DrawNode.Clear(); _car1DrawNode.PositionX = (float)_viewResolution.Width / 5; _car1DrawNode.PositionY = 0; _car2DrawNode.PositionX = 4 * (float)_viewResolution.Width / 5; _car2DrawNode.PositionY = 0; _car1DrawNode.DrawRect(_car1Rect); _car2DrawNode.DrawRect(_car2Rect); _car1.Position = new Vector(_car1DrawNode.Position.X, _car1DrawNode.Position.Y); _car2.Position = new Vector(_car2DrawNode.Position.X, _car2DrawNode.Position.Y); }
private void CreateDebugGraphic() { var debugGrahic = new CCDrawNode(); debugGrahic.Clear(); const float borderWidth = 4; debugGrahic.DrawSolidCircle( CCPoint.Zero, GameCoefficients.FruitRadius, CCColor4B.Black); debugGrahic.DrawSolidCircle( CCPoint.Zero, GameCoefficients.FruitRadius - borderWidth, FruitColor.ToCCColor()); AddChild(debugGrahic); }
private void RedrawGameScene() { _wheel.Clear(); _layer.Children?.Clear(); _layer.AddChild(_wheel); float lineWidth = (float)_centre.Mass / 10; if (lineWidth < 1f) { lineWidth = 1f; } _wheel.DrawLine(new CCPoint(-20, -20), new CCPoint(20, 20), lineWidth: lineWidth, CCColor4B.White); _wheel.DrawLine(new CCPoint(-20, 20), new CCPoint(20, -20), lineWidth: lineWidth, CCColor4B.White); _wheel.PositionX = (float)_viewResolution.Width / 2; _wheel.PositionY = (float)_viewResolution.Height / 2; }
/********************************************************************** *********************************************************************/ static void DrawExpectedSeqnum() { if (cc_expSeqnum != null) { cc_expSeqnum.Clear(); } float a = 29 - expectedSeqnum; float yMin = 7 + (a - 1) * 65; expSeqnum = new CCRect(315, yMin, 50, 65); cc_expSeqnum = new CCDrawNode(); cc_expSeqnum.DrawRect( expSeqnum, fillColor: CCColor4B.Transparent, borderWidth: 1, borderColor: CCColor4B.Blue); layer.AddChild(cc_expSeqnum); }
public static void RedrawMe(this CCDrawNode node) { node.Clear(); void draw(CCNode childNode) { if (childNode is DrawableNode) { (childNode as DrawableNode).Draw(node); } foreach (var childItem in childNode.Children) { draw(childItem); } } foreach (var child in node.Children) { draw(child); } }
/********************************************************************** *********************************************************************/ //window on the right static void DrawWindowRight(float pos) { if (cc_window2 != null) { cc_window2.Clear(); } float a = 29 - pos; float yMin = 7 + (a - windowSize) * 65; float height = windowSize * 65; window2 = new CCRect(315, yMin, 50, height); cc_window2 = new CCDrawNode(); cc_window2.DrawRect( window2, fillColor: CCColor4B.Transparent, borderWidth: 1, borderColor: CCColor4B.Blue); layer.AddChild(cc_window2); }
/********************************************************************** *********************************************************************/ //window on the left static void DrawWindowLeft(float pos) { //delete existing window if (cc_window != null) { cc_window.Clear(); } float a = 29 - pos; float yMin = 7 + (a - windowSize) * 65; // start of the coordinate system is at the lower left. But We start at the upper left float height = windowSize * 65; window = new CCRect(35, yMin, 50, height);//CCRect(x,y,legth,heigth) cc_window = new CCDrawNode(); cc_window.DrawRect( window, fillColor: CCColor4B.Transparent, borderWidth: 1, borderColor: CCColor4B.Blue); //add box to layer layer.AddChild(cc_window); }
/// <summary> /// Since layer (and scene) opacity is broken this implements a workaround for a creating a fading transition. /// </summary> /// <param name="guiLayer1"></param> /// <param name="guiLayer2"></param> public static void TransitionFadingFromTo(MyLayer guiLayer1, MyLayer guiLayer2, MyLayer layer1, MyLayer layer2, float duration) { var fadeNode = new CCDrawNode(); var bigRect = new CCRect(-100000000, -100000000, 1000000000, 1000000000); fadeNode.BlendFunc = CCBlendFunc.NonPremultiplied; fadeNode.DrawRect(bigRect, CCColor4B.Transparent); guiLayer1.AddChild(fadeNode, int.MaxValue); void FadeIn(float prog, float du) { fadeNode.Clear(); fadeNode.DrawRect(bigRect, new CCColor4B(0f, 0f, 0f, prog)); } void FadeOut(float prog, float du) { fadeNode.Clear(); fadeNode.DrawRect(bigRect, new CCColor4B(0f, 0f, 0f, 1 - prog)); } fadeNode.AddAction(new CCSequence(new CCCallFiniteTimeFunc(duration / 2, FadeIn), Constants.oS != Constants.OS.WINDOWS ? new CCCallFunc(() => { var director = layer1.Director; var scene = director.RunningScene; var gv = scene.GameView; fadeNode.RemoveFromParent(); // the following are attempts at fixing the memory leak (which all mostly failed) // created by the fact that layers are not released for some reason layer1.RemoveAllListeners(); guiLayer1.RemoveAllListeners(); layer1.RemoveEventListeners(); guiLayer1.RemoveEventListeners(); layer1.RemoveFromParent(); guiLayer1.RemoveFromParent(); layer1.Clear(); guiLayer1.Clear(); layer1.Cleanup(); guiLayer1.Cleanup(); layer1.Dispose(); guiLayer1.Dispose(); scene.RemoveAllListeners(); scene.RemoveAllChildren(); scene.StopAllActions(); scene.UnscheduleAll(); scene.RemoveFromParent(); scene.Cleanup(); scene.Dispose(); var scene2 = new CCScene(gv); scene2.AddLayer(guiLayer2); scene2.AddLayer(layer2, int.MinValue); guiLayer2.AddChild(fadeNode, int.MaxValue); director.ResetSceneStack(); director.ReplaceScene(scene2); fadeNode.AddAction(new CCSequence(new CCCallFiniteTimeFunc(duration / 2, FadeOut), new CCRemoveSelf())); }) : new CCCallFunc(() => { // this part is how it needs to be done in order to work on the old CocosSharp version //where GameView.Get fails (i.e. the DX-version) layer1.RemoveAllListeners(); guiLayer1.RemoveAllListeners(); var parent = layer1.Parent; layer1.RemoveFromParent(); guiLayer1.RemoveFromParent(); parent.AddChild(guiLayer2); parent.AddChild(layer2, int.MinValue); fadeNode.RemoveFromParent(); guiLayer2.AddChild(fadeNode, int.MaxValue); fadeNode.AddAction(new CCSequence(new CCCallFiniteTimeFunc(duration / 2, FadeOut), new CCRemoveSelf())); }) )); }
internal void UpdateDrawNode(bool useMultiplGoal = false) { if (MyDrawNode == null) { return; } MyDrawNode.Clear(); if (LootboxCount != 0) { // visualize lootbar-progress const float GROWTH_FACTOR = 1.3f; const float BORDER_WIDTH = 4f; CCColor4B white = new CCColor4B(1f, 1f, 1f, DrawNodeAlpha); CCColor4B bright = new CCColor4B(1f, 1f, 1f, DrawNodeAlpha); CCRect progressRect = new CCRect(-(ContentSize.Width * GROWTH_FACTOR) / 2, -(ContentSize.Height * GROWTH_FACTOR) / 2, ContentSize.Width * GROWTH_FACTOR, ContentSize.Height * GROWTH_FACTOR); // draw the progress bar var progressPoly = new List <CCPoint> { CCPoint.Zero, new CCPoint(0, (ContentSize.Height * GROWTH_FACTOR) / 2) }; if (LootboxProgress >= 0.125f) { progressPoly.Add(progressRect.UpperRight); } else { progressPoly.Add(new CCPoint(LootboxProgress / 0.125f * progressRect.MaxX, progressRect.MaxY)); goto done; } if (LootboxProgress >= 0.375f) { progressPoly.Add(new CCPoint(progressRect.MaxX, progressRect.MinY)); } else { progressPoly.Add(new CCPoint(progressRect.MaxX, progressRect.MaxY - progressRect.Size.Height * ((LootboxProgress - 0.125f) * 4))); goto done; } if (LootboxProgress >= 0.625f) { progressPoly.Add(new CCPoint(progressRect.MinX, progressRect.MinY)); } else { progressPoly.Add(new CCPoint(progressRect.MaxX - progressRect.Size.Width * ((LootboxProgress - 0.375f) * 4), progressRect.MinY)); goto done; } if (LootboxProgress >= 0.875f) { progressPoly.Add(new CCPoint(progressRect.MinX, progressRect.MaxY)); } else { progressPoly.Add(new CCPoint(progressRect.MinX, progressRect.MinY + progressRect.Size.Height * ((LootboxProgress - 0.625f) * 4))); goto done; } if (LootboxProgress > 0.875f) { progressPoly.Add(new CCPoint(progressRect.MinX + progressRect.Size.Width * (LootboxProgress - 0.875f) * 2, progressRect.MaxY)); } done: var progressPolyPoints = progressPoly.ToArray(); MyDrawNode.DrawPolygon(progressPolyPoints, progressPolyPoints.Length, bright, 0f, CCColor4B.Transparent); // draw the progress bar border MyDrawNode.DrawRect(progressRect, CCColor4B.Transparent, BORDER_WIDTH, white); } // additionally color the button depending on the multiplier progress int multiplier = 1; float progress = 0; if (useMultiplGoal) { multiplier = (int)CurrentMathChallengeNode.MultiplGoal; progress = CurrentMathChallengeNode.MathChallenge.MultiplProgress; } else { multiplier = CurrentMathChallengeNode.Multiplier; progress = CurrentMathChallengeNode.MultiplProgressVisible; } var lastColor = MathChallengeNode.MultiplierBarColor(multiplier - 1); var nextColor = MathChallengeNode.MultiplierBarColor(multiplier); var currentColor = multiplier <= 5 ? CCColor4B.Lerp(lastColor, nextColor, progress) : lastColor; var darkenedColor = CCColor4B.Lerp(currentColor, CCColor4B.Black, 0.25f); darkenedColor.A = (byte)(DrawNodeAlpha * byte.MaxValue); MyDrawNode.DrawRect(new CCRect(-(ContentSize.Width) / 2, -(ContentSize.Height) / 2, ContentSize.Width, ContentSize.Height), darkenedColor); }
protected void UpdateHealthBar() { drawNode.Clear(); CreateGraphic(); }
protected void UpdateSkeletonGeometry() { skeletonGeometry.ClearInstances(); //defaultBlendState = PremultipliedAlpha ? BlendState.AlphaBlend : BlendState.NonPremultiplied; float[] vertices = this.vertices; List <Slot> drawOrder = Skeleton.DrawOrder; float x = Skeleton.X, y = Skeleton.Y; CCColor3B color3b = Color; float skeletonR = color3b.R / 255f; float skeletonG = color3b.G / 255f; float skeletonB = color3b.B / 255f; float skeletonA = Opacity / 255f; for (int i = 0, n = drawOrder.Count; i < n; i++) { Slot slot = drawOrder[i]; Attachment attachment = slot.Attachment; if (attachment is RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment)attachment; //BlendState blend = slot.Data.AdditiveBlending ? BlendState.Additive : defaultBlendState; var item = skeletonGeometry.CreateGeometryInstance(4, 6); //item.InstanceAttributes.BlendState = blend; //item.InstanceAttributes.AdditionalTransform = AffineWorldTransform; item.GeometryPacket.Indicies = quadTriangles; var itemVertices = item.GeometryPacket.Vertices; AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject; item.GeometryPacket.Texture = (CCTexture2D)region.page.rendererObject; CCColor4B color; float a = skeletonA * slot.A * regionAttachment.A; if (PremultipliedAlpha) { color = new CCColor4B( skeletonR * slot.R * regionAttachment.R * a, skeletonG * slot.G * regionAttachment.G * a, skeletonB * slot.B * regionAttachment.B * a, a); } else { color = new CCColor4B( skeletonR * slot.R * regionAttachment.R, skeletonG * slot.G * regionAttachment.G, skeletonB * slot.B * regionAttachment.B, a); } itemVertices[TL].Colors = color; itemVertices[BL].Colors = color; itemVertices[BR].Colors = color; itemVertices[TR].Colors = color; regionAttachment.ComputeWorldVertices(x, y, slot.Bone, vertices); itemVertices[TL].Vertices.X = vertices[RegionAttachment.X1]; itemVertices[TL].Vertices.Y = vertices[RegionAttachment.Y1]; itemVertices[TL].Vertices.Z = 0; itemVertices[BL].Vertices.X = vertices[RegionAttachment.X2]; itemVertices[BL].Vertices.Y = vertices[RegionAttachment.Y2]; itemVertices[BL].Vertices.Z = 0; itemVertices[BR].Vertices.X = vertices[RegionAttachment.X3]; itemVertices[BR].Vertices.Y = vertices[RegionAttachment.Y3]; itemVertices[BR].Vertices.Z = 0; itemVertices[TR].Vertices.X = vertices[RegionAttachment.X4]; itemVertices[TR].Vertices.Y = vertices[RegionAttachment.Y4]; itemVertices[TR].Vertices.Z = 0; float[] uvs = regionAttachment.UVs; itemVertices[TL].TexCoords.U = uvs[RegionAttachment.X1]; itemVertices[TL].TexCoords.V = uvs[RegionAttachment.Y1]; itemVertices[BL].TexCoords.U = uvs[RegionAttachment.X2]; itemVertices[BL].TexCoords.V = uvs[RegionAttachment.Y2]; itemVertices[BR].TexCoords.U = uvs[RegionAttachment.X3]; itemVertices[BR].TexCoords.V = uvs[RegionAttachment.Y3]; itemVertices[TR].TexCoords.U = uvs[RegionAttachment.X4]; itemVertices[TR].TexCoords.V = uvs[RegionAttachment.Y4]; } else if (attachment is MeshAttachment) { MeshAttachment mesh = (MeshAttachment)attachment; int vertexCount = mesh.Vertices.Length; if (vertices.Length < vertexCount) { vertices = new float[vertexCount]; } mesh.ComputeWorldVertices(x, y, slot, vertices); int[] triangles = mesh.Triangles; var item = skeletonGeometry.CreateGeometryInstance(vertexCount, triangles.Length); //item.InstanceAttributes.AdditionalTransform = AffineWorldTransform; item.GeometryPacket.Indicies = triangles; AtlasRegion region = (AtlasRegion)mesh.RendererObject; item.GeometryPacket.Texture = (CCTexture2D)region.page.rendererObject; CCColor4B color; float a = skeletonA * slot.A * mesh.A; if (PremultipliedAlpha) { color = new CCColor4B( skeletonR * slot.R * mesh.R * a, skeletonG * slot.G * mesh.G * a, skeletonB * slot.B * mesh.B * a, a); } else { color = new CCColor4B( skeletonR * slot.R * mesh.R, skeletonG * slot.G * mesh.G, skeletonB * slot.B * mesh.B, a); } float[] uvs = mesh.UVs; var itemVertices = item.GeometryPacket.Vertices; for (int ii = 0, v = 0; v < vertexCount; ii++, v += 2) { itemVertices[ii].Colors = color; itemVertices[ii].Vertices.X = vertices[v]; itemVertices[ii].Vertices.Y = vertices[v + 1]; itemVertices[ii].Vertices.Z = 0; itemVertices[ii].TexCoords.U = uvs[v]; itemVertices[ii].TexCoords.V = uvs[v + 1]; } } else if (attachment is SkinnedMeshAttachment) { SkinnedMeshAttachment mesh = (SkinnedMeshAttachment)attachment; int vertexCount = mesh.UVs.Length; if (vertices.Length < vertexCount) { vertices = new float[vertexCount]; } mesh.ComputeWorldVertices(x, y, slot, vertices); int[] triangles = mesh.Triangles; var item = skeletonGeometry.CreateGeometryInstance(vertexCount, triangles.Length); item.GeometryPacket.Indicies = triangles; //item.InstanceAttributes.AdditionalTransform = AffineWorldTransform; AtlasRegion region = (AtlasRegion)mesh.RendererObject; item.GeometryPacket.Texture = (CCTexture2D)region.page.rendererObject; CCColor4B color; float a = skeletonA * slot.A * mesh.A; if (PremultipliedAlpha) { color = new CCColor4B( skeletonR * slot.R * mesh.R * a, skeletonG * slot.G * mesh.G * a, skeletonB * slot.B * mesh.B * a, a); } else { color = new CCColor4B( skeletonR * slot.R * mesh.R, skeletonG * slot.G * mesh.G, skeletonB * slot.B * mesh.B, a); } float[] uvs = mesh.UVs; var itemVertices = item.GeometryPacket.Vertices; for (int ii = 0, v = 0; v < vertexCount; ii++, v += 2) { itemVertices[ii].Colors = color; itemVertices[ii].Vertices.X = vertices[v]; itemVertices[ii].Vertices.Y = vertices[v + 1]; itemVertices[ii].Vertices.Z = 0; itemVertices[ii].TexCoords.U = uvs[v]; itemVertices[ii].TexCoords.V = uvs[v + 1]; } } } debugger.Clear(); if (DebugBones || DebugSlots) { if (DebugSlots) { for (int i = 0; i < Skeleton.Slots.Count; ++i) { var slot = Skeleton.Slots[i]; if (slot.Attachment == null) { continue; } var verticesCount = 0; var worldVertices = new float[1000]; // Max number of vertices per mesh. if (slot.Attachment is RegionAttachment) { var attachment = (RegionAttachment)slot.Attachment; attachment.ComputeWorldVertices(Skeleton.X, Skeleton.Y, slot.bone, worldVertices); verticesCount = 8; } else if (slot.Attachment is MeshAttachment) { var mesh = (MeshAttachment)slot.Attachment; mesh.ComputeWorldVertices(Skeleton.X, Skeleton.Y, slot, worldVertices); verticesCount = mesh.Vertices.Length; } else if (slot.Attachment is SkinnedMeshAttachment) { var mesh = (SkinnedMeshAttachment)slot.Attachment; mesh.ComputeWorldVertices(Skeleton.X, Skeleton.Y, slot, worldVertices); verticesCount = mesh.UVs.Length; } else { continue; } CCPoint[] slotVertices = new CCPoint[verticesCount / 2]; for (int ii = 0, si = 0; ii < verticesCount; ii += 2, si++) { slotVertices[si].X = worldVertices[ii] * ScaleX; slotVertices[si].Y = worldVertices[ii + 1] * ScaleY; } debugger.DrawPolygon(slotVertices, verticesCount / 2, CCColor4B.Transparent, 1, DebugSlotColor); } } if (DebugBones) { // Bone lengths. for (int i = 0; i < Skeleton.Bones.Count; i++) { Bone bone = Skeleton.Bones[i]; x = bone.Data.Length * bone.M00 + bone.WorldX; y = bone.Data.Length * bone.M10 + bone.WorldY; debugger.DrawLine(new CCPoint(bone.WorldX, bone.WorldY), new CCPoint(x, y), 1, DebugJointColor); } // Bone origins. for (int i = 0; i < Skeleton.Bones.Count; i++) { Bone bone = Skeleton.Bones[i]; debugger.DrawDot(new CCPoint(bone.WorldX, bone.WorldY), 3, DebugBoneColor); } } } }
private void DrawTargetLine() { targetLine.Clear(); targetLine.DrawLine(this.Position, this.attackTarget.Position, CCColor4B.Green, CCLineCap.Square); }