ymobe/rapanui

removeEventListener

Opened this issue · 8 comments

Hi

Wonder if someone could tell me how to remove and eventlistener from an object, i.e. one that was created like this:

playBtn:addEventListener("touch", fnPlayTouch)

thanks

Thanks again Mattia. We're evaluating moai/Rapanui by porting a game already developed using Corona (so I may be making too many assumptions based on some similarity in the methods). The name playBtn might be a bit misleading. As well as the playBtn, in the game itself there are many objects on the screen that can be individually touched. In your samples there are many examples of the format prop:addEventListener("touch", function) but all the examples of removing the listener are in the format 'RNListeners:removeEventListener("touch", listenerId)' as in the sample you pointed me to, where the creation of the listener is always 'listenerId = RNListeners:addEventListener("touch", onTouchEvent)'. These seem to relate to generic listeners not individual object listeners - is this true?

I have tried
playListenId = playBtn:addEventListener("touch", fnPlayTouch)

and later:

RNListeners:removeEventListener("touch", playListenId) but this threw an exception.

I checked the SDK to see if removing the object would also remove any associated listeners but it doesn't seem to be the case.

I apologise if this is not the right forum for support issues.

ps. the example rn-touch-rnobject.lua shows an object listener being created but not removed - this seems to be what I need.

Hi,

yes, the local listener is an old implementation and you should not use it.

You may use RNButtons which are similar to corona buttons:
https://github.com/ymobe/rapanui/tree/master/rapanui-samples/buttons

Or use the setOnTouch functions applicable to every RNObject:
https://github.com/ymobe/rapanui/blob/master/rapanui-samples/touch/rn-buttons-animated.lua

In these cases above, listeners are removed together with the object.

Thanks for the info regarding listeners. I've encountered a further problem with setTouchOnUp that didn't happen with addEventListener.

In my config I've got:

config.sizes["iPad3Dev"] = { 1536, 2048, 384, 512 } -- shrunk for easier viewing

If I use:

config.stretch = { status = false, letterbox = false, drawOnBlackBars = false, graphicsDesign = { w = 1536, h = 2048 } }

this shows the image, scaled correctly and in the expected position on the screen. But the touch sensor is in a different place on the screen.

If i change config.stretch - status = true, I get a much-enlarged version of the image partially shown on the middle/right of the screen ( where you'd expect it if the screen was really iPad3-sized, i guess). In this case the touch sensor is placed correctly on the image.

It is in this position that the sensor also appears when stretch.status is false and the reduced image is placed correctly.

is this a bug?

thanks

ps. where can i get a full list of the attributes/variables/methods associated with the event parameter that is passed to the listener callback function?

Hi,

try to use two different configurations for testing purposes:
config.sizes["iPad3Dev"] = { 1536, 2048, 1536, 2048 }
config.sizes["iPad3DevTEST"] = { 384, 512, 384, 512 }

the third and the fourth parameters should be the same as the first and second ones.
(this is because we changed screen stretch recently and such old signatures are still there)

Let me know if touch area is OK.

Thanks again. Seems to work but my brain is getting more confused. I presume on device these dimensions are taken from the device so what would iPadDev be used for during development? If the third and fourth parameter must be the same as first and second, why have two sets? And is there any way I can find out (I don't mind digging) what info is contained in the "event" parameter sent to listener callbacks?
I understand that this is a work in progress and I'm new here, but are users usually informed of significant changes to the SDK?
This looks like it will become a great framework but right now I'm having to ask questions that should be answered, if not in docs, then at least in up-to-date samples. Do you have a date for when a relatively stable version will be available with some docs?

I presume on device these dimensions are taken from the device so what would iPadDev be used for during development?

Those values are to be specified in confi.lua because they are the size of the surface the game is running.

And is there any way I can find out (I don't mind digging) what info is contained in the "event" parameter sent to listener callbacks?

If you are referring to the touch listener it receives a table event containing
event.x
event.y
event.target
event.touches
the target is your object
(you can always check all values in a table using lua's for in pair)
for i, v in pairs(table)do print(i,v)end

About your other questions:
the master branch has always the more stable version, but we don't have version tags at the moment, and the documentation is a work in progress.
I'm sorry but we don't have a date for a version at the moment.

However luckily, since it's an opensource framework you can ask here (we don't have a community forum, yet) or in Moai's forum, or check the source by yourself if needed ;D

I'm glad you like RapaNui ^^

Thanks again for the time you've given to my queries. Is config.lua required for live apps? If so, how can we get the device dimensions so that an appropriate scaled sprite atlas can be loaded? Is there an example of a working open-source game developed with Rapanui that might be used as a comprehensive example?

Thanks again.