public override void ccTouchEnded(CCTouch touch, CCEvent eve) { CCPoint location = touch.locationInView(touch.view()); CCPoint convertedLocation = CCDirector.sharedDirector().convertToGL(location); CCPoint pos = new CCPoint(0, 0); if (m_background != null) { pos = m_background.convertToWorldSpace(new CCPoint(0, 0)); } m_emitter.position = CCPointExtension.ccpSub(convertedLocation, pos); }
public override void runThisTest() { CCLayer pLayer1 = new MenuLayer1(); CCLayer pLayer2 = new MenuLayer2(); CCLayer pLayer3 = new MenuLayer3(); CCLayer pLayer4 = new MenuLayer4(); CCLayerMultiplex layer = CCLayerMultiplex.layerWithLayers(pLayer1, pLayer2, pLayer3, pLayer4); addChild(layer, 0); CCDirector.sharedDirector().replaceScene(this); }
public override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { if (CCDirector.sharedDirector().runningScene is StartScene) { this.Game.Exit(); return; } SceneController.RunScene(EnumScene.Start); } base.Update(gameTime); }
public void restartCallback(CCObject pSender) { CCScene s = new TransitionsTestScene(); CCLayer pLayer = new TestLayer1(); s.addChild(pLayer); CCScene pScene = TransitionsTestScene.createTransition(TransitionsTestScene.s_nSceneIdx, TransitionsTestScene.TRANSITION_DURATION, s); if (pScene != null) { CCDirector.sharedDirector().replaceScene(pScene); } }
public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow) { application.PreferMultiSampling = false; application.ContentRootDirectory = "Content"; application.ContentSearchPaths.Add("animations"); application.ContentSearchPaths.Add("fonts"); application.ContentSearchPaths.Add("sounds"); CCSize windowSize = mainWindow.WindowSizeInPixels; float desiredWidth = 1024.0f; float desiredHeight = 768.0f; // This will set the world bounds to be (0,0, w, h) // Use CCSceneResolutionPolicy.Custom as we're manually setting our viewports CCScene.SetDefaultDesignResolution(desiredWidth, desiredHeight, CCSceneResolutionPolicy.Custom); // Determine whether to use the high or low def versions of our images // Make sure the default texel to content size ratio is set correctly // Of course you're free to have a finer set of image resolutions e.g (ld, hd, super-hd) if (desiredWidth < windowSize.Width) { application.ContentSearchPaths.Add("images/hd"); CCSprite.DefaultTexelToContentSizeRatio = 2.0f; } else { application.ContentSearchPaths.Add("images/ld"); CCSprite.DefaultTexelToContentSizeRatio = 1.0f; } var topViewport = new CCViewport(new CCRect(0.0f, 0.2f, .5f, 0.6f)); var bottomViewport = new CCViewport(new CCRect(0.5f, 0.0f, .5f, 1.0f)); // Each viewport needs its own director var sceneDirector1 = new CCDirector(); var sceneDirector2 = new CCDirector(); var scene1 = new CCScene(mainWindow, topViewport, sceneDirector1); var scene2 = new CCScene(mainWindow, bottomViewport, sceneDirector2); var layer1 = new GameLayer(); var layer2 = new GameLayer(); scene1.AddChild(layer1); scene2.AddChild(layer2); sceneDirector1.RunWithScene(scene1); sceneDirector2.RunWithScene(scene2); }
private void performanceout20(CCSprite pSprite) { Random random = new Random(); CCSize size = CCDirector.sharedDirector().getWinSize(); if (random.Next() < 0.2f) { pSprite.position = new CCPoint((random.Next() % (int)size.width), (random.Next() % (int)size.height)); } else { pSprite.position = new CCPoint(-1000, -1000); } }
public override bool init() { if (base.init()) { CCSize size = CCDirector.sharedDirector().getWinSize(); PauseCrashTestScene n = new PauseCrashTestScene(); n.position = new CCPoint(0, 0); n.contentSize = new CCSize(size); this.addChild(n); n.init(); return(true); } return(false); }
public LabelGlyphDesigner() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCLayerColor layer = CCLayerColor.layerWithColor(new ccColor4B(128, 128, 128, 255)); addChild(layer, -10); // CCLabelBMFont CCLabelBMFont label1 = CCLabelBMFont.labelWithString("Testing Glyph Designer", "fonts/fnt/futura-48"); addChild(label1); label1.position = new CCPoint(s.width / 2, s.height / 2); }
public CameraOrbitTest() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCSprite p = CCSprite.spriteWithFile(TestResource.s_back3); addChild(p, 0); p.position = (new CCPoint(s.width / 2, s.height / 2)); p.Opacity = 128; CCSprite sprite; CCOrbitCamera orbit; CCCamera cam; CCSize ss; // LEFT s = p.contentSize; sprite = CCSprite.spriteWithFile(TestResource.s_pPathGrossini); sprite.scale = (0.5f); p.addChild(sprite, 0); sprite.position = (new CCPoint(s.width / 4 * 1, s.height / 2)); cam = sprite.Camera; orbit = CCOrbitCamera.actionWithDuration(2, 1, 0, 0, 360, 0, 0); //sprite.runAction(CCRepeatForever.actionWithAction(orbit)); // CENTER sprite = CCSprite.spriteWithFile(TestResource.s_pPathGrossini); sprite.scale = 1.0f; p.addChild(sprite, 0); sprite.position = new CCPoint(s.width / 4 * 2, s.height / 2); orbit = CCOrbitCamera.actionWithDuration(2, 1, 0, 0, 360, 45, 0); //sprite.runAction(CCRepeatForever.actionWithAction(orbit)); // RIGHT sprite = CCSprite.spriteWithFile(TestResource.s_pPathGrossini); sprite.scale = 2.0f; p.addChild(sprite, 0); sprite.position = new CCPoint(s.width / 4 * 3, s.height / 2); ss = sprite.contentSize; orbit = CCOrbitCamera.actionWithDuration(2, 1, 0, 0, 360, 90, -45); //sprite.runAction(CCRepeatForever.actionWithAction(orbit)); // PARENT orbit = CCOrbitCamera.actionWithDuration(10, 1, 0, 0, 360, 0, 90); //p.runAction(CCRepeatForever.actionWithAction(orbit)); scale = 1; }
/// <summary> /// AddTitleMenu only text /// </summary> /// <param name="p_Layer">current CCLayer</param> /// <param name="p_TitleText">show text</param> /// <param name="y">current y</param> public static void AddTitleMenu(CCLayer p_Layer, String p_TitleText, ref float y) { CCLabelTTF label = CCLabelTTF.labelWithString(p_TitleText, "ChineseTitle", 28); label.Color = new ccColor3B(Color.White); CCMenuItemLabel tab = CCMenuItemLabel.itemWithLabel(label); CCMenu menu = CCMenu.menuWithItems(tab); menu.position = new CCPoint(CCDirector.sharedDirector().displaySizeInPixels.width / 2, y); //menu.position.y = p_CurrPoint.y; y -= tab.contentSize.height + Blank; p_Layer.addChild(menu); }
private void AddCloseButton() { CCMenuItemImage pCloseItem = CCMenuItemImage.itemFromNormalImage( "Images\\close", "Images\\close", this, new SEL_MenuHandler(menuCloseCallback)); pCloseItem.position = new CCPoint(CCDirector.sharedDirector().getWinSize().width - 20, 20); CCMenu pMenu = CCMenu.menuWithItems(pCloseItem); pMenu.position = new CCPoint(0, 0); this.addChild(pMenu, 1); }
public override void ccTouchMoved(CCTouch touch, CCEvent parmevent) { CCPoint touchLocation = touch.locationInView(touch.view()); CCPoint prevLocation = touch.previousLocationInView(touch.view()); touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation); prevLocation = CCDirector.sharedDirector().convertToGL(prevLocation); CCPoint diff = new CCPoint(touchLocation.x - prevLocation.x, touchLocation.y - prevLocation.y); CCNode node = getChildByTag(1); CCPoint currentPos = node.position; node.position = new CCPoint(currentPos.x + diff.x, currentPos.y + diff.y); }
public Atlas3() { m_time = 0; CCLayerColor col = CCLayerColor.layerWithColor(new ccColor4B(128, 128, 128, 255)); addChild(col, -10); CCLabelBMFont label1 = CCLabelBMFont.labelWithString("Test", "fonts/fnt/bitmapFontTest2"); // testing anchors label1.anchorPoint = new CCPoint(0, 0); addChild(label1, 0, (int)TagSprite.kTagBitmapAtlas1); CCActionInterval fade = CCFadeOut.actionWithDuration(1.0f); CCFiniteTimeAction fade_in = fade.reverse(); CCFiniteTimeAction seq = CCSequence.actions(fade, fade_in); CCAction repeat = CCRepeatForever.actionWithAction((CCActionInterval)seq); label1.runAction(repeat); // VERY IMPORTANT // color and opacity work OK because bitmapFontAltas2 loads a BMP image (not a PNG image) // If you want to use both opacity and color, it is recommended to use NON premultiplied images like BMP images // Of course, you can also tell XCode not to compress PNG images, but I think it doesn't work as expected CCLabelBMFont label2 = CCLabelBMFont.labelWithString("Test", "fonts/fnt/bitmapFontTest2"); // testing anchors label2.anchorPoint = new CCPoint(0.5f, 0.5f); label2.Color = ccRED; addChild(label2, 0, (int)TagSprite.kTagBitmapAtlas2); label2.runAction((CCAction)(repeat.copy())); CCLabelBMFont label3 = CCLabelBMFont.labelWithString("Test", "fonts/fnt/bitmapFontTest2"); // testing anchors label3.anchorPoint = new CCPoint(1, 1); addChild(label3, 0, (int)TagSprite.kTagBitmapAtlas3); CCSize s = CCDirector.sharedDirector().getWinSize(); label1.position = new CCPoint(); label2.position = new CCPoint(s.width / 2, s.height / 2); label3.position = new CCPoint(s.width, s.height); base.schedule(step);//:@selector(step:)]; }
public SpriteBatchNodeReorderIssue744() { CCSize s = CCDirector.sharedDirector().getWinSize(); // Testing issue #744 // http://code.google.com/p/cocos2d-iphone/issues/detail?id=744 CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 15); addChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSprite sprite = CCSprite.spriteWithBatchNode(batch, new CCRect(0, 0, 85, 121)); sprite.position = (new CCPoint(s.width / 2, s.height / 2)); batch.addChild(sprite, 3); batch.reorderChild(sprite, 1); }
public override void TouchesEnded(List <CCTouch> touches) { foreach (CCTouch touch in touches) { if (touch == null) { break; } CCPoint a = touch.LocationInView; CCDirector director = CCDirector.SharedDirector; CCPoint b = director.ConvertToUi(director.ConvertToGl(a)); //CCLog("(%d,%d) == (%d,%d)", (int) a.x, (int)a.y, (int)b.x, (int)b.y ); CCLog.Log("({0},{1}) == ({2},{3})", (int)a.X, (int)a.Y, (int)b.X, (int)b.Y); } }
public SpriteFlip() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCSprite sprite1 = CCSprite.spriteWithFile("Images/grossini_dance_atlas", new CCRect(85 * 1, 121 * 1, 85, 121)); sprite1.position = (new CCPoint(s.width / 2 - 100, s.height / 2)); addChild(sprite1, 0, (int)kTagSprite.kTagSprite1); CCSprite sprite2 = CCSprite.spriteWithFile("Images/grossini_dance_atlas", new CCRect(85 * 1, 121 * 1, 85, 121)); sprite2.position = (new CCPoint(s.width / 2 + 100, s.height / 2)); addChild(sprite2, 0, (int)kTagSprite.kTagSprite2); schedule(flipSprites, 1); }
public override void onEnter() { base.onEnter(); float x, y; CCSize size = CCDirector.sharedDirector().getWinSize(); x = size.width; y = size.height; //CCMutableArray *array = [UIFont familyNames]; //for( CCString *s in array ) // NSLog( s ); CCLabelTTF label = CCLabelTTF.labelWithString("cocos2d", "Arial", 64); label.position = new CCPoint(x / 2, y / 2); addChild(label); }
public override void ccTouchesEnded(List <CCTouch> touches, CCEvent eventarg) { foreach (CCTouch touch in touches) { if (touch == null) { break; } CCPoint a = touch.locationInView(touch.view()); CCDirector director = CCDirector.sharedDirector(); CCPoint b = director.convertToUI(director.convertToGL(a)); //CCLog("(%d,%d) == (%d,%d)", (int) a.x, (int)a.y, (int)b.x, (int)b.y ); CCLog.Log("({0},{1}) == ({2},{3})", (int)a.x, (int)a.y, (int)b.x, (int)b.y); } }
public override void ccTouchesEnded(List <CCTouch> touches, CCEvent event_) { foreach (CCTouch item in touches) { if (item == null) { break; } CCPoint location = item.locationInView(item.view()); location = CCDirector.sharedDirector().convertToGL(location); addNewSpriteWithCoords(location); } base.ccTouchesEnded(touches, event_); }
public override void onEnter() { base.onEnter(); //add the menu item for back to main menu CCLabelTTF label = CCLabelTTF.labelWithString("MainMenu", "Arial", 20); CCMenuItemLabel pMenuItem = CCMenuItemLabel.itemWithLabel(label, this, new SEL_MenuHandler(MainMenuCallback)); CCMenu pMenu = CCMenu.menuWithItems(pMenuItem); CCSize s = CCDirector.sharedDirector().getWinSize(); pMenu.position = new CCPoint(0.0f, 0.0f); pMenuItem.position = new CCPoint(s.width - 50, 25); addChild(pMenu, 1); }
public CCAnimate CreateAnimateAction(CCDirector director) { var frameList = new List <CCSpriteFrame>(); for (var i = 0; i < 7; i++) { var texture = CreateCharacterTexture(director); var sprite = new CCSpriteFrame(texture, new CCRect(0, 0, texture.ContentSizeInPixels.Width, texture.ContentSizeInPixels.Height)); frameList.Add(sprite); } var animation = new CCAnimation(frameList, 0.1f); var animate = new CCAnimate(animation); return(animate); }
public void addNewSprite() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCPoint p = new CCPoint((float)(rand.NextDouble() * s.width), (float)(rand.NextDouble() * s.height)); int idx = (int)(rand.NextDouble() * 1400 / 100); int x = (idx % 5) * 85; int y = (idx / 5) * 121; CCNode node = getChildByTag((int)kTags.kTagSpriteBatchNode); CCSprite sprite = CCSprite.spriteWithTexture(m_texture1, new CCRect(x, y, 85, 121)); node.addChild(sprite); sprite.position = (new CCPoint(p.x, p.y)); CCActionInterval action; float random = (float)rand.NextDouble(); if (random < 0.20) { action = CCScaleBy.actionWithDuration(3, 2); } else if (random < 0.40) { action = CCRotateBy.actionWithDuration(3, 360); } else if (random < 0.60) { action = CCBlink.actionWithDuration(1, 3); } else if (random < 0.8) { action = CCTintBy.actionWithDuration(2, 0, -255, -255); } else { action = CCFadeOut.actionWithDuration(2); } CCActionInterval action_back = (CCActionInterval)action.reverse(); CCActionInterval seq = (CCActionInterval)(CCSequence.actions(action, action_back)); sprite.runAction(CCRepeatForever.actionWithAction(seq)); }
public override void onEnter() { base.onEnter(); CCSize size = CCDirector.sharedDirector().getWinSize(); CCLog.Log("Loading 512x512 image..."); CCSprite sprite1 = CCSprite.spriteWithFile("Images/texture512x512"); if (sprite1 != null) { CCLog.Log("OK\n"); sprite1.position = new CCPoint(size.width - 50, size.height - 50); this.addChild(sprite1); } else { CCLog.Log("Error\n"); } CCLog.Log("Loading 1024x1024 image..."); CCSprite sprite2 = CCSprite.spriteWithFile("Images/texture1024x1024"); if (sprite2 != null) { CCLog.Log("OK\n"); this.addChild(sprite2); } else { CCLog.Log("Error\n"); } // @todo // CCLog("Loading 2048x2048 image..."); // sprite = CCSprite::spriteWithFile("Images/texture2048x2048.png"); // if( sprite ) // CCLog("OK\n"); // else // CCLog("Error\n"); // // CCLog("Loading 4096x4096 image..."); // sprite = CCSprite::spriteWithFile("Images/texture4096x4096.png"); // if( sprite ) // CCLog("OK\n"); // else // CCLog("Error\n"); }
/// <summary> /// Implement CCDirector and CCScene init code here. /// </summary> /// <returns> /// true Initialize success, app continue. /// false Initialize failed, app terminate. /// </returns> public override void ApplicationDidFinishLaunching(CCApplication application) { //1280 x 768 #if WINDOWS_PHONE preferredWidth = 1280; preferredHeight = 768; #else preferredWidth = 1024; preferredHeight = 768; #endif application.PreferredBackBufferWidth = preferredWidth; application.PreferredBackBufferHeight = preferredHeight; application.PreferMultiSampling = true; application.ContentRootDirectory = "Content"; //CCSpriteFontCache.FontScale = 0.5f; //CCSpriteFontCache.RegisterFont("MarkerFelt", 22); //CCSpriteFontCache.RegisterFont("arial", 12, 24); CCDirector director = CCApplication.SharedApplication.MainWindowDirector; director.DisplayStats = true; director.AnimationInterval = 1.0 / 60; CCSize designSize = new CCSize(480, 320); if (CCDrawManager.FrameSize.Height > preferredHeight) { //CCSize resourceSize = new CCSize(960, 640); CCSize resourceSize = new CCSize(preferredWidth, preferredHeight); application.ContentSearchPaths.Add("hd"); director.ContentScaleFactor = resourceSize.Height / designSize.Height; } CCDrawManager.SetDesignResolutionSize(designSize.Width, designSize.Height, CCResolutionPolicy.ShowAll); // turn on display FPS director.DisplayStats = true; // set FPS. the default value is 1.0/60 if you don't call this director.AnimationInterval = 1.0 / 60; CCScene pScene = IntroLayer.Scene; director.RunWithScene(pScene); }
public override bool init() { if (base.init()) { CCSize size = CCDirector.sharedDirector().getWinSize(); CCLabelTTF label = CCLabelTTF.labelWithString("Layer2", "Marker Felt", 36); label.position = new CCPoint(size.width / 2, size.height / 2); addChild(label); isAccelerometerEnabled = true; schedule(switchLayer, 5.0f); return(true); } return(false); }
public SpriteBatchNodeAnchorPoint() { // small capacity. Testing resizing. // Don't use capacity=1 in your real game. It is expensive to resize the capacity CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 1); addChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSize s = CCDirector.sharedDirector().getWinSize(); CCActionInterval rotate = CCRotateBy.actionWithDuration(10, 360); CCAction action = CCRepeatForever.actionWithAction(rotate); for (int i = 0; i < 3; i++) { CCSprite sprite = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * i, 121 * 1, 85, 121)); sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2)); CCSprite point = CCSprite.spriteWithFile("Images/r1"); point.scale = 0.25f; point.position = sprite.position; addChild(point, 1); switch (i) { case 0: sprite.anchorPoint = new CCPoint(0, 0); break; case 1: sprite.anchorPoint = (new CCPoint(0.5f, 0.5f)); break; case 2: sprite.anchorPoint = (new CCPoint(1, 1)); break; } point.position = sprite.position; CCAction copy = (CCAction)(action.copy()); sprite.runAction(copy); batch.addChild(sprite, i); } }
public override void onEnter() { base.onEnter(); centerSprites(1); CCSize s = CCDirector.sharedDirector().getWinSize(); m_grossini.position = new CCPoint(-200, s.height / 2); CCActionInterval move = CCMoveBy.actionWithDuration(2, new CCPoint(s.width * 3, 0)); CCFiniteTimeAction move_back = move.reverse(); CCFiniteTimeAction seq = CCSequence.actions(move, move_back); CCAction rep = CCRepeatForever.actionWithAction((CCActionInterval)seq); m_grossini.runAction(rep); this.runAction(CCFollow.actionWithTarget(m_grossini, new CCRect(0, 0, s.width * 2 - 100, s.height))); }
public override void showCurrentTest() { CCScene pScene = null; switch (m_nCurCase) { case 0: pScene = TextureTest.scene(); break; } PerformanceTextureTest.s_nTexCurCase = m_nCurCase; if (pScene != null) { CCDirector.sharedDirector().replaceScene(pScene); } }
public override void onEnter() { base.onEnter(); CCSize s = CCDirector.sharedDirector().getWinSize(); CCMenuItemFont.FontName = "Arial"; CCMenuItemFont.FontSize = 24; CCMenuItemFont pMainItem = CCMenuItemFont.itemFromString("Back", this, backCallback); pMainItem.position = new CCPoint(s.width - 50, 25); CCMenu pMenu = CCMenu.menuWithItems(pMainItem, null); pMenu.position = new CCPoint(0, 0); addChild(pMenu); }
public virtual void ccTouchMoved(CCTouch touch, CCEvent eventer) { // If it weren't for the TouchDispatcher, you would need to keep a reference // to the touch from touchBegan and check that the current touch is the same // as that one. // Actually, it would be even more complicated since in the Cocos dispatcher // you get CCSets instead of 1 UITouch, so you'd need to loop through the set // in each touchXXX method. Debug.Assert(m_state == PaddleState.kPaddleStateGrabbed, "Paddle - Unexpected state!"); CCPoint touchPoint = touch.locationInView(touch.view()); touchPoint = CCDirector.sharedDirector().convertToGL(touchPoint); base.position = new CCPoint(touchPoint.x, base.position.y); }