Difference between revisions of "Event"

From GiderosMobile
m
 
(22 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''Supported platforms:''' android, ios, mac, pc<br/>
+
<!-- GIDEROSOBJ:Event -->
 +
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
 
'''Available since:''' Gideros 2011.6<br/>
 
'''Available since:''' Gideros 2011.6<br/>
 +
'''Inherits from:''' [[Object]]<br/>
 +
 
=== Description ===
 
=== Description ===
<translate><br />
+
The objects of '''Event''' class contain information about an event that has occurred. '''Event''' objects are passed to event listeners when an event occurs.
The objects of [[Special:MyLanguage/Event|Event]] class contains information about an event that has occurred. [[Special:MyLanguage/Event|Event]] objects<br />
+
 
are passed to event listeners when an event occurs.<br />
+
Usually event objects contain specific additional information about the event that has occured. For example, when an [[Event.MOUSE_DOWN]] event occurs, ''x'' and ''y'' fields contain the coordinates.
<br />
+
 
Usually event objects contains specific additional information about the event that has occured. For example,<br />
+
Users can create their own events and dispatch through the event mechanism.
when an [[Special:MyLanguage/Event.MOUSE_DOWN|Event.MOUSE_DOWN]] event occurs, [[Special:MyLanguage/x|x]] and [[Special:MyLanguage/y|y]] fields contain the coordinates.<br />
+
 
Users can create their own events and dispatch through the event mechanism.<br /></translate>
 
 
=== Examples ===
 
=== Examples ===
'''Mouse down event example'''<br/>
+
'''Mouse down event example'''
<source lang="lua">function onMouseDown(event)
+
<syntaxhighlight lang="lua">
print(event.x, event.y)
+
function onMouseDown(event)
 +
  print(event.x, event.y)
 
end
 
end
mysprite:addEventListener(Event.MOUSE_DOWN, onMouseDown)</source>
+
 
'''User created event'''<br/>
+
mysprite:addEventListener(Event.MOUSE_DOWN, onMouseDown)
<source lang="lua">local event = Event.new(&quot;myevent&quot;)
+
</syntaxhighlight>
event.data1 = &quot;12345&quot;
+
 
event.data2 = &quot;abcde&quot;
+
'''User created event'''
mydispatcher:dispatchEvent(event)</source>
+
<syntaxhighlight lang="lua">
 +
local event = Event.new("myevent")
 +
event.data1 = "12345"
 +
event.data2 = "abcde"
 +
mydispatcher:dispatchEvent(event)
 +
</syntaxhighlight>
 +
 
 +
=== Note ===
 +
Please note that most events happen in the '''[[Sprite]]''' class.
 +
 
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 
=== Methods ===
 
=== Methods ===
[[Special:MyLanguage/Event.new|Event.new]] ''<translate>creates a new Event object</translate>''<br/>
+
[[Event.new]] ''creates a new Event object''<br/><!--GIDEROSMTD:Event.new(type) creates a new Event object-->
[[Special:MyLanguage/Event:getTarget|Event:getTarget]] ''<translate>returns the element on which the event listener was registered</translate>''<br/>
+
 
[[Special:MyLanguage/Event:getType|Event:getType]] ''<translate>returns the type of Event</translate>''<br/>
+
[[Event:getTarget]] ''returns the element on which the event listener was registered''<br/><!--GIDEROSMTD:Event:getTarget() returns the element on which the event listener was registered-->
[[Special:MyLanguage/Event:stopPropagation|Event:stopPropagation]] ''<translate>stops the propagation of the current event in the scene tree hierarchy</translate>''<br/>
+
[[Event:getType]] ''returns the type of Event''<br/><!--GIDEROSMTD:Event:getType() returns the type of Event-->
 +
[[Event:stopPropagation]] ''stops the propagation of the current event in the scene tree hierarchy''<br/><!--GIDEROSMTD:Event:stopPropagation() stops the propagation of the current event in the scene tree hierarchy-->
 +
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 
=== Events ===
 
=== Events ===
 
=== Constants ===
 
=== Constants ===
 
|}
 
|}
 +
 +
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 20:16, 15 December 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2011.6
Inherits from: Object

Description

The objects of Event class contain information about an event that has occurred. Event objects are passed to event listeners when an event occurs.

Usually event objects contain specific additional information about the event that has occured. For example, when an Event.MOUSE_DOWN event occurs, x and y fields contain the coordinates.

Users can create their own events and dispatch through the event mechanism.

Examples

Mouse down event example

function onMouseDown(event)
  print(event.x, event.y)
end

mysprite:addEventListener(Event.MOUSE_DOWN, onMouseDown)

User created event

local event = Event.new("myevent")
event.data1 = "12345"
event.data2 = "abcde"
mydispatcher:dispatchEvent(event)

Note

Please note that most events happen in the Sprite class.

Methods

Event.new creates a new Event object

Event:getTarget returns the element on which the event listener was registered
Event:getType returns the type of Event
Event:stopPropagation stops the propagation of the current event in the scene tree hierarchy

Events

Constants