Пример #1
0
        private void HandleViewCreated(object sender, EventArgs e)
        {
            var ccGView = sender as CCGameView;

            if (ccGView != null)
            {
                ccGView.DesignResolution = new CCSizeI(App.Width, App.Height);

                _scene = new ParticlesScene(ccGView);

                var touchEvent = new CCEventListenerTouchOneByOne();

                touchEvent.OnTouchBegan = (touch, _event) =>
                {
                    _scene.DrawParticle(touch.LocationOnScreen);
                    return(true);
                };

                touchEvent.OnTouchMoved = (touch, _event) =>
                {
                    _scene.DrawParticle(touch.LocationOnScreen);
                };

                _scene.AddEventListener(touchEvent);

                ccGView.RunWithScene(_scene);
            }
        }
Пример #2
0
        private void HandleViewCreated(object sender, EventArgs e)
        {
            if (!(sender is CCGameView gameView))
            {
                return;
            }

            // This sets the game "world" resolution to 100x100:
            gameView.DesignResolution = _viewResolution;

            // GameScene is the root of the CocosSharp rendering hierarchy:
            CCScene gameScene = new CCScene(gameView);

            SetupGameScene(gameScene);

            // Register for touch events
            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.OnTouchBegan += OnTouchBegan;
            touchListener.OnTouchMoved += OnTouchMoved;

            _layer.AddEventListener(touchListener, _layer);

            // Starts CocosSharp:
            gameView.RunWithScene(gameScene);
        }
Пример #3
0
        public GameScene(CCGameView gameView) : base(gameView)
        {
            layer = new GameLayer();
            this.AddLayer(layer);

            fireworks     = new CCParticleFireworks(CCPoint.Zero);
            explosion     = new CCParticleExplosion(CCPoint.Zero);
            startLocation = CCPoint.Zero;

            fireworks.StartColor = new CCColor4F(CCColor3B.Yellow);
            fireworks.Position   = new CCPoint(App.ScreenWidth / 1.5f, App.ScreenHeight / 1.5f);
            layer.AddChild(fireworks);

            explosion.StartColor = new CCColor4F(CCColor3B.Red);
            explosion.EndColor   = new CCColor4F(CCColor3B.Black);
            explosion.Position   = new CCPoint(App.ScreenWidth / 3f, App.ScreenHeight / 3f);

            layer.AddChild(explosion);

            //Device.StartTimer(TimeSpan.FromMilliseconds(2000), HandleFunc);

            var touchEvent = new CCEventListenerTouchOneByOne();

            touchEvent.OnTouchBegan = (CCTouch arg1, CCEvent arg2) => {
                CCPoint newLocation =
                    new CCPoint(arg1.LocationOnScreen.X * xRatio, App.ScreenHeight - arg1.LocationOnScreen.Y * yRatio);
                startLocation = newLocation;
                return(HandleFunc());
            };
            // AddEventListener(touchEvent);
        }
Пример #4
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            GameCore                 = new Field();
            GameCore.CellDeleted    += OnCellDeleted;
            GameCore.MovedDown      += OnMovedDown;
            GameCore.CellCreated    += OnCellCreated;
            GameCore.NoMoreMatches  += OnNoMoreMatches;
            GameCore.PointsChanged  += OnScoreChanged;
            GameCore.BonusCreated   += OnBonusCreated;
            GameCore.Detonated      += OnDetonated;
            GameCore.ActivatedBonus += OnActivatedBonus;

            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.OnTouchBegan = TouchBegan;
            AddEventListener(touchListener, this);

            Scene.SceneResolutionPolicy = CCSceneResolutionPolicy.ShowAll;
            places = new CellSprite[Field.SIZE, Field.SIZE];
            gems   = new List <GemSprite>();

            CreateField();
            AddScoreLabel();
            AddTimerLabel();
            InitTimer();
            InitColorsCountChangeUI();
        }
Пример #5
0
        public bool initWithEntryID(int entryId)
        {
            // Register Touch Event
            touchListener = new CCEventListenerTouchOneByOne();
            touchListener.IsSwallowTouches = true;

            touchListener.OnTouchBegan = onTouchBegan;
            touchListener.OnTouchMoved = onTouchMoved;
            touchListener.OnTouchEnded = onTouchEnded;

            AddEventListener(touchListener, -10);

            var keyboardListener = new CCEventListenerKeyboard();

            keyboardListener.OnKeyPressed  = onKeyPressed;
            keyboardListener.OnKeyReleased = onKeyReleased;

            AddEventListener(keyboardListener);



            m_entry = TestEntries.TestList[entryId];
            m_test  = m_entry.CreateFcn();

            return(true);
        }
Пример #6
0
        protected override void AddedToScene()
        {
            base.AddedToScene();
            backButton = new CCLabel("もどる", "arial", 40)
            {
                Position = new CCPoint(GlobalGameData.Window_Center_X, 430)
            };
            AddChild(backButton);

            var t = new CCEventListenerTouchOneByOne();

            {
                t.IsSwallowTouches = true;
                t.OnTouchBegan     = (_, __) => true;
                t.OnTouchEnded     = (touch, __) =>
                {
                    if (backButton.BoundingBox.ContainsPoint(touch.Location))
                    {
                        RemoveEventListener(t);
                        RemoveFromParent(true);
                    }
                };
            };

            AddEventListener(t, -1);
        }
Пример #7
0
        //CONSTRUCTOR 2
        public OldPipelineProtocolsACK(int seqnum, int tc, int small) : base()
        {
            this.small     = true;
            corrupt        = false;
            lost           = false;
            ignore         = true;
            stopEverything = false;
            this.id        = count;
            count++;
            this.seqnum = seqnum;
            touchCount  = 5; //unable to react to touch

            this.sprite             = new CCSprite();
            this.sprite.AnchorPoint = AnchorPoint = new CCPoint(0, 0);
            sprite.Color            = CCColor3B.Green;                                                              //EXtra line of code for Android.....since I didn't find out how to access the png in Android. It crashed every single time
            CCSpriteFrame whiteFrame = new CCSpriteFrame(new CCTexture2D("myWhite.png"), new CCRect(0, 0, 20, 25)); //x and y pos in the sprite image and width and heigth of the sprite

            this.sprite.SpriteFrame = whiteFrame;
            this.AddChild(sprite);

            touchListener = new CCEventListenerTouchOneByOne();
            touchListener.OnTouchBegan = OnTouchBegan;
            AddEventListener(touchListener, this);

            Schedule(Process);             // prediefined method that takes an Action and schedules it to run for every cycle
        }
Пример #8
0
 public ButtonEventDispatcher()
 {
     Listener = new CCEventListenerTouchOneByOne()
     {
         OnTouchBegan = OnTouchBegan,
         OnTouchEnded = OnTouchEnded,
     };
 }
 public void MakeListener()
 {
     mListener = new CCEventListenerTouchOneByOne();
     mListener.IsSwallowTouches = true;
     mListener.OnTouchBegan     = OnTouchBegan;
     mListener.OnTouchEnded     = OnTouchesEnded;
     mListener.OnTouchMoved     = HandleTouchesMoved;
 }
Пример #10
0
 public virtual void Init(float width, float height)
 {
     EventListener = new CCEventListenerTouchOneByOne()
     {
         OnTouchBegan = OnTouchBegan,
         OnTouchEnded = OnTouchEnded,
     };
     ContentSize = new CCSize(width, height);
 }
Пример #11
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCRect visibleBounds = Layer.VisibleBoundsWorldspace;

            // Laying out content based on window size
            closeMenu.Position     = CCPoint.Zero;
            closeMenuItem.Position = new CCPoint(visibleBounds.Size.Width - 40, visibleBounds.Size.Height - 40);

#if !PSM && !WINDOWS_PHONE
            versionLabel.AnchorPoint = CCPoint.AnchorUpperLeft;
            versionLabel.Position    = new CCPoint(10.0f, visibleBounds.Size.Height);
#endif
            testListMenu.ContentSize = new CCSize(visibleBounds.Size.Width, (testCases.Count + 1) * LINE_SPACE);

            int i = 0;
            foreach (CCMenuItem testItem in testListMenuItems)
            {
                testItem.Position = new CCPoint(visibleBounds.Size.Center.X, (visibleBounds.Top().Y - (i + 1) * LINE_SPACE));
                i++;
            }

            #if XBOX || OUYA
            // Center the menu on the first item so that it is
            // in the center of the screen
            homePosition = new CCPoint(0f, visibleBounds.Size.Height / 2f + LINE_SPACE / 2f);
            lastPosition = new CCPoint(0f, homePosition.Y - (testListMenuItems.Count - 1) * LINE_SPACE);
            #else
            homePosition = curPos;
            #endif

            testListMenu.Position = homePosition;

            // Add listeners
            #if !XBOX && !OUYA
            var touchListener = new CCEventListenerTouchOneByOne();
            touchListener.IsSwallowTouches = true;
            touchListener.OnTouchBegan     = OnTouchBegan;
            touchListener.OnTouchMoved     = OnTouchMoved;

            AddEventListener(touchListener);

            var mouseListener = new CCEventListenerMouse();
            mouseListener.OnMouseScroll = OnMouseScroll;
            AddEventListener(mouseListener);
            #endif

            #if WINDOWS || WINDOWSGL || MACOS
            EnableGamePad();
            #endif

            // set the first one to have the selection highlight
            currentItemIndex = 0;
            //SelectMenuItem();
        }
Пример #12
0
        public GameTouchHandler(GameLayer gameLayer, HexMexCamera hexMexCamera)
        {
            GameLayer    = gameLayer;
            HexMexCamera = hexMexCamera;
            var eventListener = new CCEventListenerTouchOneByOne {
                IsEnabled = true, OnTouchBegan = OnTouchBegan, OnTouchCancelled = OnTouchCancelled, OnTouchEnded = OnTouchEnded, OnTouchMoved = OnTouchMoved
            };

            gameLayer.AddEventListener(eventListener);
        }
Пример #13
0
        protected override void AddedToScene()
        {
            base.AddedToScene();
            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.OnTouchBegan = OnTouchBegan;
            touchListener.OnTouchEnded = OnTouchEnded;

            AddEventListener(touchListener);
        }
Пример #14
0
        public IsoNodePosition() : base("TileMaps/iso-test-zorder")
        {
            drawNode = new CCDrawNode();
            tileLayersContainer.AddChild(drawNode);

            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.OnTouchBegan = OnTouchBegan;

            AddEventListener(touchListener);
        }
Пример #15
0
        public TMXStaggeredMapTest() : base("TileMaps/staggered_test")
        {
            drawNode = new CCDrawNode();
            tileLayersContainer.AddChild(drawNode);

            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.OnTouchBegan = OnTouchBegan;

            AddEventListener(touchListener);
        }
Пример #16
0
        public KeyboardNotificationLayer()
        {
            // Register Touch Event
            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.IsSwallowTouches = true;

            touchListener.OnTouchBegan = OnTouchBegan;
            touchListener.OnTouchEnded = OnTouchEnded;

            AddEventListener(touchListener);
        }
Пример #17
0
            void AttachListener()
            {
                // Register Touch Event
                var listener = new CCEventListenerTouchOneByOne();

                listener.IsSwallowTouches = true;

                listener.OnTouchBegan     = OnTouchBegan;
                listener.OnTouchEnded     = OnTouchEnded;
                listener.OnTouchCancelled = OnTouchCancelled;

                AddEventListener(listener, this);
            }
Пример #18
0
        public MenuLayer1()
        {
            // Register Touch Event
            touchListener = new CCEventListenerTouchOneByOne();
            touchListener.IsSwallowTouches = true;

            touchListener.OnTouchBegan     = onTouchBegan;
            touchListener.OnTouchMoved     = onTouchMoved;
            touchListener.OnTouchEnded     = onTouchEnded;
            touchListener.OnTouchCancelled = onTouchCancelled;

            AddEventListener(touchListener, 1);
        }
Пример #19
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            eventListener = new CCEventListenerTouchOneByOne()
            {
                IsSwallowTouches = true,
                OnTouchBegan     = (touch, __) =>
                {
                    //if (_backGround?.BoundingBox.ContainsPoint(touch.Location) ?? false)
                    //{
                    //    return false;
                    //}
                    return(true);
                },
                OnTouchEnded = (_, __) =>
                {
                    //                    Close();
                },
            };


            AddChild(layer, this.ZOrder);
            this.AddEventListener(eventListener, -100);
//            SetListenerPriority(eventListener, -50);
            CCLog.Log($"[OreOreLog]:[YesNoDialog]{this.ZOrder}");

            //var lll = new CCLabel("たいとるもどる", "Arial", 30)
            //{
            //    Position = new CCPoint(400, 500),
            //};

            //AddChild(lll);

            //var ls = new CCEventListenerTouchOneByOne()
            //{
            //    OnTouchBegan = (_, __) => true,
            //    OnTouchEnded = (_, __) =>
            //    {
            //        if (lll.BoundingBox.ContainsPoint(_.Location))
            //        {
            //            var scene = new CCScene(GameView);
            //            scene.AddChild(new Layers.Loading(new TitleAssetsLoader()));
            //            Director.ReplaceScene(scene);
            //            Close();
            //        }
            //    },

            //};
//            AddEventListener(ls, -1000);
        }
Пример #20
0
        //adds buttons and text to the screen, and adds and registers a touchListener
        protected override void AddedToScene()
        {
            base.AddedToScene();
            CCRect bounds = VisibleBoundsWorldspace;

            CreateButtons();
            CreateText();

            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.IsSwallowTouches = true;
            touchListener.OnTouchBegan     = this.OnTouchesBegan;
            AddEventListener(touchListener, button1);
        }
Пример #21
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            // Register Touch Event
            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.IsSwallowTouches = true;

            touchListener.OnTouchBegan = OnTouchBegan;
            touchListener.OnTouchEnded = OnTouchEnded;

            AddEventListener(touchListener);
        }
Пример #22
0
        public override void OnEnter()
        {
            base.OnEnter();

            // Register Touch Event
            var listener = new CCEventListenerTouchOneByOne();

            listener.IsSwallowTouches = true;

            listener.OnTouchBegan = onTouchBegan;
            listener.OnTouchMoved = onTouchMoved;
            listener.OnTouchEnded = onTouchEnded;

            AddEventListener(listener);
        }
Пример #23
0
        public TMXHexTest() : base("TileMaps/hexa-test1")
        {
            CCLayerColor color = new CCLayerColor(new CCColor4B(64, 64, 64, 255));

            AddChild(color, -1);

            drawNode = new CCDrawNode();
            tileLayersContainer.AddChild(drawNode);

            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.OnTouchBegan = OnTouchBegan;

            AddEventListener(touchListener);
        }
Пример #24
0
        public bool initWithEntryID(int entryId)
        {
            m_entryID = entryId;

            // Register Touch Event
            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.IsSwallowTouches = false;

            touchListener.OnTouchBegan = onTouchBegan;
            touchListener.OnTouchMoved = onTouchMoved;

            AddEventListener(touchListener);

            return(true);
        }
Пример #25
0
        public bool initWithEntryID(int entryId)
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            m_entryID = entryId;

            // Register Touch Event
            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.IsSwallowTouches = true;

            touchListener.OnTouchBegan = onTouchBegan;
            touchListener.OnTouchMoved = onTouchMoved;

            EventDispatcher.AddEventListener(touchListener, this);

            Box2DView view = Box2DView.viewWithEntryID(entryId);

            AddChild(view, 0, kTagBox2DNode);
            view.Scale       = 10;
            view.AnchorPoint = new CCPoint(0, 0);
            view.Position    = new CCPoint(s.Width / 2, s.Height / 4);
            //#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
            //    CCLabelBMFont* label = new CCLabelBMFont(view.title().c_str(),  "fonts/arial16.fnt");
            //#else
            CCLabelTtf label = new CCLabelTtf(view.title(), "arial", 28);

            //#endif
            AddChild(label, 1);
            label.Position = new CCPoint(s.Width / 2, s.Height - 50);

            CCMenuItemImage item1 = new CCMenuItemImage("Images/b1", "Images/b2", backCallback);
            CCMenuItemImage item2 = new CCMenuItemImage("Images/r1", "Images/r2", restartCallback);
            CCMenuItemImage item3 = new CCMenuItemImage("Images/f1", "Images/f2", nextCallback);

            CCMenu menu = new CCMenu(item1, item2, item3);

            menu.Position  = CCPoint.Zero;
            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);

            return(true);
        }
Пример #26
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            initPhysics();

            // Use the bounds to layout the positioning of our drawable assets
            var bounds = VisibleBoundsWorldspace;

            // position the label on the center of the screen
            //labelScore.Position = new CCPoint(80, bounds.Size.Height - 16);

            //labelLives.Position = new CCPoint(bounds.Size.Width - 100, bounds.Size.Height - 16);

            _progressTimer.Position = new CCPoint(bounds.Center.X, bounds.Center.Y);
            //_progressTimer.Midpoint = new CCPoint(0.5f, 0.5f);
            //_progressTimer.ReverseDirection = true;

            _cordinatesGenerator = new CordinatesGenerator(bounds);
            animator             = new Animator(_cordinatesGenerator);

            _cordinatesGenerator.SetSquaresCordinates(_squares);

            //_soundButton.Position = new CCPoint(bounds.Size.Width - 90, bounds.Size.Height - 90);
            //_pauseButton.Position = new CCPoint(90, bounds.Size.Height - 90);

            _cordinatesGenerator.SetSoundPosition(_soundButton);
            _cordinatesGenerator.SetPausePosition(_pauseButton);



            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.IsSwallowTouches = true;
            touchListener.OnTouchBegan     = this.OnTouchesBegan;
            //AddEventListener(touchListener, this);
            AddEventListener(touchListener, _redPlay.Current);
            AddEventListener(touchListener.Copy(), _greenPlay.Current);
            AddEventListener(touchListener.Copy(), _yellowPlay.Current);
            AddEventListener(touchListener.Copy(), _bluePlay.Current);

            FirstRun();
        }
Пример #27
0
        public override void OnEnter()
        {
            base.OnEnter();
            var listener = new CCEventListenerTouchOneByOne();

            listener.IsSwallowTouches = true;

            listener.OnTouchBegan = (CCTouch touch, CCEvent touchEvent) =>
            {
                var    locationInNode = touch.Location;//     Layer.ScreenToWorldspace(touch.LocationOnScreen);
                var    s    = ContentSize;
                CCRect rect = BoundingBoxTransformedToWorld;

                if (rect.ContainsPoint(locationInNode))
                {
                    Color = CCColor3B.Red;
                    return(true);
                }
                return(false);
            };

            listener.OnTouchEnded = (CCTouch touch, CCEvent rouchEvent) =>
            {
                Color = CCColor3B.White;

                if (IsRemoveListenerOnTouchEnded)
                {
                    RemoveEventListener(Listener);
                }
            };

            if (FixedPriority != 0)
            {
                AddEventListener(listener, FixedPriority);
            }
            else
            {
                AddEventListener(listener);
            }

            Listener = listener;
        }
Пример #28
0
        public override void OnEnter()
        {
            base.OnEnter();
            Schedule(Step);

#if WINDOWS || MACOS
            //AccelerometerEnabled = false;
            //TouchEnabled = true;
            //TouchMode = CCTouchMode.OneByOne;
            touchListener = new CCEventListenerTouchOneByOne();
            touchListener.OnTouchBegan = OnTouchBegan;
            touchListener.OnTouchMoved = OnTouchMoved;
            touchListener.OnTouchEnded = OnTouchEnded;
#else
            AccelerometerEnabled = true;
            SingleTouchEnabled   = false;
#endif
            //IsAccelerometerEnabled = true;

            // CCDirector.SharedDirector.Accelerometer.SetDelegate(new AccelerometerDelegate(DidAccelerate);
            StartGame();
        }
Пример #29
0
        public CocoPiece(Piece piece, CCSpriteFrame cCSpriteFrame)
            : base(cCSpriteFrame)
        {
            this.ScaleX                 = 118 / cCSpriteFrame.Texture.ContentSizeInPixels.Width + 0.1f;
            this.ScaleY                 = 118 / cCSpriteFrame.Texture.ContentSizeInPixels.Width + 0.1f;
            this.piece                  = piece;
            this.piece.PieceTaken      += OnPieceTaken;
            this.piece.PositionUpdated += (s, p) =>
            {
                this.Position = p.GetPoint(this.piece.Board.Size);
            };

            AnchorPoint   = CCPoint.AnchorMiddle;
            Position      = this.GetPosition();
            touchListener = new CCEventListenerTouchOneByOne();

            touchListener.OnTouchMoved     = Touch;
            touchListener.OnTouchBegan     = ToucheBegan;
            touchListener.OnTouchEnded     = TouchEnded;
            touchListener.OnTouchCancelled = TouchCanceled;
            AddEventListener(touchListener, this);
        }
Пример #30
0
        public bool initWithEntryID(int entryId)
        {
            //TouchEnabled = true;

            Schedule(tick);

            m_entry = TestEntries.TestList[entryId];
            m_test  = m_entry.CreateFcn();
            m_test.Initialize();

            // Register Touch Event
            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.IsSwallowTouches = true;

            touchListener.OnTouchBegan = onTouchBegan;
            touchListener.OnTouchMoved = onTouchMoved;
            touchListener.OnTouchEnded = onTouchEnded;

            EventDispatcher.AddEventListener(touchListener, this);


            return(true);
        }