Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Non-sprite custom classes — Gideros Forum

Non-sprite custom classes

freesspfreessp Member
edited February 2015 in Game & application design
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

  • marcelojuniormarcelojunior Member
    edited February 2015
    Hi @freessp

    Yes, you can create it using Core.class() without any parameter.

    http://docs.giderosmobile.com/classes_in_gideros.html

  • Thanks for the help marcelojunior. I was trying to do that earlier and could not get it to work properly.

    When using sprites, one would use stage:addChild(sprite) to initialize the new instance of the class. How do I properly initialize Core.class()?
  • keszeghkeszegh Member
    edited February 2015 Accepted Answer
    the initialization is done when you create the instance, i.e.
    the init function is called when you do
    myInstance=myClass.new()
    (so in fact adding to stage does not do anything like this)
  • piepie Member
    Accepted Answer
    @freessp you init the Sprite with
    Sprite.new ()

    And add it to stage (or other parent) with addChild.
    I presume you just have to use something like:
    yourClass = Core.class ()
     
    function yourClass:init(params)
    --(...)
    end
     
    --then you initialize it
     
     instancename = yourClass.new (params)
    :)
  • Thanks guys. I was thinking I had to perform another step after

    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.
Sign In or Register to comment.