Is there a way to create a custom class (a separate .lua file) that simply performs some function? If so, how can it be called?
Let me explain. Currently, I have a projectile with collision detection. If the projectile strikes the enemy, I call an instance of a custom class that counts the number of times the enemy has been hit. If the enemy is hit the proper number of times, then the enemy is removed from the stage through the custom class. It works fine, but to make it work I am doing the following:
If the projectile hits the enemy, then an instance of my custom class is created (currently a Sprite set to invisible) and added to the stage. I then have to remove the invisible sprites from the stage. I am wondering if there is a way to call the custom class without it being a sprite that must be added and removed.
I hope this makes sense.
Comments
Yes, you can create it using Core.class() without any parameter.
http://docs.giderosmobile.com/classes_in_gideros.html
When using sprites, one would use stage:addChild(sprite) to initialize the new instance of the class. How do I properly initialize Core.class()?
the init function is called when you do
myInstance=myClass.new()
(so in fact adding to stage does not do anything like this)
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Sprite.new ()
And add it to stage (or other parent) with addChild.
I presume you just have to use something like:
myInstance = myClass.new()
I was thinking that would just create a variable called myInstance which was equal to myClass (like saying a = b), then I would have to do something to make it "happen." I have a tendency to overcomplicate things. Thanks for clearing everything up for me.