public override void Update(float dt) { elapsed += dt; if (elapsed > 1f) { elapsed = 0f; // CCLabelBMFont if (label1 != null) { RemoveChild(label1); } CCNode node = new CCNode(); CCSize s = CCDirector.SharedDirector.WinSize; float x = s.Width * CCMacros.CCRandomBetween0And1(); float y = s.Height * CCMacros.CCRandomBetween0And1(); label1 = new CCLabelBMFont(string.Format("{0:N2},{1:N2} @ Mem Leak Ctor", x, y), "fonts/konqa32.fnt", 255f, CCTextAlignment.Right, CCPoint.Zero); node.AddChild(label1); label1.Position = new CCPoint(x, y); AddChild(node); label1 = node; // Start - test case for memory leak mentioned at https://cocos2dxna.codeplex.com/discussions/544032 node.Scale = 2f; //--> This action causes the leak CCScaleTo acScale = new CCScaleTo(0.1f, 1); CCDelayTime acShow = new CCDelayTime(0.1f); CCSplitRows acFadeOut = new CCSplitRows(0.1f, 20); CCRemoveSelf acRemove = new CCRemoveSelf(true); CCSequence seq = new CCSequence(acScale, acShow, acFadeOut, acRemove); node.RunAction(seq); } }
private void MyGamePadTriggerUpdate(float leftTriggerStrength, float rightTriggerStrength, PlayerIndex player) { CCNode node = GetChildByTag(kTagTileMap); if (node != null) { node.Rotation += rightTriggerStrength * CCMacros.CCDegreesToRadians(15f) - leftTriggerStrength * CCMacros.CCDegreesToRadians(15f); } }
public override void Update(float dt) { // reset seed //srandom(0); if (bTested) { return; } // 15 percent int totalToAdd = (int)(currentQuantityOfNodes * 0.15f); if (totalToAdd > 0) { List <CCSprite> sprites = new List <CCSprite>(totalToAdd); //int zs = new int[totalToAdd]; int[] zs = new int[totalToAdd]; // Don't include the sprite creation time and random as part of the profiling long lStart = DateTime.Now.Ticks; for (int i = 0; i < totalToAdd; i++) { CCSprite pSprite = new CCSprite(batchNode.Texture, new CCRect(0, 0, 32, 32)); sprites.Add(pSprite); zs[i] = (int)(CCMacros.CCRandomBetweenNegative1And1() * 50); } long ldiff = DateTime.Now.Ticks - lStart; CCLog.Log("Add Sprite took {0} sec", (new TimeSpan(ldiff)).TotalSeconds); // add them with random Z (very important!) //#if CC_ENABLE_PROFILERS // CCProfilingBeginTimingBlock(_profilingTimer); //#endif lStart = DateTime.Now.Ticks; for (int i = 0; i < totalToAdd; i++) { batchNode.AddChild((CCNode)(sprites[i]), zs[i], PerformanceNodeChildrenTest.kTagBase + i); } ldiff = DateTime.Now.Ticks - lStart; CCLog.Log("Add Child to Batch took {0} sec", (new TimeSpan(ldiff)).TotalSeconds); //#if CC_ENABLE_PROFILERS // CCProfilingEndTimingBlock(_profilingTimer); //#endif // remove them lStart = DateTime.Now.Ticks; for (int i = 0; i < totalToAdd; i++) { batchNode.RemoveChildByTag(PerformanceNodeChildrenTest.kTagBase + i, true); } ldiff = DateTime.Now.Ticks - lStart; CCLog.Log("Remove Child took {0} sec", (new TimeSpan(ldiff)).TotalSeconds); } bTested = true; }
protected override void AddedToScene() { base.AddedToScene(); var s = Layer.VisibleBoundsWorldspace.Size; for (int i = 0; i < 100; i++) { var p = new CCPoint(CCMacros.CCRandomBetween0And1() * s.Width, CCMacros.CCRandomBetween0And1() * s.Height); this[i + 100].Position = p; } }
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 override void Update(float dt) { if (bDone) { return; } //srandom(0); // 15 percent int totalToAdd = (int)(currentQuantityOfNodes * 0.15f); if (totalToAdd > 0) { List <CCSprite> sprites = new List <CCSprite>(); // Don't include the sprite creation time as part of the profiling StartTimer(); for (int i = 0; i < totalToAdd; i++) { CCSprite pSprite = new CCSprite(batchNode.Texture, new CCRect(0, 0, 32, 32)); sprites.Add(pSprite); } EndTimer("Add " + totalToAdd + " sprites"); // add them with random Z (very important!) StartTimer(); for (int i = 0; i < totalToAdd; i++) { batchNode.AddChild((CCNode)(sprites[i]), (int)(CCMacros.CCRandomBetweenNegative1And1() * 50), PerformanceNodeChildrenTest.kTagBase + i); } EndTimer("Add sprites to a batch node"); // remove them //#if CC_ENABLE_PROFILERS // CCProfilingBeginTimingBlock(_profilingTimer); //#endif StartTimer(); for (int i = 0; i < totalToAdd; i++) { batchNode.RemoveChildByTag(PerformanceNodeChildrenTest.kTagBase + i, true); } EndTimer("Remove children by tag from the batch node"); //#if CC_ENABLE_PROFILERS // CCProfilingEndTimingBlock(_profilingTimer); //#endif } bDone = true; }
public void UpdateSprite() { if (PhysicsBody == null) { return; } b2Vec2 pos = PhysicsBody.Position; float x = pos.x * Box2DTestLayer.PTM_RATIO; float y = pos.y * Box2DTestLayer.PTM_RATIO; Position = new CCPoint(x, y); Rotation = -CCMacros.CCRadiansToDegrees(PhysicsBody.Angle); }
public override void Update(float dt) { //srandom(0); // 15 percent int totalToAdd = (int)(currentQuantityOfNodes * 0.15f); if (totalToAdd > 0) { List <CCSprite> sprites = new List <CCSprite>(); // Don't include the sprite creation time as part of the profiling for (int i = 0; i < totalToAdd; i++) { CCSprite pSprite = new CCSprite(batchNode.Texture, new CCRect(0, 0, 32, 32)); sprites.Add(pSprite); } // add them with random Z (very important!) for (int i = 0; i < totalToAdd; i++) { batchNode.AddChild((CCNode)(sprites[i]), (int)(CCMacros.CCRandomBetweenNegative1And1() * 50), PerformanceNodeChildrenTest.kTagBase + i); } // [batchNode sortAllChildren]; // reorder them //#if CC_ENABLE_PROFILERS // CCProfilingBeginTimingBlock(_profilingTimer); //#endif for (int i = 0; i < totalToAdd; i++) { CCNode node = (CCNode)(batchNode.Children[i]); batchNode.ReorderChild(node, (int)(CCMacros.CCRandomBetweenNegative1And1() * 50)); } //#if CC_ENABLE_PROFILERS // CCProfilingEndTimingBlock(_profilingTimer); //#endif // remove them for (int i = 0; i < totalToAdd; i++) { batchNode.RemoveChildByTag(PerformanceNodeChildrenTest.kTagBase + i, true); } } }
public override void TouchEnded(CCTouch touch) { base.TouchEnded(touch); CCLightning node = (CCLightning)GetChildByTag(55); node.AddBolt(new CCLightningBolt() { BoltColor = CCLightning.LightningBlue, BoltGlowColor = CCLightning.LightningBlue, Start = CCDirector.SharedDirector.WinSize.Center, End = ConvertToNodeSpace(touch.Location), StrikeTime = (2f * CCMacros.CCRandomBetween0And1()), FadeTime = 0.15f, Width = .5f }); }
protected override void AddedToScene() { base.AddedToScene(); var s = VisibleBoundsWorldspace.Size; var parent = new CCNode(); parent.Position = new CCPoint(0, 0); AddChild(parent); for (int i = 0; i < 10000 / 3.9; ++i) { var sprite = new CCSprite("Images/grossini_dance_01.png"); sprite.Scale = 0.1f; sprite.Position = new CCPoint(CCMacros.CCRandomBetween0And1() * s.Width, CCMacros.CCRandomBetween0And1() * s.Height); parent.AddChild(sprite); } }
public AtlasFastBitmap() { // Upper Label for (int i = 0; i < 100; i++) { //char str[6] = {0}; string str; //sprintf(str, "-%d-", i); str = string.Format("-{0}-", i); CCLabelBMFont label = new CCLabelBMFont(str, "fonts/bitmapFontTest.fnt"); AddChild(label); CCSize s = CCDirector.SharedDirector.WinSize; CCPoint p = new CCPoint(CCMacros.CCRandomBetween0And1() * s.Width, CCMacros.CCRandomBetween0And1() * s.Height); label.Position = p; label.AnchorPoint = new CCPoint(0.5f, 0.5f); } }
public override void Update(float dt) { elapsed += dt; if (elapsed > 0.5f) { elapsed = 0f; // CCLabelBMFont if (label1 != null) { RemoveChild(label1); } CCSize s = CCDirector.SharedDirector.WinSize; float x = s.Width * CCMacros.CCRandomBetween0And1(); float y = s.Height * CCMacros.CCRandomBetween0And1(); label1 = new CCLabelBMFont(string.Format("{0:N2},{1:N2} @ MEMORY LEAK", x, y), "fonts/konqa32.fnt"); AddChild(label1); label1.Position = new CCPoint(x, y); } }
public override void TouchesBegan(List <CCTouch> touches) { foreach (CCTouch t in touches) { // ask director the the window size CCSize size = CCDirector.SharedDirector.WinSize; CCPoint center = new CCPoint(size.Width / 2, size.Height / 2); CCPoint end = t.Location; float fadeTime = CCMacros.CCRandomBetween0And1() * 5f; CCLightningStreak s = new CCLightningStreak(center, end, fadeTime, 15f, 4.0f, new CCColor3B(0, 0, 255), TestResource.s_fire); s.Duration = .5f; AddChild(s); var target = new CCParticleSun(); target.Scale = 0.2f; target.Position = end; AddChild(target); target.RunAction(new CCSequence(new CCFadeOut(fadeTime), new CCRemoveSelf())); } }
public void addNewSpriteWithCoords(CCPoint p) { int idx = (int)(CCMacros.CCRandomBetween0And1() * 1400.0f / 100.0f); int x = (idx % 5) * 85; int y = (idx / 5) * 121; CCSprite sprite = new CCSprite("Images/grossini_dance_atlas", new CCRect(x, y, 85, 121)); AddChild(sprite); sprite.Position = p; CCActionInterval action; float random = CCMacros.CCRandomBetween0And1(); if (random < 0.20) { action = new CCScaleBy(3, 2); } else if (random < 0.40) { action = new CCRotateBy(3, 360); } else if (random < 0.60) { action = new CCBlink(1, 3); } else if (random < 0.8) { action = new CCTintBy(2, 0, -255, -255); } else { action = new CCFadeOut(2); } object obj = action.Reverse(); CCActionInterval action_back = (CCActionInterval)action.Reverse(); CCActionInterval seq = (CCActionInterval)(new CCSequence(action, action_back)); sprite.RunAction(new CCRepeatForever(seq)); }
public override void Update(float dt) { elapsed += dt; if (elapsed > 0.5f) { elapsed = 0f; // CCLabelBMFont if (label1 != null) { RemoveChild(label1); } CCNode node = new CCNode(); CCSize s = CCDirector.SharedDirector.WinSize; float x = s.Width * CCMacros.CCRandomBetween0And1(); float y = s.Height * CCMacros.CCRandomBetween0And1(); label1 = new CCLabelBMFont(string.Format("{0:N2},{1:N2} @ Mem Leak Ctor", x, y), "fonts/konqa32.fnt", 255f, CCTextAlignment.Right, CCPoint.Zero); node.AddChild(label1); label1.Position = new CCPoint(x, y); AddChild(node); label1 = node; } }
public ParallaxScrollTest() { CCSize screen = CCDirector.SharedDirector.WinSize; parallax = new CCParallaxScrollNode(); CCSprite land1 = new CCSprite("Images/land_green"); CCSprite land2 = new CCSprite("Images/land_green"); parallax.AddInfiniteScrollXWithZ(0, new CCPoint(0.5f, 0.2f), CCPoint.Zero, new CCSprite[] { land1, land2 }); CCSprite land3 = new CCSprite("Images/land_grey"); CCSprite land4 = new CCSprite("Images/land_grey"); parallax.AddInfiniteScrollXWithZ(-2, new CCPoint(0.05f, 0.2f), new CCPoint(0f, 60f), new CCSprite[] { land3, land4 }); CCSprite clouds1 = new CCSprite("Images/clouds"); CCSprite clouds2 = new CCSprite("Images/clouds"); parallax.AddInfiniteScrollXWithZ(1, new CCPoint(0.1f, 0.1f), new CCPoint(0f, screen.Height - clouds1.ContentSize.Height), new CCSprite[] { clouds1, clouds2 }); for (int i = 0; i < 10; i++) { CCSprite mountain = new CCSprite("Images/mountain_grey"); CCPoint pos = new CCPoint(CCMacros.CCRandomBetween0And1() * land1.ContentSize.Width * 2f, (0.1f + 0.24f * CCMacros.CCRandomBetween0And1()) * screen.Height); float speedMountainX = 0.15f + CCMacros.CCRandomBetween0And1() * 0.1f; parallax.AddChild(mountain, -1, new CCPoint(speedMountainX, .015f), pos, new CCPoint(land1.ContentSize.Width * 2f, 0)); mountain.Scale = 0.6f + CCMacros.CCRandomBetween0And1() * 0.4f; } CCSprite sky = new CCSprite("Images/sky_evening"); sky.AnchorPoint = CCPoint.AnchorLowerLeft; AddChild(parallax); AddChild(sky, -1); }
protected override void Draw() { base.Draw(); CCSize size = Layer.VisibleBoundsWorldspace.Size; var visibleRect = VisibleBoundsWorldspace; CCDrawingPrimitives.Begin(); // *NOTE* Using the Director.ContentScaleFactor for now until we work something out with the initialization // CCDrawPriitives should be able to do this converstion themselves. // draw a simple line // The default state is: // Line Width: 1 // color: 255,255,255,255 (white, non-transparent) // Anti-Aliased // glEnable(GL_LINE_SMOOTH); CCDrawingPrimitives.LineWidth = 1; CCDrawingPrimitives.DrawLine(visibleRect.LeftBottom(), visibleRect.RightTop()); // line: color, width, aliased CCDrawingPrimitives.LineWidth = 5; CCDrawingPrimitives.DrawColor = CCColor4B.Red; CCDrawingPrimitives.DrawLine(visibleRect.LeftTop(), visibleRect.RightBottom()); // TIP: // If you are going to use always thde same color or width, you don't // need to call it before every draw // // draw big point in the center CCDrawingPrimitives.PointSize = 64; CCDrawingPrimitives.DrawColor = new CCColor4B(0, 0, 255, 128); CCDrawingPrimitives.DrawPoint(visibleRect.Center()); // draw 4 small points CCPoint[] points = { new CCPoint(60, 60), new CCPoint(70, 70), new CCPoint(60, 70), new CCPoint(70, 60) }; CCDrawingPrimitives.PointSize = 8; CCDrawingPrimitives.DrawColor = new CCColor4B(0, 255, 255, 255); CCDrawingPrimitives.DrawPoints(points); // draw a green circle with 10 segments CCDrawingPrimitives.LineWidth = 16; CCDrawingPrimitives.DrawColor = CCColor4B.Green; CCDrawingPrimitives.DrawCircle(visibleRect.Center, 100, 0, 10, false); // draw a green circle with 50 segments with line to center CCDrawingPrimitives.LineWidth = 2; CCDrawingPrimitives.DrawColor = new CCColor4B(0, 255, 255, 255); CCDrawingPrimitives.DrawCircle(visibleRect.Center, 50, CCMacros.CCDegreesToRadians(45), 50, true); // draw a pink solid circle with 50 segments CCDrawingPrimitives.LineWidth = 2; CCDrawingPrimitives.DrawColor = new CCColor4B(255, 0, 255, 255); CCDrawingPrimitives.DrawSolidCircle(visibleRect.Center + new CCPoint(140, 0), 40, CCMacros.CCDegreesToRadians(90), 50); // draw an arc within rectangular region CCDrawingPrimitives.LineWidth = 5; CCDrawingPrimitives.DrawArc(new CCRect(200, 100, 100, 200), 0, 180, CCColor4B.AliceBlue); // draw an ellipse within rectangular region CCDrawingPrimitives.DrawEllipse(new CCRect(100, 100, 100, 200), CCColor4B.Red); // draw an arc within rectangular region CCDrawingPrimitives.DrawPie(new CCRect(350, 0, 100, 100), 20, 100, CCColor4B.AliceBlue); // draw an arc within rectangular region CCDrawingPrimitives.DrawPie(new CCRect(347, -5, 100, 100), 120, 260, CCColor4B.Aquamarine); // open yellow poly CCPoint[] vertices = { new CCPoint(0, 0), new CCPoint(50, 50), new CCPoint(100, 50), new CCPoint(100, 100), new CCPoint(50, 100) }; CCDrawingPrimitives.LineWidth = 10; CCDrawingPrimitives.DrawColor = CCColor4B.Yellow; CCDrawingPrimitives.DrawPoly(vertices, 5, false, new CCColor4B(255, 255, 0, 255)); // filled poly CCDrawingPrimitives.LineWidth = 1; CCPoint[] filledVertices = { new CCPoint(0, 120), new CCPoint(50, 120), new CCPoint(50, 170), new CCPoint(25, 200), new CCPoint(0, 170) }; CCDrawingPrimitives.DrawSolidPoly(filledVertices, new CCColor4F(0.5f, 0.5f, 1, 1)); // closed purple poly CCDrawingPrimitives.LineWidth = 2; CCDrawingPrimitives.DrawColor = new CCColor4B(255, 0, 255, 255); CCPoint[] vertices2 = { new CCPoint(30, 130), new CCPoint(30, 230), new CCPoint(50, 200) }; CCDrawingPrimitives.DrawPoly(vertices2, true); // draw quad bezier path CCDrawingPrimitives.DrawQuadBezier(new CCPoint(0, size.Height), visibleRect.Center, (CCPoint)visibleRect.Size, 50, new CCColor4B(255, 0, 255, 255)); // draw cubic bezier path CCDrawingPrimitives.DrawCubicBezier(visibleRect.Center, new CCPoint(size.Width / 2 + 30, size.Height / 2 + 50), new CCPoint(size.Width / 2 + 60, size.Height / 2 - 50), new CCPoint(size.Width, size.Height / 2), 100); //draw a solid polygon CCPoint[] vertices3 = { new CCPoint(60, 160), new CCPoint(70, 190), new CCPoint(100, 190), new CCPoint(90, 160) }; CCDrawingPrimitives.DrawSolidPoly(vertices3, 4, new CCColor4F(1, 1, 0, 1)); CCDrawingPrimitives.End(); }
void ClearImage(object sender) { target.BeginWithClear((byte)(CCMacros.CCRandomBetween0And1() * 255), (byte)(CCMacros.CCRandomBetween0And1() * 255), (byte)(CCMacros.CCRandomBetween0And1() * 255), (byte)(CCMacros.CCRandomBetween0And1() * 255)); target.End(); }
void CreateObject() { // Define the dynamic body. var bodyDef = b2BodyDef.Create(); bodyDef.type = b2BodyType.b2_dynamicBody; //or you could use b2_staticBody bodyDef.position.Set(initialLocation.X / Constants.PTM_RATIO, initialLocation.Y / Constants.PTM_RATIO); var shape = new b2PolygonShape(); var shapeCircle = new b2CircleShape(); if (shapeCreationMethod == CreationMethod.DiameterOfImageForCircle) { var tempSprite = new CCSprite(spriteImageName); var radiusInMeters = (tempSprite.ContentSize.Width / Constants.PTM_RATIO) * 0.5f; shapeCircle.Radius = radiusInMeters; } else if (shapeCreationMethod == CreationMethod.ShapeOfSourceImage) { var tempSprite = new CCSprite(spriteImageName); var num = 4; b2Vec2[] vertices = { new b2Vec2((tempSprite.ContentSize.Width / -2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO), //top left corner new b2Vec2((tempSprite.ContentSize.Width / -2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom left corner new b2Vec2((tempSprite.ContentSize.Width / 2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom right corner new b2Vec2((tempSprite.ContentSize.Width / 2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO) //top right corner }; shape.Set(vertices, num); } else if (shapeCreationMethod == CreationMethod.Triangle) { var tempSprite = new CCSprite(spriteImageName); var num = 3; b2Vec2[] vertices = { new b2Vec2((tempSprite.ContentSize.Width / -2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom left corner new b2Vec2((tempSprite.ContentSize.Width / 2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom right corner new b2Vec2(0.0f / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO) // top center of image }; shape.Set(vertices, num); } else if (shapeCreationMethod == CreationMethod.TriangleRightAngle) { var tempSprite = new CCSprite(spriteImageName); var num = 3; b2Vec2[] vertices = { new b2Vec2((tempSprite.ContentSize.Width / 2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO), //top right corner new b2Vec2((tempSprite.ContentSize.Width / -2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO), //top left corner new b2Vec2((tempSprite.ContentSize.Width / -2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO) //bottom left corner }; shape.Set(vertices, num); } else if (shapeCreationMethod == CreationMethod.Trapezoid) { var tempSprite = new CCSprite(spriteImageName); var num = 4; b2Vec2[] vertices = { new b2Vec2((tempSprite.ContentSize.Width / 4) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO), //top of image, 3/4's across new b2Vec2((tempSprite.ContentSize.Width / -4) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO), //top of image, 1/4's across new b2Vec2((tempSprite.ContentSize.Width / -2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom left corner new b2Vec2((tempSprite.ContentSize.Width / 2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom right corner }; shape.Set(vertices, num); } else if (shapeCreationMethod == CreationMethod.Hexagon) { var tempSprite = new CCSprite(spriteImageName); var num = 6; b2Vec2[] vertices = { new b2Vec2((tempSprite.ContentSize.Width / -4) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO), //top of image, 1/4 across new b2Vec2((tempSprite.ContentSize.Width / -2) / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO), // left, center new b2Vec2((tempSprite.ContentSize.Width / -4) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom of image, 1/4 across new b2Vec2((tempSprite.ContentSize.Width / 4) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom of image, 3/4's across new b2Vec2((tempSprite.ContentSize.Width / 2) / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO), // right, center new b2Vec2((tempSprite.ContentSize.Width / 4) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO) //top of image, 3/4's across }; shape.Set(vertices, num); } else if (shapeCreationMethod == CreationMethod.Pentagon) { var tempSprite = new CCSprite(spriteImageName); var num = 5; b2Vec2[] vertices = { new b2Vec2(0 / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO), //top of image, center new b2Vec2((tempSprite.ContentSize.Width / -2) / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO), // left, center new b2Vec2((tempSprite.ContentSize.Width / -4) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom of image, 1/4 across new b2Vec2((tempSprite.ContentSize.Width / 4) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom of image, 3/4's across new b2Vec2((tempSprite.ContentSize.Width / 2) / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO), // right, center }; shape.Set(vertices, num); } else if (shapeCreationMethod == CreationMethod.Octagon) { var tempSprite = new CCSprite(spriteImageName); var num = 8; b2Vec2[] vertices = { new b2Vec2((tempSprite.ContentSize.Width / -6) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO), //use the source image octogonShape.png for reference new b2Vec2((tempSprite.ContentSize.Width / -2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 6) / Constants.PTM_RATIO), new b2Vec2((tempSprite.ContentSize.Width / -2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -6) / Constants.PTM_RATIO), new b2Vec2((tempSprite.ContentSize.Width / -6) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), new b2Vec2((tempSprite.ContentSize.Width / 6) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), new b2Vec2((tempSprite.ContentSize.Width / 2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -6) / Constants.PTM_RATIO), new b2Vec2((tempSprite.ContentSize.Width / 2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 6) / Constants.PTM_RATIO), new b2Vec2((tempSprite.ContentSize.Width / 6) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO) }; shape.Set(vertices, num); } else if (shapeCreationMethod == CreationMethod.Parallelogram) { var tempSprite = new CCSprite(spriteImageName); var num = 4; b2Vec2[] vertices = { new b2Vec2((tempSprite.ContentSize.Width / -4) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO), //top of image, 1/4 across new b2Vec2((tempSprite.ContentSize.Width / -2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom left corner new b2Vec2((tempSprite.ContentSize.Width / 4) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2) / Constants.PTM_RATIO), //bottom of image, 3/4's across new b2Vec2((tempSprite.ContentSize.Width / 2) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2) / Constants.PTM_RATIO) //top right corner }; shape.Set(vertices, num); } else if (shapeCreationMethod == CreationMethod.CustomCoordinates1) //use your own custom coordinates from a program like Vertex Helper Pro { var num = 4; b2Vec2[] vertices = { new b2Vec2(-64.0f / Constants.PTM_RATIO, 16.0f / Constants.PTM_RATIO), new b2Vec2(-64.0f / Constants.PTM_RATIO, -16.0f / Constants.PTM_RATIO), new b2Vec2(64.0f / Constants.PTM_RATIO, -16.0f / Constants.PTM_RATIO), new b2Vec2(64.0f / Constants.PTM_RATIO, 16.0f / Constants.PTM_RATIO) }; shape.Set(vertices, num); } // Define the dynamic body fixture. var fixtureDef = b2FixtureDef.Create(); if (shapeCreationMethod == CreationMethod.DiameterOfImageForCircle) { fixtureDef.shape = shapeCircle; } else { fixtureDef.shape = shape; } fixtureDef.density = theDensity; fixtureDef.friction = 0.3f; fixtureDef.restitution = 0.1f; CreateBodyWithSpriteAndFixture(theWorld, bodyDef, fixtureDef, spriteImageName); if (angle != 0) { int currentAngle = (int)body.Angle; b2Vec2 locationInMeters = body.Position; body.SetTransform(locationInMeters, CCMacros.CCDegreesToRadians(currentAngle + angle)); } if (IsStatic) { MakeBodyStatic(); } }
void ClearImage(object sender) { target.Clear(CCMacros.CCRandomBetween0And1(), CCMacros.CCRandomBetween0And1(), CCMacros.CCRandomBetween0And1(), CCMacros.CCRandomBetween0And1()); }
public void clearImage(object pSender) { m_pTarget.Clear(CCMacros.CCRandomBetween0And1(), CCMacros.CCRandomBetween0And1(), CCMacros.CCRandomBetween0And1(), CCMacros.CCRandomBetween0And1()); }
public override void Draw() { base.Draw(); CCApplication app = CCApplication.SharedApplication; CCSize s = CCDirector.SharedDirector.WinSize; CCDrawingPrimitives.Begin(); // draw a simple line CCDrawingPrimitives.DrawLine(new CCPoint(0, 0), new CCPoint(s.Width, s.Height), new CCColor4B(255, 255, 255, 255)); // line: color, width, aliased CCDrawingPrimitives.DrawLine(new CCPoint(0, s.Height), new CCPoint(s.Width, 0), new CCColor4B(255, 0, 0, 255)); // draw big point in the center CCDrawingPrimitives.DrawPoint(new CCPoint(s.Width / 2, s.Height / 2), 64, new CCColor4B(0, 0, 255, 128)); // draw 4 small points CCPoint[] points = { new CCPoint(60, 60), new CCPoint(70, 70), new CCPoint(60, 70), new CCPoint(70, 60) }; CCDrawingPrimitives.DrawPoints(points, 4, 4, new CCColor4B(0, 255, 255, 255)); // draw a green circle with 10 segments CCDrawingPrimitives.DrawCircle(new CCPoint(s.Width / 2, s.Height / 2), 100, 0, 10, false, new CCColor4B(0, 255, 0, 255)); // draw a green circle with 50 segments with line to center CCDrawingPrimitives.DrawCircle(new CCPoint(s.Width / 2, s.Height / 2), 50, CCMacros.CCDegreesToRadians(90), 50, true, new CCColor4B(0, 255, 255, 255)); // draw an arc within rectangular region CCDrawingPrimitives.DrawArc(new CCRect(200, 200, 100, 200), 0, 180, new CCColor4B(Microsoft.Xna.Framework.Color.AliceBlue)); // draw an ellipse within rectangular region CCDrawingPrimitives.DrawEllipse(new CCRect(500, 200, 100, 200), new CCColor4B(255, 0, 0, 255)); // draw an arc within rectangular region CCDrawingPrimitives.DrawPie(new CCRect(350, 0, 100, 100), 20, 100, new CCColor4B(Microsoft.Xna.Framework.Color.AliceBlue)); // draw an arc within rectangular region CCDrawingPrimitives.DrawPie(new CCRect(347, -5, 100, 100), 120, 260, new CCColor4B(Microsoft.Xna.Framework.Color.Aquamarine)); // open yellow poly CCPoint[] vertices = { new CCPoint(0, 0), new CCPoint(50, 50), new CCPoint(100, 50), new CCPoint(100, 100), new CCPoint(50, 100) }; CCDrawingPrimitives.DrawPoly(vertices, 5, false, new CCColor4B(255, 255, 0, 255)); // filled poly CCPoint[] filledVertices = { new CCPoint(0, 120), new CCPoint(50, 120), new CCPoint(50, 170), new CCPoint(25, 200), new CCPoint(0, 170) }; CCDrawingPrimitives.DrawSolidPoly(filledVertices, 5, new CCColor4B(128, 128, 255, 255)); // closed purble poly CCPoint[] vertices2 = { new CCPoint(30, 130), new CCPoint(30, 230), new CCPoint(50, 200) }; CCDrawingPrimitives.DrawPoly(vertices2, 3, true, new CCColor4B(255, 0, 255, 255)); // draw quad bezier path CCDrawingPrimitives.DrawQuadBezier(new CCPoint(0, s.Height), new CCPoint(s.Width / 2, s.Height / 2), new CCPoint(s.Width, s.Height), 50, new CCColor4B(255, 0, 255, 255)); // draw cubic bezier path CCDrawingPrimitives.DrawCubicBezier(new CCPoint(s.Width / 2, s.Height / 2), new CCPoint(s.Width / 2 + 30, s.Height / 2 + 50), new CCPoint(s.Width / 2 + 60, s.Height / 2 - 50), new CCPoint(s.Width, s.Height / 2), 100, new CCColor4B(255, 0, 255, 255)); //draw a solid polygon CCPoint[] vertices3 = { new CCPoint(60, 160), new CCPoint(70, 190), new CCPoint(100, 190), new CCPoint(90, 160) }; CCDrawingPrimitives.DrawSolidPoly(vertices3, 4, new CCColor4B(255, 255, 0, 255)); CCDrawingPrimitives.End(); }
public float ToDegrees() { return(-1 * CCMacros.CCRadiansToDegrees(angle)); }