コード例 #1
0
 public SneakyButtonControl(CCRect rect, int id)
 {
     status       = true; //defaults to enabled
     value        = false;
     active       = false;
     isHoldable   = true;
     isToggleable = false;
     radius       = 32.0f;
     rateLimit    = 1.0f / 120.0f;
     Position     = rect.Origin;
     ID           = id;
     buttonEvent  = new CCEventCustom(SneakyPanelControl.BUTTON_LISTENER_ID);
 }
コード例 #2
0
 public SneakyButtonControl(CCRect rect, int id, CCDrawNode drawNode )
 {
     this.drawNode = drawNode;
     status = true; //defaults to enabled
     value = false;
     active = false;
     isHoldable = true;
     isToggleable = false;
     radius = 32.0f;
     rateLimit = 1.0f / 120.0f;
     Position = rect.Origin;
     ID = id;
     buttonEvent = new CCEventCustom(SneakyPanelControl.BUTTON_LISTENER_ID);
 }
コード例 #3
0
 void OnEvent1(CCEventCustom customEvent)
 {
     label1.Text = string.Format("Update: {0}", count1++);
 }
コード例 #4
0
 void OnEvent2(CCEventCustom customEvent)
 {
     label2.Text = string.Format("Visit: {0}", count2++);
 }
コード例 #5
0
        public override void OnEnter()
        {
            base.OnEnter();

            var origin = Layer.VisibleBoundsWorldspace.Origin;
            var size   = Layer.VisibleBoundsWorldspace.Size;

            //MenuItemFont::setFontSize(20);

            var statusLabel = new CCLabelTtf("No custom event 1 received!", "", 20);

            statusLabel.Position = origin + new CCPoint(size.Width / 2, size.Height - 90);
            AddChild(statusLabel);

            listener = new CCEventListenerCustom("game_custom_event1", (customEvent) =>
            {
                var str          = "Custom event 1 received, ";
                var buf          = customEvent.UserData;
                str             += buf;
                str             += " times";
                statusLabel.Text = str;
            });

            AddEventListener(listener, 1);
            var count    = 0;
            var sendItem = new CCMenuItemFont("Send Custom Event 1", (sender) =>
            {
                ++count;
                var userData = string.Format("{0}", count);
                DispatchEvent("game_custom_event1", userData);
            });

            sendItem.Position = origin + size.Center;

            var statusLabel2 = new CCLabelTtf("No custom event 2 received!", "", 20);

            statusLabel2.Position = origin + new CCPoint(size.Width / 2, size.Height - 120);
            AddChild(statusLabel2);

            listener2 = new CCEventListenerCustom("game_custom_event2", (customEvent) =>
            {
                statusLabel2.Text = string.Format("Custom event 2 received, {0} times", customEvent.UserData);
            });

            AddEventListener(listener2, 1);

            var count2    = 0;
            var sendItem2 = new CCMenuItemFont("Send Custom Event 2", (sender) =>
            {
                var customEvent      = new CCEventCustom("game_custom_event2");
                customEvent.UserData = ++count2;
                DispatchEvent(customEvent);
            });

            sendItem2.Position = origin + new CCPoint(size.Width / 2, size.Height / 2 - 40);

            var menu = new CCMenu(sendItem, sendItem2);

            menu.Position    = CCPoint.Zero;
            menu.AnchorPoint = CCPoint.AnchorUpperLeft;
            AddChild(menu, -1);
        }