Difference between revisions of "Event"
(template) |
|||
Line 5: | Line 5: | ||
'''<translate>Available since</translate>:''' Gideros 2011.6<br/> | '''<translate>Available since</translate>:''' Gideros 2011.6<br/> | ||
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/> | '''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/> | ||
+ | |||
=== <translate>Description</translate> === | === <translate>Description</translate> === | ||
− | + | The objects of [[Special:MyLanguage/Event|Event]] class contains information about an event that has occurred. [[Special:MyLanguage/Event|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 | + | |
− | are passed to event listeners when an event occurs. | + | Usually event objects contains specific additional information about the event that has occured. For example, when an [[Special:MyLanguage/Event.MOUSE_DOWN|Event.MOUSE_DOWN]] event occurs, ''x'' and ''y'' fields contain the coordinates. |
− | + | ||
− | Usually event objects contains specific additional information about the event that has occured. For example, | + | Users can create their own events and dispatch through the event mechanism. |
− | when an [[Special:MyLanguage/Event.MOUSE_DOWN|Event.MOUSE_DOWN]] event occurs, ''x'' and ''y'' fields contain the coordinates. | + | |
− | Users can create their own events and dispatch through the event mechanism. | ||
=== <translate>Examples</translate> === | === <translate>Examples</translate> === | ||
− | '''Mouse down event example''' | + | '''Mouse down event example''' |
− | <source lang="lua">function onMouseDown(event) | + | <source lang="lua"> |
+ | function onMouseDown(event) | ||
print(event.x, event.y) | print(event.x, event.y) | ||
end | end | ||
− | mysprite:addEventListener(Event.MOUSE_DOWN, onMouseDown)</source> | + | mysprite:addEventListener(Event.MOUSE_DOWN, onMouseDown) |
− | + | </source> | |
− | '''User created event''' | + | |
− | <source lang="lua">local event = Event.new("myevent") | + | '''User created event''' |
+ | <source lang="lua"> | ||
+ | local event = Event.new("myevent") | ||
event.data1 = "12345" | event.data1 = "12345" | ||
event.data2 = "abcde" | event.data2 = "abcde" | ||
− | mydispatcher:dispatchEvent(event)</source> | + | mydispatcher:dispatchEvent(event) |
+ | </source> | ||
+ | |||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | |||
=== <translate>Methods</translate> === | === <translate>Methods</translate> === | ||
[[Special:MyLanguage/Event.new|Event.new]] ''<translate>creates a new Event object</translate>''<br/><!-- GIDEROSMTD:Event.new(type) creates a new Event object --> | [[Special:MyLanguage/Event.new|Event.new]] ''<translate>creates a new Event object</translate>''<br/><!-- GIDEROSMTD:Event.new(type) creates a new Event object --> | ||
Line 34: | Line 38: | ||
[[Special:MyLanguage/Event:getType|Event:getType]] ''<translate>returns the type of Event</translate>''<br/><!-- GIDEROSMTD:Event:getType() returns the type of Event --> | [[Special:MyLanguage/Event:getType|Event:getType]] ''<translate>returns the type of Event</translate>''<br/><!-- GIDEROSMTD:Event:getType() returns the type of Event --> | ||
[[Special:MyLanguage/Event:stopPropagation|Event:stopPropagation]] ''<translate>stops the propagation of the current event in the scene tree hierarchy</translate>''<br/><!-- GIDEROSMTD:Event:stopPropagation() stops the propagation of the current event in the scene tree hierarchy --> | [[Special:MyLanguage/Event:stopPropagation|Event:stopPropagation]] ''<translate>stops the propagation of the current event in the scene tree hierarchy</translate>''<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;"| | ||
=== <translate>Events</translate> === | === <translate>Events</translate> === | ||
=== <translate>Constants</translate> === | === <translate>Constants</translate> === | ||
|} | |} | ||
− | |||
− |
Revision as of 23:22, 9 December 2019
Supported platforms:
Available since: Gideros 2011.6
Inherits from: Object
Description
The objects of Event class contains information about an event that has occurred. Event objects are passed to event listeners when an event occurs.
Usually event objects contains 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)
MethodsEvent.new creates a new Event object |
EventsConstants |