/// <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, CCWindow mainWindow) { preferredWidth = 1024; preferredHeight = 768; application.PreferMultiSampling = true; application.ContentRootDirectory = "Content"; //CCSpriteFontCache.FontScale = 0.5f; //CCSpriteFontCache.RegisterFont("MarkerFelt", 22); //CCSpriteFontCache.RegisterFont("arial", 12, 24); CCSize designSize = new CCSize(480, 320); // if (CCDrawManager.FrameSize.Height > 320) // { // //CCSize resourceSize = new CCSize(960, 640); // CCSize resourceSize = new CCSize(480, 320); // application.ContentSearchPaths.Add("hd"); // director.ContentScaleFactor = resourceSize.Height / designSize.Height; // } CCScene.SetDefaultDesignResolution(designSize.Width, designSize.Height, CCSceneResolutionPolicy.ShowAll); // turn on display FPS mainWindow.DisplayStats = true; //mainWindow.StatsScale = 2; CCScene pScene = GoblinLayer.Scene(mainWindow); mainWindow.RunWithScene(pScene); }
public static CCScene Scene(CCWindow window) { // 'scene' is an autorelease object. var scene = new CCScene(window); // 'layer' is an autorelease object. var layer = new GoblinLayer(); // add layer as a child to scene scene.AddChild(layer); // return the scene return(scene); }
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 = 480f; float desiredHeight = 320f; // This will set the world bounds to be (0,0, w, h) // CCSceneResolutionPolicy.ShowAll will ensure that the aspect ratio is preserved CCScene.SetDefaultDesignResolution(desiredWidth, desiredHeight, CCSceneResolutionPolicy.ShowAll); // 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; } CCScene scene = new CCScene(mainWindow); var gameLayer = new GoblinLayer(); scene.AddChild(gameLayer); mainWindow.RunWithScene(scene); }
public SpineBoyLayer() { CCMenuItemFont.FontName = "arial"; CCMenuItemFont.FontSize = 12; labelBones = new CCMenuItemFont("B = Toggle Debug Bones", (obj) => { skeletonNode.DebugBones = !skeletonNode.DebugBones; } ) { AnchorPoint = CCPoint.AnchorMiddleLeft }; labelSlots = new CCMenuItemFont("M = Toggle Debug Slots", (obj) => { skeletonNode.DebugSlots = !skeletonNode.DebugSlots; } ) { AnchorPoint = CCPoint.AnchorMiddleLeft }; labelTimeScaleUp = new CCMenuItemFont("Up - TimeScale +", (obj) => { skeletonNode.TimeScale += 0.1f; } ) { AnchorPoint = CCPoint.AnchorMiddleLeft }; labelTimeScaleDown = new CCMenuItemFont("Down - TimeScale -", (obj) => { skeletonNode.TimeScale -= 0.1f; } ) { AnchorPoint = CCPoint.AnchorMiddleLeft }; labelScene = new CCMenuItemFont("G = Goblins", (obj) => { Director.ReplaceScene(GoblinLayer.Scene(Window)); } ) { AnchorPoint = CCPoint.AnchorMiddleLeft }; labelJump = new CCMenuItemFont("J = Jump", (obj) => { // I truthfully do not know if this is how it is done or not skeletonNode.SetAnimation(0, "jump", false); skeletonNode.AddAnimation(0, "run", true); } ) { AnchorPoint = CCPoint.AnchorMiddleLeft }; menu = new CCMenu(labelBones, labelSlots, labelTimeScaleUp, labelTimeScaleDown, labelJump, labelScene); menu.AlignItemsVertically(); AddChild(menu); String name = @"spineboy"; skeletonNode = new CCSkeletonAnimation(name + ".json", name + ".atlas", 0.25f); skeletonNode.SetMix("walk", "jump", 0.2f); skeletonNode.SetMix("jump", "run", 0.2f); skeletonNode.SetAnimation(0, "walk", true); TrackEntry jumpEntry = skeletonNode.AddAnimation(0, "jump", false, 3); skeletonNode.AddAnimation(0, "run", true); skeletonNode.Start += Start; skeletonNode.End += End; skeletonNode.Complete += Complete; skeletonNode.Event += Event; AddChild(skeletonNode); var listener = new CCEventListenerTouchOneByOne(); listener.OnTouchBegan = (touch, touchEvent) => { if (!skeletonNode.DebugBones) { skeletonNode.DebugBones = true; } else if (skeletonNode.TimeScale == 1) { skeletonNode.TimeScale = 0.3f; } return(true); }; AddEventListener(listener, this); var keyListener = new CCEventListenerKeyboard(); keyListener.OnKeyPressed = (keyEvent) => { switch (keyEvent.Keys) { case CCKeys.B: skeletonNode.DebugBones = !skeletonNode.DebugBones; break; case CCKeys.M: skeletonNode.DebugSlots = !skeletonNode.DebugSlots; break; case CCKeys.Up: skeletonNode.TimeScale += 0.1f; break; case CCKeys.Down: skeletonNode.TimeScale -= 0.1f; break; case CCKeys.G: Director.ReplaceScene(GoblinLayer.Scene(Window)); break; case CCKeys.J: // I truthfully do not know if this is how it is done or not skeletonNode.SetAnimation(0, "jump", false); skeletonNode.AddAnimation(0, "run", true); break; } }; AddEventListener(keyListener, this); }
public static CCScene Scene(CCWindow window) { // 'scene' is an autorelease object. var scene = new CCScene(window); // 'layer' is an autorelease object. var layer = new GoblinLayer(); // add layer as a child to scene scene.AddChild(layer); // return the scene return scene; }