public override void OnEnter() { base.OnEnter(); var origin = Layer.VisibleBoundsWorldspace.Origin; var s = Layer.VisibleBoundsWorldspace.Size; label1 = new CCLabelTtf("Update: 0", "arial", 20); label1.AnchorPoint = CCPoint.AnchorUpperLeft; label1.Position = new CCPoint(30, s.Height / 2 + 60); AddChild(label1); label2 = new CCLabelTtf("Visit: 0", "arial", 20); label2.AnchorPoint = CCPoint.AnchorUpperLeft; label2.Position = new CCPoint(30, s.Height / 2 + 20); AddChild(label2); label3 = new CCLabelTtf("Draw: 0", "arial", 20); label3.AnchorPoint = CCPoint.AnchorUpperLeft; label3.Position = new CCPoint(30, s.Height / 2 - 20); AddChild(label3); label4 = new CCLabelTtf("Projection: 0", "arial", 20); label4.AnchorPoint = CCPoint.AnchorUpperLeft; label4.Position = new CCPoint(30, s.Height / 2 - 60); AddChild(label4); event1 = AddCustomEventListener(CCWindow.EVENT_AFTER_UPDATE, OnEvent1); event2 = AddCustomEventListener(CCWindow.EVENT_AFTER_VISIT, OnEvent2); event3 = AddCustomEventListener(CCWindow.EVENT_AFTER_DRAW, (customEvent) => { label3.Text = string.Format("Draw: {0}", count3++); }); event4 = AddCustomEventListener(CCWindow.EVENT_PROJECTION_CHANGED, (customEvent) => { label4.Text = string.Format("Projection: {0}", count4++); }); Schedule(); }
public override void OnEnter() { base.OnEnter(); CCRect visibleBounds = Layer.VisibleBoundsWorldspace; customlistener = AddCustomEventListener(CCEvent.EVENT_COME_TO_BACKGROUND, (customEvent) => { var label = new CCLabelTtf("Yeah, this issue was fixed.", "", 20); label.AnchorPoint = CCPoint.AnchorMiddleLeft; label.Position = new CCPoint(visibleBounds.Origin.X, visibleBounds.Origin.Y + visibleBounds.Size.Height / 2); AddChild(label); // After test, remove it. RemoveEventListener(customlistener); customlistener = null; bugFixed = true; }); removeAllTouchItem.Position = new CCPoint(visibleBounds.Origin.X + visibleBounds.Size.Width - 100, visibleBounds.Origin.Y + visibleBounds.Size.Height / 2); menu.Position = CCPoint.Zero; }
protected override void AddedToScene() { base.AddedToScene(); InitializeJoystick(); InitializeMonkey(); InitializeBear(); CurrentSprite = monkeySprite; joystickPanel.Player = CurrentSprite; CurrentSprite.Position = Window.WindowSizeInPixels.Center; CCSimpleAudioEngine.SharedEngine.PreloadEffect("sound_oso"); joystickListener = new CCEventListenerCustom(SneakyPanelControl.JOY_LISTENER_ID, (customEvent) => { var response = customEvent.UserData as SneakyJoystickEventResponse; if (response != null) { switch (response.ResponseType) { case SneakyJoystickMovementStatus.Start: isWalking = true; Console.WriteLine("Start walk."); break; case SneakyJoystickMovementStatus.End: isWalking = false; Console.WriteLine("Stop walk."); break; default: break; } } }); AddEventListener(joystickListener, 1); buttonListener = new CCEventListenerCustom(SneakyPanelControl.BUTTON_LISTENER_ID, (customEvent) => { var response = customEvent.UserData as SneakyButtonEventResponse; if (response != null) { if (response.ID == 1) { CCSimpleAudioEngine.SharedEngine.PlayEffect("sound_oso"); } if (response.ID == 0 && response.ResponseType == SneakyButtonStatus.Release) { SwitchSprite(); } Console.WriteLine("BUTTON {0} {1}", response.ID, response.ResponseType == SneakyButtonStatus.Press ? "PRESSED" : "UNPRESSED"); } }); AddEventListener(buttonListener, 1); Schedule(); }
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); }