Difference between revisions of "Event"
(----) |
m |
||
(12 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | + | <!-- 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/> | '''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/> | ||
Line 6: | Line 6: | ||
=== Description === | === Description === | ||
− | The objects of | + | 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 | + | 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 | + | Users can create their own events and dispatch through the event mechanism. |
=== Examples === | === Examples === | ||
− | '''Mouse down event example''' | + | '''Mouse down event example''' |
− | < | + | <syntaxhighlight lang="lua"> |
function onMouseDown(event) | function onMouseDown(event) | ||
print(event.x, event.y) | print(event.x, event.y) | ||
end | end | ||
+ | |||
mysprite:addEventListener(Event.MOUSE_DOWN, onMouseDown) | mysprite:addEventListener(Event.MOUSE_DOWN, onMouseDown) | ||
− | </ | + | </syntaxhighlight> |
− | |||
− | '''User created event''' | + | '''User created event''' |
− | < | + | <syntaxhighlight lang="lua"> |
local event = Event.new("myevent") | local event = Event.new("myevent") | ||
event.data1 = "12345" | event.data1 = "12345" | ||
event.data2 = "abcde" | event.data2 = "abcde" | ||
mydispatcher:dispatchEvent(event) | 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 === | ||
+ | [[Event.new]] ''creates a new Event object''<br/><!--GIDEROSMTD:Event.new(type) creates a new Event object--> | ||
− | + | [[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--> | |
− | [[Event | + | [[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--> | |
− | [[Event:getType]] ''returns the type of Event''<br/> | ||
− | [[Event:stopPropagation]] ''stops the propagation of the current event in the scene tree hierarchy''<br/> | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | |||
=== Events === | === Events === | ||
− | |||
=== Constants === | === Constants === | ||
− | |||
|} | |} | ||
− | + | {{GIDEROS IMPORTANT LINKS}} | |
− | {{ | ||
− |
Latest revision as of 19:16, 15 December 2023
Supported platforms:
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.
MethodsEvent.new creates a new Event object Event:getTarget returns the element on which the event listener was registered |
EventsConstants |