public bool initWithSize(ccGridSize gridSize) { CCDirector pDirector = CCDirector.sharedDirector(); CCSize s = pDirector.winSizeInPixels; ulong POTWide = ccNextPOT((uint)s.width); ulong POTHigh = ccNextPOT((uint)s.height); // we only use rgba8888 CCTexture2DPixelFormat format = CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888; CCTexture2D pTexture = new CCTexture2D(); pTexture.initWithData(null, format, (uint)POTWide, (uint)POTHigh, s); if (pTexture == null) { CCLog.Log("cocos2d: CCGrid: error creating texture"); return(false); } initWithSize(gridSize, pTexture, false); return(true); }
public override void onEnter() { int num; int num1; base.onEnter(); CCSize winSize = CCDirector.sharedDirector().getWinSize(); if (winSize.width <= winSize.height) { num = 12; num1 = 16; } else { num = 16; num1 = 12; } CCActionInterval cCActionInterval = this.actionWithSize(ccTypes.ccg(num, num1)); if (!this.m_bBack) { CCScene mPOutScene = this.m_pOutScene; CCFiniteTimeAction[] cCFiniteTimeActionArray = new CCFiniteTimeAction[] { cCActionInterval, CCCallFunc.actionWithTarget(this, new SEL_CallFunc(this.finish)), CCStopGrid.action() }; mPOutScene.runAction(CCSequence.actions(cCFiniteTimeActionArray)); return; } this.m_pInScene.visible = false; CCScene mPInScene = this.m_pInScene; CCFiniteTimeAction[] cCFiniteTimeActionArray1 = new CCFiniteTimeAction[] { CCShow.action(), cCActionInterval, CCCallFunc.actionWithTarget(this, new SEL_CallFunc(this.finish)), CCStopGrid.action() }; mPInScene.runAction(CCSequence.actions(cCFiniteTimeActionArray1)); }
public override void onEnter() { base.onEnter(); CCSize winSize = CCDirector.sharedDirector().getWinSize(); this.m_pInScene.scale = 0.5f; this.m_pInScene.position = new CCPoint(winSize.width, 0f); this.m_pInScene.anchorPoint = new CCPoint(0.5f, 0.5f); this.m_pOutScene.anchorPoint = new CCPoint(0.5f, 0.5f); CCActionInterval cCActionInterval = CCJumpBy.actionWithDuration(this.m_fDuration / 4f, new CCPoint(-winSize.width, 0f), winSize.width / 4f, 2); CCActionInterval cCActionInterval1 = CCScaleTo.actionWithDuration(this.m_fDuration / 4f, 1f); CCActionInterval cCActionInterval2 = CCScaleTo.actionWithDuration(this.m_fDuration / 4f, 0.5f); CCFiniteTimeAction[] cCFiniteTimeActionArray = new CCFiniteTimeAction[] { cCActionInterval2, cCActionInterval }; CCActionInterval cCActionInterval3 = (CCActionInterval)CCSequence.actions(cCFiniteTimeActionArray); CCFiniteTimeAction[] cCFiniteTimeActionArray1 = new CCFiniteTimeAction[] { cCActionInterval, cCActionInterval1 }; CCActionInterval cCActionInterval4 = (CCActionInterval)CCSequence.actions(cCFiniteTimeActionArray1); CCActionInterval cCActionInterval5 = CCDelayTime.actionWithDuration(this.m_fDuration / 2f); this.m_pOutScene.runAction(cCActionInterval3); CCScene mPInScene = this.m_pInScene; CCFiniteTimeAction[] cCFiniteTimeActionArray2 = new CCFiniteTimeAction[] { cCActionInterval5, cCActionInterval4, CCCallFunc.actionWithTarget(this, new SEL_CallFunc(this.finish)) }; mPInScene.runAction(CCSequence.actions(cCFiniteTimeActionArray2)); }
/// <summary> /// initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid /// </summary> public bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { bool bRet = false; do { w *= (int)CCDirector.sharedDirector().ContentScaleFactor; h *= (int)CCDirector.sharedDirector().ContentScaleFactor; //glGetIntegerv(0x8CA6, m_nOldFBO); // textures must be power of two squared uint powW = (uint)ccUtils.ccNextPOT(w); uint powH = (uint)ccUtils.ccNextPOT(h); m_pTexture = new CCTexture2D(); CCApplication app = CCApplication.sharedApplication(); m_RenderTarget2D = new RenderTarget2D(app.GraphicsDevice, (int)w, (int)h); app.GraphicsDevice.SetRenderTarget(m_RenderTarget2D); app.GraphicsDevice.Clear(new Microsoft.Xna.Framework.Color(0, 0, 0, 0)); m_pTexture.initWithTexture(m_RenderTarget2D); // generate FBO //ccglGenFramebuffers(1, &m_uFBO); //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO); // associate texture with FBO //ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0); // check if it worked (probably worth doing :) ) //GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER); //if (status != CC_GL_FRAMEBUFFER_COMPLETE) //{ // CCAssert(0, "Render Texture : Could not attach texture to framebuffer"); // CC_SAFE_DELETE(m_pTexture); // break; //} //m_pTexture.setAliasTexParameters(); m_pSprite = CCSprite.spriteWithTexture(m_pTexture); //m_pTexture->release(); //m_pSprite.scaleY = -1; this.addChild(m_pSprite); ccBlendFunc tBlendFunc = new ccBlendFunc { src = 1, dst = 0x0303 }; m_pSprite.BlendFunc = tBlendFunc; //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO); bRet = true; } while (false); return(bRet); }
public override void onEnter() { base.onEnter(); CCSize s = CCDirector.sharedDirector().getWinSize(); CCLabelTTF label = CCLabelTTF.labelWithString(title(), "Arial", 28); addChild(label, 1); label.position = new CCPoint(s.width / 2, s.height - 50); string strSubtitle = subtitle(); if (strSubtitle != null) { CCLabelTTF l = CCLabelTTF.labelWithString(strSubtitle, "Arial", 16); addChild(l, 1); l.position = new CCPoint(s.width / 2, s.height - 80); } CCMenuItemImage item1 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathB1, TestResource.s_pPathB2, this, new SEL_MenuHandler(backCallback)); CCMenuItemImage item2 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathR1, TestResource.s_pPathR2, this, new SEL_MenuHandler(restartCallback)); CCMenuItemImage item3 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathF1, TestResource.s_pPathF2, this, new SEL_MenuHandler(nextCallback)); CCMenu menu = CCMenu.menuWithItems(item1, item2, item3); menu.position = new CCPoint(); item1.position = new CCPoint(s.width / 2 - 100, 30); item2.position = new CCPoint(s.width / 2, 30); item3.position = new CCPoint(s.width / 2 + 100, 30); addChild(menu, 1); }
public override void blit() { int mSGridSize = this.m_sGridSize.x; int num = this.m_sGridSize.y; CCApplication texture2D = CCApplication.sharedApplication(); CCDirector.sharedDirector().getWinSize(); texture2D.basicEffect.Texture = this.m_pTexture.getTexture2D(); texture2D.basicEffect.TextureEnabled = true; texture2D.GraphicsDevice.BlendState = BlendState.AlphaBlend; texture2D.basicEffect.VertexColorEnabled = true; List <VertexPositionColorTexture> vertexPositionColorTextures = new List <VertexPositionColorTexture>(); for (int i = 0; i < (this.m_sGridSize.x + 1) * (this.m_sGridSize.y + 1); i++) { VertexPositionColorTexture vertexPositionColorTexture = new VertexPositionColorTexture() { Position = new Vector3(this.m_pVertices[i].x, this.m_pVertices[i].y, this.m_pVertices[i].z), TextureCoordinate = new Vector2(this.m_pTexCoordinates[i].x, this.m_pTexCoordinates[i].y), Color = Color.White }; vertexPositionColorTextures.Add(vertexPositionColorTexture); } short[] mPIndices = this.m_pIndices; foreach (EffectPass pass in texture2D.basicEffect.CurrentTechnique.Passes) { pass.Apply(); texture2D.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, vertexPositionColorTextures.ToArray(), 0, vertexPositionColorTextures.Count, mPIndices, 0, (int)mPIndices.Length / 3); } }
public override void onEnter() { base.onEnter(); CCSize s = CCDirector.sharedDirector().getWinSize(); m_pInScene.scale = 0.5f; m_pInScene.position = new CCPoint(s.width, 0); m_pInScene.anchorPoint = new CCPoint(0.5f, 0.5f); m_pOutScene.anchorPoint = new CCPoint(0.5f, 0.5f); CCActionInterval jump = CCJumpBy.actionWithDuration(m_fDuration / 4, new CCPoint(-s.width, 0), s.width / 4, 2); CCActionInterval scaleIn = CCScaleTo.actionWithDuration(m_fDuration / 4, 1.0f); CCActionInterval scaleOut = CCScaleTo.actionWithDuration(m_fDuration / 4, 0.5f); CCActionInterval jumpZoomOut = (CCActionInterval)(CCSequence.actions(scaleOut, jump)); CCActionInterval jumpZoomIn = (CCActionInterval)(CCSequence.actions(jump, scaleIn)); CCActionInterval delay = CCDelayTime.actionWithDuration(m_fDuration / 2); m_pOutScene.runAction(jumpZoomOut); m_pInScene.runAction ( CCSequence.actions ( delay, jumpZoomIn, CCCallFunc.actionWithTarget(this, base.finish) ) ); }
public override void ccTouchEnded(CCTouch pTouch, CCEvent pEvent) { if (m_pTrackNode != null) { return; } CCPoint endPos = pTouch.locationInView(pTouch.view()); endPos = CCDirector.sharedDirector().convertToGL(endPos); float delta = 5.0f; if (Math.Abs(endPos.x - m_beginPos.x) > delta || Math.Abs(endPos.y - m_beginPos.y) > delta) { // not click m_beginPos.x = m_beginPos.y = -1; return; } // decide the trackNode is clicked. CCRect rect; CCPoint point = convertTouchToNodeSpaceAR(pTouch); Debug.WriteLine("KeyboardNotificationLayer:clickedAt(%f,%f)", point.x, point.y); rect = TextInputTestScene.getRect(m_pTrackNode); Debug.WriteLine("KeyboardNotificationLayer:TrackNode at(origin:%f,%f, size:%f,%f)", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); this.onClickTrackNode(CCRect.CCRectContainsPoint(rect, point)); Debug.WriteLine("----------------------------------"); }
// CCLayer public override void onEnter() { base.onEnter(); m_nCharLimit = 12; m_pTextFieldAction = CCRepeatForever.actionWithAction( (CCActionInterval)CCSequence.actions( CCFadeOut.actionWithDuration(0.25f), CCFadeIn.actionWithDuration(0.25f))); //m_pTextFieldAction->retain(); m_bAction = false; // add CCTextFieldTTF CCSize s = CCDirector.sharedDirector().getWinSize(); m_pTextField = CCTextFieldTTF.textFieldWithPlaceHolder("<click here for input>", TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE); addChild(m_pTextField); //m_pTextField.setDelegate(this); //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) // // on android, CCTextFieldTTF cannot auto adjust its position when soft-keyboard pop up // // so we had to set a higher position // m_pTextField->setPosition(new CCPoint(s.width / 2, s.height/2 + 50)); //#else // m_pTextField->setPosition(ccp(s.width / 2, s.height / 2)); //#endif m_pTrackNode = m_pTextField; }
public CCPoint convertTouchToNodeSpaceAR(CCTouch touch) { CCPoint obPoint = touch.locationInView(touch.view()); obPoint = CCDirector.sharedDirector().convertToGL(obPoint); return(this.convertToNodeSpaceAR(obPoint)); }
// CCLayer public override bool ccTouchBegan(CCTouch pTouch, CCEvent pEvent) { Debug.WriteLine("++++++++++++++++++++++++++++++++++++++++++++"); m_beginPos = pTouch.locationInView(pTouch.view()); m_beginPos = CCDirector.sharedDirector().convertToGL(m_beginPos); return(true); }
public void initTexCoordsWithRect(CCRect pointRect) { CCRect rect = new CCRect(pointRect.origin.x * CCDirector.sharedDirector().ContentScaleFactor, pointRect.origin.y * CCDirector.sharedDirector().ContentScaleFactor, pointRect.size.width * CCDirector.sharedDirector().ContentScaleFactor, pointRect.size.height * CCDirector.sharedDirector().ContentScaleFactor); float width = pointRect.size.width; float height = pointRect.size.height; if (this.Texture != null) { width = this.Texture.PixelsWide; height = this.Texture.PixelsHigh; } float num3 = rect.origin.x / width; float y = rect.origin.y / height; float num5 = num3 + (rect.size.width / width); float x = y + (rect.size.height / height); ccMacros.CC_SWAP <float>(ref x, ref y); for (uint i = 0; i < base.TotalParticles; i++) { this.m_pQuads[i] = new ccV2F_C4B_T2F_Quad(); this.m_pQuads[i].bl.texCoords.u = num3; this.m_pQuads[i].bl.texCoords.v = y; this.m_pQuads[i].br.texCoords.u = num5; this.m_pQuads[i].br.texCoords.v = y; this.m_pQuads[i].tl.texCoords.u = num3; this.m_pQuads[i].tl.texCoords.v = x; this.m_pQuads[i].tr.texCoords.u = num5; this.m_pQuads[i].tr.texCoords.v = x; } }
public override void draw() { base.draw(); BlendState blendState = CCApplication.sharedApplication().GraphicsDevice.BlendState; BlendState alphaBlend = BlendState.AlphaBlend; if (base.IsBlendAdditive) { alphaBlend = BlendState.Additive; } CCApplication.sharedApplication().spriteBatch.Begin(SpriteSortMode.Deferred, alphaBlend); for (int i = 0; i < base.ParticleCount; i++) { CCParticle particle = base.m_pParticles[i]; CCPoint obPoint = CCPointExtension.ccpAdd(CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(), base.nodeToWorldTransform()), new CCPoint(this.m_pQuads[i].bl.vertices.x, this.m_pQuads[i].bl.vertices.y)); obPoint = CCDirector.sharedDirector().convertToUI(obPoint); Vector2 position = new Vector2(obPoint.x, obPoint.y); Color color = new Color(particle.color.r, particle.color.g, particle.color.b, particle.color.a); float scale = 1f; if (this.Texture.getTexture2D().Width > this.Texture.getTexture2D().Height) { scale = particle.size / ((float)this.Texture.getTexture2D().Height); } else { scale = particle.size / ((float)this.Texture.getTexture2D().Width); } float rotation = particle.rotation; Vector2 origin = new Vector2((float)(this.Texture.getTexture2D().Width / 2), (float)(this.Texture.getTexture2D().Height / 2)); Rectangle?sourceRectangle = null; CCApplication.sharedApplication().spriteBatch.Draw(this.Texture.getTexture2D(), position, sourceRectangle, color, rotation, origin, scale, SpriteEffects.None, 0f); } CCApplication.sharedApplication().spriteBatch.End(); CCApplication.sharedApplication().GraphicsDevice.BlendState = blendState; }
protected void applyLandscape() { CCDirector pDirector = CCDirector.sharedDirector(); CCSize winSize = pDirector.displaySizeInPixels; float w = winSize.width / 2; float h = winSize.height / 2; ccDeviceOrientation orientation = pDirector.deviceOrientation; switch (orientation) { case ccDeviceOrientation.CCDeviceOrientationPortraitUpsideDown: //glTranslatef(w,h,0); //glRotatef(180,0,0,1); //glTranslatef(-w,-h,0); break; case ccDeviceOrientation.CCDeviceOrientationLandscapeLeft: //glTranslatef(w,h,0); //glRotatef(-90,0,0,1); //glTranslatef(-h,-w,0); break; case ccDeviceOrientation.CCDeviceOrientationLandscapeRight: //glTranslatef(w,h,0); //glRotatef(90,0,0,1); //glTranslatef(-h,-w,0); break; default: break; } }
public void setCenterXYZ(float fCenterX, float fCenterY, float fCenterZ) { this.m_fCenterX = fCenterX * CCDirector.sharedDirector().ContentScaleFactor; this.m_fCenterY = fCenterY * CCDirector.sharedDirector().ContentScaleFactor; this.m_fCenterZ = fCenterZ * CCDirector.sharedDirector().ContentScaleFactor; this.m_bDirty = true; }
public override void onEnter() { base.onEnter(); CCSize s = CCDirector.sharedDirector().getWinSize(); CCLabelTTF label = CCLabelTTF.labelWithString(title(), "Arial", 24); addChild(label); label.position = new CCPoint(s.width / 2, s.height - 50); string subTitle = m_pNotificationLayer.subtitle(); if (subTitle != null) { CCLabelTTF l = CCLabelTTF.labelWithString(subTitle, "Thonburi", 16); addChild(l, 1); l.position = new CCPoint(s.width / 2, s.height - 80); } CCMenuItemImage item1 = CCMenuItemImage.itemFromNormalImage("Images/b1.png", "Images/b2.png", this, backCallback); CCMenuItemImage item2 = CCMenuItemImage.itemFromNormalImage("Images/r1.png", "Images/r2.png", this, restartCallback); CCMenuItemImage item3 = CCMenuItemImage.itemFromNormalImage("Images/f1.png", "Images/f2.png", this, nextCallback); CCMenu menu = CCMenu.menuWithItems(item1, item2, item3); menu.position = new CCPoint(0, 0); item1.position = new CCPoint(s.width / 2 - 100, 30); item2.position = new CCPoint(s.width / 2, 30); item3.position = new CCPoint(s.width / 2 + 100, 30); addChild(menu, 1); }
public void setEyeXYZ(float fEyeX, float fEyeY, float fEyeZ) { this.m_fEyeX = fEyeX * CCDirector.sharedDirector().ContentScaleFactor; this.m_fEyeY = fEyeY * CCDirector.sharedDirector().ContentScaleFactor; this.m_fEyeZ = fEyeZ * CCDirector.sharedDirector().ContentScaleFactor; this.m_bDirty = true; }
public static void ccDrawCircle(CCPoint center, float radius, float angle, int segments, bool drawLineToCenter, ccColor4B color) { int num = 1; if (drawLineToCenter) { num++; } CCApplication cCApplication = CCApplication.sharedApplication(); float contentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor; float single = 6.28318548f / (float)segments; VertexPositionColor[] vector3 = new VertexPositionColor[2 * (segments + 2)]; for (int i = 0; i <= segments; i++) { float single1 = (float)i * single; float single2 = radius * (float)Math.Cos((double)(single1 + angle)) + center.x; float single3 = radius * (float)Math.Sin((double)(single1 + angle)) + center.y; vector3[i] = new VertexPositionColor(); vector3[i].Position = new Vector3(single2 * contentScaleFactor, single3 * contentScaleFactor, 0f); vector3[i].Color = new Color((int)color.r, (int)color.g, (int)color.b, (int)color.a); } cCApplication.basicEffect.TextureEnabled = false; cCApplication.basicEffect.VertexColorEnabled = true; foreach (EffectPass pass in cCApplication.basicEffect.CurrentTechnique.Passes) { pass.Apply(); cCApplication.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vector3, 0, segments); } }
/// <summary> /// draws a quad bezier path /// @since v0.8 /// </summary> public static void ccDrawQuadBezier(CCPoint origin, CCPoint control, CCPoint destination, int segments, ccColor4F color) { VertexPositionColor[] vertices = new VertexPositionColor[segments + 1]; float factor = CCDirector.sharedDirector().ContentScaleFactor; CCApplication app = CCApplication.sharedApplication(); float t = 0.0f; for (int i = 0; i < segments; i++) { float x = (float)Math.Pow(1 - t, 2) * origin.x + 2.0f * (1 - t) * t * control.x + t * t * destination.x; float y = (float)Math.Pow(1 - t, 2) * origin.y + 2.0f * (1 - t) * t * control.y + t * t * destination.y; vertices[i] = new VertexPositionColor(); vertices[i].Position = new Vector3(x * factor, y * factor, 0); vertices[i].Color = new Color(color.r, color.g, color.b, color.a); t += 1.0f / segments; } vertices[segments] = new VertexPositionColor() { Position = new Vector3(destination.x * factor, destination.y * factor, 0), Color = new Color(color.r, color.g, color.b, color.a), }; app.basicEffect.TextureEnabled = false; app.basicEffect.VertexColorEnabled = true; foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, segments); } }
public static void ccDrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, ccColor4F color) { VertexPositionColor[] vector3 = new VertexPositionColor[segments + 1]; float contentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor; CCApplication cCApplication = CCApplication.sharedApplication(); float single = 0f; for (int i = 0; i < segments; i++) { float single1 = (float)Math.Pow((double)(1f - single), 3) * origin.x + 3f * (float)Math.Pow((double)(1f - single), 2) * single * control1.x + 3f * (1f - single) * single * single * control2.x + single * single * single * destination.x; float single2 = (float)Math.Pow((double)(1f - single), 3) * origin.y + 3f * (float)Math.Pow((double)(1f - single), 2) * single * control1.y + 3f * (1f - single) * single * single * control2.y + single * single * single * destination.y; vector3[i] = new VertexPositionColor(); vector3[i].Position = new Vector3(single1 * contentScaleFactor, single2 * contentScaleFactor, 0f); vector3[i].Color = new Color(color.r, color.g, color.b, color.a); single = single + 1f / (float)segments; } VertexPositionColor vertexPositionColor = new VertexPositionColor() { Color = new Color(color.r, color.g, color.b, color.a), Position = new Vector3(destination.x * contentScaleFactor, destination.y * contentScaleFactor, 0f) }; vector3[segments] = vertexPositionColor; cCApplication.basicEffect.TextureEnabled = false; cCApplication.basicEffect.VertexColorEnabled = true; foreach (EffectPass pass in cCApplication.basicEffect.CurrentTechnique.Passes) { pass.Apply(); cCApplication.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vector3, 0, segments); } }
/** There are 4 types of Director. * - kCCDirectorTypeNSTimer (default) * - kCCDirectorTypeMainLoop * - kCCDirectorTypeThreadMainLoop * - kCCDirectorTypeDisplayLink * * Each Director has it's own benefits, limitations. * Now we only support DisplayLink director, so it has not effect. */ ///<summary> /// This method should be called before any other call to the director. ///@since v0.8.2 /// </summary> public static bool setDirectorType(ccDirectorType obDirectorType) { // we only support CCDisplayLinkDirector CCDirector.sharedDirector(); return(true); }
/// <summary> /// initializes a CCLayer with color. Width and height are the window size. /// </summary> public virtual bool initWithColor(ccColor4B color) { CCSize s = CCDirector.sharedDirector().getWinSize(); this.initWithColorWidthHeight(color, s.width, s.height); return(true); }
public AtlasBitmapColor() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCLabelBMFont label = null; label = CCLabelBMFont.labelWithString("Blue", "fonts/bitmapFontTest5.fnt"); label.Color = ccBLUE; addChild(label); label.position = new CCPoint(s.width / 2, s.height / 4); label.anchorPoint = new CCPoint(0.5f, 0.5f); label = CCLabelBMFont.labelWithString("Red", "fonts/bitmapFontTest5.fnt"); addChild(label); label.position = new CCPoint(s.width / 2, 2 * s.height / 4); label.anchorPoint = new CCPoint(0.5f, 0.5f); label.Color = ccRED; label = CCLabelBMFont.labelWithString("G", "fonts/bitmapFontTest5.fnt"); addChild(label); label.position = new CCPoint(s.width / 2, 3 * s.height / 4); label.anchorPoint = new CCPoint(0.5f, 0.5f); label.Color = ccGREEN; label.setString("Green"); }
public override void draw() { base.draw(); CCApplication app = CCApplication.sharedApplication(); CCSize size = CCDirector.sharedDirector().getWinSize(); app.basicEffect.VertexColorEnabled = true; app.basicEffect.TextureEnabled = false; app.basicEffect.Alpha = (float)this.m_cOpacity / 255.0f; VertexDeclaration vertexDeclaration = new VertexDeclaration(new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector4, VertexElementUsage.Color, 0) }); foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>( PrimitiveType.TriangleStrip, vertices, 0, 2); } app.basicEffect.Alpha = 1; }
public LabelsEmpty() { CCSize s = CCDirector.sharedDirector().getWinSize(); // CCLabelBMFont CCLabelBMFont label1 = CCLabelBMFont.labelWithString("", "fonts/bitmapFontTest3.fnt"); addChild(label1, 0, (int)TagSprite.kTagBitmapAtlas1); label1.position = new CCPoint(s.width / 2, s.height - 100); // CCLabelTTF CCLabelTTF label2 = CCLabelTTF.labelWithString("", "Arial", 24); addChild(label2, 0, (int)TagSprite.kTagBitmapAtlas2); label2.position = new CCPoint(s.width / 2, s.height / 2); // CCLabelAtlas CCLabelAtlas label3 = CCLabelAtlas.labelWithString("", "fonts/tuffy_bold_italic-charmap.png", 48, 64, ' '); addChild(label3, 0, (int)TagSprite.kTagBitmapAtlas3); label3.position = new CCPoint(s.width / 2, 0 + 100); base.schedule(updateStrings, 1.0f); setEmpty = false; }
protected CCMenuItem itemForTouch(CCTouch touch) { //XNA point CCPoint touchLocation = touch.locationInView(touch.view()); //cocos2d point touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation); if (m_pChildren != null && m_pChildren.Count > 0) { foreach (var pChild in m_pChildren) { if (pChild != null && pChild.visible && ((CCMenuItem)pChild).Enabled) { CCPoint local = pChild.convertToNodeSpace(touchLocation); CCRect r = ((CCMenuItem)pChild).rect(); r.origin = CCPoint.Zero; if (CCRect.CCRectContainsPoint(r, local)) { return((CCMenuItem)pChild); } } } } return(null); }
/// <summary> /// starts grabbing /// </summary> public void begin() { // Save the current matrix //glPushMatrix(); CCSize texSize = m_pTexture.ContentSizeInPixels; // Calculate the adjustment ratios based on the old and new projections CCSize size = CCDirector.sharedDirector().displaySizeInPixels; float widthRatio = size.width / texSize.width; float heightRatio = size.height / texSize.height; CCApplication.sharedApplication().GraphicsDevice.SetRenderTarget(m_RenderTarget2D); // Adjust the orthographic propjection and viewport //ccglOrtho((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1); //glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height); // CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, texSize.width, texSize.height); //glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_nOldFBO); //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);//Will direct drawing to the frame buffer created above // Issue #1145 // There is no need to enable the default GL states here // but since CCRenderTexture is mostly used outside the "render" loop // these states needs to be enabled. // Since this bug was discovered in API-freeze (very close of 1.0 release) // This bug won't be fixed to prevent incompatibilities with code. // // If you understand the above mentioned message, then you can comment the following line // and enable the gl states manually, in case you need them. //CC_ENABLE_DEFAULT_GL_STATES(); }
public bool initWithTarget(CCNode followedNode, CCRect rect) { this.m_pobFollowedNode = followedNode; this.m_bBoundarySet = true; this.m_bBoundaryFullyCovered = false; CCSize size = CCDirector.sharedDirector().getWinSize(); this.m_obFullScreenSize = new CCPoint(size.width, size.height); this.m_obHalfScreenSize = CCPointExtension.ccpMult(this.m_obFullScreenSize, 0.5f); this.m_fLeftBoundary = -((rect.origin.x + rect.size.width) - this.m_obFullScreenSize.x); this.m_fRightBoundary = -rect.origin.x; this.m_fLeftBoundary = -rect.origin.y; this.m_fBottomBoundary = -((rect.origin.y + rect.size.height) - this.m_obFullScreenSize.y); if (this.m_fRightBoundary < this.m_fLeftBoundary) { this.m_fRightBoundary = this.m_fLeftBoundary = (this.m_fLeftBoundary + this.m_fRightBoundary) / 2f; } if (this.m_fTopBoundary < this.m_fBottomBoundary) { this.m_fTopBoundary = this.m_fBottomBoundary = (this.m_fTopBoundary + this.m_fBottomBoundary) / 2f; } if ((this.m_fTopBoundary == this.m_fBottomBoundary) && (this.m_fLeftBoundary == this.m_fRightBoundary)) { this.m_bBoundaryFullyCovered = true; } return(true); }
/// <summary> /// initializes a transition with duration and incoming scene /// </summary> public virtual bool initWithDuration(float t, CCScene scene) { if (scene == null) { throw (new ArgumentNullException("scene", "Target scene must not be null")); } if (base.init()) { m_fDuration = t; // retain m_pInScene = scene; m_pOutScene = CCDirector.sharedDirector().runningScene; m_eSceneType = ccSceneFlag.ccTransitionScene; if (m_pInScene == m_pOutScene) { throw (new ArgumentException("scene", "Target and source scenes must be different")); } // disable events while transitions CCTouchDispatcher.sharedDispatcher().IsDispatchEvents = false; this.sceneOrder(); return(true); } else { return(false); } }
public override void onEnter() { base.onEnter(); CCSize winSize = CCDirector.sharedDirector().getWinSize(); CCRenderTexture cCPoint = CCRenderTexture.renderTextureWithWidthAndHeight((int)winSize.width, (int)winSize.height); if (cCPoint == null) { return; } cCPoint.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); cCPoint.position = new CCPoint(winSize.width / 2f, winSize.height / 2f); cCPoint.anchorPoint = new CCPoint(0.5f, 0.5f); cCPoint.clear(0f, 0f, 0f, 1f); cCPoint.begin(); this.m_pOutScene.visit(); cCPoint.end(); base.hideOutShowIn(); CCProgressTimer cCProgressTimer = CCProgressTimer.progressWithTexture(cCPoint.Sprite.Texture); cCProgressTimer.Type = this.radialType(); cCProgressTimer.Percentage = 100f; cCProgressTimer.position = new CCPoint(winSize.width / 2f, winSize.height / 2f); cCProgressTimer.anchorPoint = new CCPoint(0.5f, 0.5f); CCFiniteTimeAction[] cCFiniteTimeActionArray = new CCFiniteTimeAction[] { CCProgressFromTo.actionWithDuration(this.m_fDuration, 100f, 0f), CCCallFunc.actionWithTarget(this, new SEL_CallFunc(this.finish)) }; cCProgressTimer.runAction(CCSequence.actions(cCFiniteTimeActionArray)); this.addChild(cCProgressTimer, 2, 2147483647); }