removes onEnterFrame listener, and touch listeners.
This when? Level? Ship? Gear? all? Is this functions to add?
You have to call removeEventListener before change scene (Level) always. There should be addEventListener previous. But you are removing a listener that does not exist in your code.
@jdbc I tried it over again and was EXACTLY that! I was not declaring it inside init. Now It works like a charm!! Living and learning hahah! Really thank you for the help and time spent!! Now I can remove their event listeners and kill them completely!!
Locals as the name suggests are local things: they are faster to access than any other variable or property, but they have a downside which is they are available only in their scope (their "function"). Self instead refers to a property of a class, (which is a variable too in the end) which is bound to the class itself, and therefore it's available throughout the whole class (ie in any method of the class - methods are functions of a class- or from outside of it, as long as the class instance is accessible) Have you read Programming in gideros by arturs? It's a bit outdated but totally valuable to understand the basics of gideros. Last time I saw it online its price was less than 10$ as digital dl
@pie I will try to get it... Aways see its sayings when I was trying to learn something. Now It is working as expected but I had to make these changes:
if self.counter ==1100then--add the last one
self.nogears +=1
self.gear[self.nogears]= Gear.new(ship)
self:addChild(self.gear[self.nogears])
self.counter =0-- now it will repeat and keep adding gears to the tableend
In the function of restart I use that method of killing sprites @antix posted, and now it is working like a charm!
Thanks @jdbc@antix for the support Thanks everyone!
@Paulo777 the main problem you have is that your code is very messy and inefficient. It mostly works but it doesn't work 100% For what you have you are doing really well for a beginner.. don't give up!
I could rewrite the entire thing for you but really it would take me days and whilst I would enjoy the challenge, I just don't have time for that. So in lieu of a total rewrite I've made an example project this evening that demonstrates one way to add gears and bullets, check collision between them, and remove them on collision.
The game scene should serve as an example of a good (IMHO) scene containing all the required functions to manage transitions.
You will see in the example we start the game scene. From there it creates two sprites (gears and playerProjectiles) and attaches them to its self. These two sprites (or groups) are where we will attach our gears, and yes.. playerProjectiles. This makes things really easy to process because we just iterate (backwards) through each groups children, processing and disposing them as required.
A number of gears are spawned when the scene starts and a new gear is spawned every couple of seconds. The gears move downwards and are disposed of when they leave the bottom of the screen.
Touching the screen will spawn a playerProjectile which travels up the screen and is disposed when it leaves the top of the screen.
During it's update, each playerProjectile checks if it has collided with a gear and if so, both objects are disposed.
The collision method used is point in rectangle but the code is present (commented) if you want to switch back to rect in rect.
There are TextFields to show how many of each object there are currently on screen.
Something to note is that unlike your code, the gear and fire classes are subclasses of the Bitmap class. This is more efficient and as long as you supply the texture parameter first you can supply others as well.
If you have questions ask, right now I'm going to bed
Omg @antix thanks again for the tips and support. I'm a begginer on Gideros and Lua and this project is at a glance for learning and understanding how Gideros works and to learn a new programming language to me that is Lua, coincidently created by Brazillians haha! On this project I was really doing tests and if it works, I'd leave it so... But I'm on the road to construct a code and logic that is efficient and with best practices, using the maximum Gideros can offer... I have toooo much to learn and that is what I want to do.
I looked at your code! I feel amazed! There is to much to learning with that! One of the things I've figured out, you use I mean, custom events
@Paulo777 you are welcome. It took me a little while to get used to how everything works but eventually it will fall into place
Custom events are very cool but as with any event, use them sparingly. The only custom events I use personally are the ones required for correct operation of SceneManager.
Making a variable (in the case of the example the game scene) global means that you can then access that scene from any other scene. It is very handy, though some might say a bit lazy
Setting the random seed and then throwing a bunch of random numbers at the beginning of your code is a good way to actually get random numbers.
Adding sprites to other sprites is very useful for grouping sprites. So if you make one sprite and then attach 50 children sprites to it, when you move the original sprite, all of the others will seem to move at the same time. So add your groups to the stage (or the scene where they are being used) and then add children to the group.
I hope that clears a few things up for you. And btw, your code is probably a little tidier than my original spaghetti
@antix surely It does! Now I got a better vision of how things works.
@jdbc , looking at your code, I've noticed that there is a file with setting for multi-language. As an android programmer into an android prepared development enviroment, I have folders with the specific language and inside of it I have xml files with "strings" inside of it. But in Gideros this is a little different. Can you or anybody else if knows, light it for me on how it works in Gideros?
> Newcomers roadmap: from where to start learning Gideros "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
@antix surely It does! Now I got a better vision of how things works.
@jdbc , looking at your code, I've noticed that there is a file with setting for multi-language. As an android programmer into an android prepared development enviroment, I have folders with the specific language and inside of it I have xml files with "strings" inside of it. But in Gideros this is a little different. Can you or anybody else if knows, light it for me on how it works in Gideros?
This my solution for multi-language. Just define a file with languages and key/value with translation and getString(key) function. Quite easy.
Comments
You have to call removeEventListener before change scene (Level) always. There should be addEventListener previous. But you are removing a listener that does not exist in your code.
Likes: Paulo777
Gideros is not the problem, if you remove objects they are removed, if you remove listeners they are removed.
You should look to my Dots source code and try to use Core.class() in a better way than you are using to avoid most of your current problems.
Do not use functions inside classes functions for instance, and use classes functions for drawing and gameplay.
Likes: Paulo777
Likes: Paulo777
You could try self.removeChild(self.gear) also before changescene
Likes: Paulo777
Likes: jdbc
Self instead refers to a property of a class, (which is a variable too in the end) which is bound to the class itself, and therefore it's available throughout the whole class (ie in any method of the class - methods are functions of a class- or from outside of it, as long as the class instance is accessible)
Have you read Programming in gideros by arturs? It's a bit outdated but totally valuable to understand the basics of gideros. Last time I saw it online its price was less than 10$ as digital dl
Likes: Paulo777
Thanks @jdbc @antix for the support
Thanks everyone!
Likes: Paulo777
Just looking at your code now.. a SHMUP.. nice.. one of the example games in my book (I hope to complete it one day) will be the same genre
Likes: Apollo14, Paulo777
I could rewrite the entire thing for you but really it would take me days and whilst I would enjoy the challenge, I just don't have time for that. So in lieu of a total rewrite I've made an example project this evening that demonstrates one way to add gears and bullets, check collision between them, and remove them on collision.
The game scene should serve as an example of a good (IMHO) scene containing all the required functions to manage transitions.
You will see in the example we start the game scene. From there it creates two sprites (gears and playerProjectiles) and attaches them to its self. These two sprites (or groups) are where we will attach our gears, and yes.. playerProjectiles. This makes things really easy to process because we just iterate (backwards) through each groups children, processing and disposing them as required.
A number of gears are spawned when the scene starts and a new gear is spawned every couple of seconds. The gears move downwards and are disposed of when they leave the bottom of the screen.
Touching the screen will spawn a playerProjectile which travels up the screen and is disposed when it leaves the top of the screen.
During it's update, each playerProjectile checks if it has collided with a gear and if so, both objects are disposed.
The collision method used is point in rectangle but the code is present (commented) if you want to switch back to rect in rect.
There are TextFields to show how many of each object there are currently on screen.
Something to note is that unlike your code, the gear and fire classes are subclasses of the Bitmap class. This is more efficient and as long as you supply the texture parameter first you can supply others as well.
If you have questions ask, right now I'm going to bed
Likes: Apollo14, Paulo777
I looked at your code! I feel amazed! There is to much to learning with that! One of the things I've figured out, you use I mean, custom events
Also this is a thing that I didn't know
GAME = self
Custom events are very cool but as with any event, use them sparingly. The only custom events I use personally are the ones required for correct operation of SceneManager.
Making a variable (in the case of the example the game scene) global means that you can then access that scene from any other scene. It is very handy, though some might say a bit lazy
Setting the random seed and then throwing a bunch of random numbers at the beginning of your code is a good way to actually get random numbers.
Adding sprites to other sprites is very useful for grouping sprites. So if you make one sprite and then attach 50 children sprites to it, when you move the original sprite, all of the others will seem to move at the same time. So add your groups to the stage (or the scene where they are being used) and then add children to the group.
I hope that clears a few things up for you. And btw, your code is probably a little tidier than my original spaghetti
Likes: Paulo777
@jdbc , looking at your code, I've noticed that there is a file with setting for multi-language. As an android programmer into an android prepared development enviroment, I have folders with the specific language and inside of it I have xml files with "strings" inside of it. But in Gideros this is a little different. Can you or anybody else if knows, light it for me on how it works in Gideros?
Likes: antix, Paulo777
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
Likes: Paulo777