… you’ll see that it only accepts two arguments, not a long list as you have done. You have the first argument correct (i.e. “tap”) but the second argument needs to be either a reference to a properly-scoped function, or an inline “anonymous” function. So, it might look something like this, using an anonymous function (I’m making some assumptions since I don’t know all of the code you’ve written):
The correct commands to remove an object are either “display.remove( object )” or “object:removeSelf()”, either of which could be called from the function which listens for a tap on the object.
I’m curious, have you seen or followed through our Getting Started guide and game project?
If not, I highly recommend that you do, because it covers a large amount of core aspects of Corona. I know it’s probably more fun to just dive in and start working on your game idea, but the guide is also pretty fun because you get to create a working “Asteroids” game while learning many valuable things about Corona… and doing so will make your own game development much easier and enjoyable.
I did try the “object:removeSelf()” line a few different times in a few different places and it just takes the square away before it can even be tapped.
I have been reading the guides, I’m now just trying to see if I can put to my own use and understanding. Looks like I have a ways to go as I’m still not grasping some concepts.
I know it was example code. I copied and added my own modifications (probably where I’m getting the errors).
It seems the events I’m creating are not working correctly.
The example you just provided worked great in a new file, it’s when I try to adapt it to my project I get errors (I have changed obj names) and if I try to add going to the next slide seems to make it worse.
If you use the code I wrote for you above, you will see it draws a white box and when you tap on that box it fades into another box and removes the first box. This is how you should be coding. You can replace the boxes with your images easily.
As Brent already pointed out, your code for adding events is completely wrong and will not work.
I understand that my code is not working correctly, thats why I’m asking for help (and I do appreciate the help, thank you).
When I try to replace the scares with my images (and keeping my images centered, and adding the squares, and keeping the squares centered I get errors. I’m also trying to add scores and I know I can’t do all of that in one line. the more lines or events I add the more errors.
So far I am able to display my first image, have one square appear, have it clicked, it fades, new square appears.
I’m still not able to have it go to the next slide/image or keep scores.
So you want to have 12 different background images and 12 really faint touch points? A tap on the touch point moves to the next slide and awards some score but a tap not on the touch points decrements the score? I also assume you want to move the touch point per slide - otherwise it will be a bit easy?
Thank you so much!! his looks awesome and I can actually understand most of it from what I’ve previously read.
is there a way to place the squares in specific spots with the specific slides/images? (I’m using transparent squares to have the player click on objects in the photos/mages). I’m pretty sure you did that in the second line.
This looks much easier, sorry I was used to working with longer scripts.
Yes you define the rects in the second line. I used a runtime tap handler and then worked out if the tap “hit” the current rect or not and adjusted accordingly. I’ve left enough comments so it should make sense.
Keep in mind that when you use an anonymous function with addEventListener(), you get a memory address returned and both the event type and the address have to match if you ever want to call removeEventListener(). Since you have no access to address of the anonymous function, you can’t remove it.
Now for touch and tap handlers on display objects, you will likely remove the object and never need to remove the touch/tap handler, so you can get away with an anonymous function, but if you want to set up other types of event listeners that you want to remove, you have to use a non-anonymous function so you can pass the same memory address to removeEventListener() that you did to addEventListener()
Wow thanks again.
I assume it would also be possible to add a second object (say “rect2” or some other shape) to some slides (or on every slide but hide them off screen–I’ve been redoing the Astroid game).
I’m wondering if some slides can make use a second object so that the game can have a “choose your own adventure” style text gameplay.
Click on the proper square and go to the next slide, click on the second square and have a detour to a different slide or text. And back again to the original slide.
I’ll keep typing with what you gave me
Thanks again