void LoadGame(object sender, EventArgs e) { var nativeGameView = sender as CCGameView; if (nativeGameView != null) { var contentSearchPaths = new List <string> () { "Fonts", "Sounds" }; CCSizeI viewSize = nativeGameView.ViewSize; CCSizeI designResolution = nativeGameView.DesignResolution; // 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 (designResolution.Width < viewSize.Width) { contentSearchPaths.Add("Images/Hd"); CCSprite.DefaultTexelToContentSizeRatio = 2.0f; } else { contentSearchPaths.Add("Images/Ld"); CCSprite.DefaultTexelToContentSizeRatio = 1.0f; } nativeGameView.ContentManager.SearchPaths = contentSearchPaths; CCScene gameScene = new CCScene(nativeGameView); var gameLayer = new MainLayer(); gameLayer.Schedule(); gameScene.AddLayer(gameLayer); nativeGameView.RunWithScene(gameScene); } }
public static void LoadGame(object sender, EventArgs e) { CCGameView gameView = sender as CCGameView; if (gameView != null) { var contentSearchPaths = new List <string>() { "Fonts", "Sounds" }; CCSizeI viewSize = gameView.ViewSize; // Set world dimensions gameView.DesignResolution = new CCSizeI(viewSize.Width, viewSize.Height); // 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 (width < viewSize.Width) //{ // contentSearchPaths.Add("Images/Hd"); // CCSprite.DefaultTexelToContentSizeRatio = 2.0f; //} //else //{ contentSearchPaths.Add("Images/Ld"); CCSprite.DefaultTexelToContentSizeRatio = 2.0f; //} gameView.ContentManager.SearchPaths = contentSearchPaths; CCAudioEngine.SharedEngine.PreloadEffect("pop"); CCScene gameScene = new CCScene(gameView); gameScene.AddLayer(new MenuLayer()); gameView.RunWithScene(gameScene); } }
void LoadGame(object sender, EventArgs e) { CCGameView gameView = sender as CCGameView; if (gameView != null) { var contentSearchPaths = new List <string>() { "Fonts", "Sounds" }; CCSizeI viewSize = gameView.ViewSize; Display display = WindowManager.DefaultDisplay; Point Size = new Point(); display.GetSize(Size); int width = Size.X - 1; int height = Size.Y - 1; gameView.DesignResolution = new CCSizeI(width, height); if (width < viewSize.Width) { contentSearchPaths.Add("Images/Hd"); CCSprite.DefaultTexelToContentSizeRatio = 2.0f; } else { contentSearchPaths.Add("Images/Ld"); CCSprite.DefaultTexelToContentSizeRatio = 1.0f; } gameView.ContentManager.SearchPaths = contentSearchPaths; CCScene gameScene = new CCScene(gameView); gameScene.AddLayer(new GameLayer(this, width, height, IntentType, NrTel, GameId)); gameView.RunWithScene(gameScene); } }
private void LoadGame(object sender, EventArgs e) { var gameView = sender as CCGameView; if (gameView != null) { gameView.DesignResolution = new CCSizeI(600, 600); gameView.ContentManager.SearchPaths = new List <string>() { "", "hd", "animations", "fonts", "sounds", "images" }; CCScene gameScene = new CCScene(gameView); this.game = new GameLayer(new CCSize(600, 600)); gameScene.AddLayer(game); gameView.RunWithScene(gameScene); Device.BeginInvokeOnMainThread(() => { this.moveLabel.Text = $"Press \"Next\" to start"; }); } }
public static CCScene GameStartLayerScene(CCGameView mainWindow, float _dynamicWidth, float _dynamicHeight, string json, GamePage gamePage) { var scene = new CCScene(mainWindow); IconStorageObject jsonObject = null; if (json != "") { try { jsonObject = JsonConvert.DeserializeObject <IconStorageObject>(json); } catch { jsonObject = null; } } var layer = new GameLayer(_dynamicWidth, _dynamicHeight, jsonObject, gamePage); scene.AddLayer(layer); return(scene); }
void LoadGame(object sender, EventArgs e) { CCGameView gameView = sender as CCGameView; if (gameView != null) { var contentSearchPaths = new List <string>() { "Fonts", "Sounds", "Images" }; int width = 512; int height = 384; // Set world dimensions gameView.DesignResolution = new CCSizeI(width, height); gameView.ContentManager.SearchPaths = contentSearchPaths; CCScene gameScene = new CCScene(gameView); gameScene.AddLayer(new GameLayer()); gameView.RunWithScene(gameScene); } }
public void ConstructGameScene(CCGameView nativeGameView) { gameScene = new CCScene(nativeGameView); string json = GetBoards("IconBoard"); IconStorageObject jsonObject = null; if (json != "") { try { jsonObject = JsonConvert.DeserializeObject <IconStorageObject>(json); } catch { jsonObject = null; } } mLayer = new GameLayer(width, height, jsonObject, this); gameScene.AddLayer(mLayer); }
void HandleViewCreated(object sender, EventArgs e) { //loads the view var ccGView = sender as CCGameView; var contentSearchPaths = new List <string>() { "Resources", "Assets" }; ccGView.ContentManager.SearchPaths = contentSearchPaths; if (ccGView != null) { //if the view is created then load all the assets ccGView.DesignResolution = new CCSizeI(App.Width, App.Height); _scene = new CCScene(ccGView); _layer = new CCLayer(); _scene.AddLayer(_layer); //ship ship = new Ship(this); ship.PositionX = ((App.Width) / 2); ship.PositionY = ((App.Height) / 4); _layer.AddChild(ship); //starts are generated as particles var stars = new CCParticleRain(new CCPoint(200, App.Height)) { StartSize = 1, Color = CCColor3B.White, Speed = 250, SourcePosition = new CCPoint(0.0f, -10.0f), }; stars.StartColor = new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f); _layer.AddChild(stars); var faststars = new CCParticleRain(new CCPoint(200, App.Height)) { StartSize = 1, Speed = 500, SourcePosition = new CCPoint(0.0f, -10.0f), }; faststars.StartColor = new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f); _layer.AddChild(faststars); var slowstars = new CCParticleRain(new CCPoint(200, App.Height)) { TotalParticles = 1, StartSize = 2, Color = CCColor3B.Blue, Speed = 50, SourcePosition = new CCPoint(0.0f, -10.0f), }; faststars.StartColor = new CCColor4F(0.0f, 0.0f, 1.0f, 1.0f); _layer.AddChild(slowstars); //the fire trailing the rocket fire = new CCParticleFire(new CCPoint(((App.Width) / 2), ((App.Height) / 4))) { StartSize = 1, Angle = 270, Speed = 100, SourcePosition = new CCPoint(0.0f, -10.0f), }; _layer.AddChild(fire); //the handlers for the screne being touched var touchEvent = new CCEventListenerTouchAllAtOnce(); touchEvent.OnTouchesEnded = OnTouchesEnded; _layer.AddEventListener(touchEvent); //asteroid asteroids = new List <Asteroid>(); void HandleAsteroidCreated(Asteroid newAsteroid) { _layer.AddChild(newAsteroid); asteroids.Add(newAsteroid); } AsteroidFactory.Self.AsteroidCreated += HandleAsteroidCreated; //psyche psyche = new Psyche(); psyche.PositionX = 200; psyche.PositionY = 4000; psyche.VelocityY = -50; _layer.AddChild(psyche); ccGView.RunWithScene(_scene); } }
/// <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())); }) )); }
private void SetupGameScene(CCScene gameScene) { gameScene.AddLayer(_layer); _layer.Schedule(Update); }
private void SetupGameScene(CCScene gameScene) { gameScene.AddLayer(_layer); RedrawParticles(); }