/* ============================================================= * Reference OnTouchesBegan: externally sourced code * Purpose: to create touch logic on the sprite buttons in the level select screen * Date: 28/10/2018 * Source: stackoverflow * Author: jaybers * url: https://stackoverflow.com/questions/33168953/android-game-drag-one-image-at-a-time-into-screen-from-a-group-of-images * Adaption required: provide links to each level as per the corresponding button * ============================================================== */ bool OnTouchesBegan(CCTouch touch, CCEvent touchEvent) { CCSprite caller = touchEvent.CurrentTarget as CCSprite; currentSpriteTouched = null; if (caller == button1) { if (button1.BoundingBoxTransformedToWorld.ContainsPoint(touch.Location)) { //System.Diagnostics.Debug.WriteLine("Button pressed"); Window.DefaultDirector.ReplaceScene(LevelOne.LvlOneScene(Window)); return(true); } else if (button2.BoundingBoxTransformedToWorld.ContainsPoint(touch.Location)) { Window.DefaultDirector.ReplaceScene(LevelTwo.LvlTwoScene(Window)); return(true); } else if (button3.BoundingBoxTransformedToParent.ContainsPoint(touch.Location)) { Window.DefaultDirector.ReplaceScene(LevelThree.LvlThreeScene(Window)); return(true); } else { return(false); } } else { return(false); } }
//reference to the scene for navigation purposes. The level select screen uses this to navigate to this level public static CCScene LvlOneScene(CCWindow mainWindow) { var scene = new CCScene(mainWindow); var layer = new LevelOne(); scene.AddChild(layer); return(scene); }