Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Getting better every day, just a few questions for the resident gurus... - Gideros Forum

Getting better every day, just a few questions for the resident gurus...

Hey guys!

So my skills are improving a little bit every day but there are still a couple of things that I'm a bit hazy on. One is around variable scoping, the other is about bump.

So here goes!

Let's say I have the following:
function GameScene:init()
 
  GAME = self
  myNumber = 7
  self.myNumber = 7
  GameScene.myNumber = 7
 
end
 
...
 
function GameScene:printMyNumber()
  print(self.myNumber)
  print(GameScene.myNumber)
end
 
function GameScene:handleSelf(randomObject)
  print(self.myNumber) -- I gots nothin'!
  print(GameScene.myNumber) -- I gots nothin'!
  print(GAME.myNumber)
end
So, I can't access self.myNumber if I'm passing in an argument to that last function. If I pass in self first though... Is that how you would do it in Lua? (Does that even work? I don't have access to my IDE right now. :/)

On that note, is self.myNumber and GameScene.myNumber the same thing, or is GameScene.myNumber instantiating itself again? They usually have the same table address so I'd wager the former.

About bump (or cbump rather!), is there a way to show the physics in debug mode? Something like world:enableDebug or world:showPhysics? I edited one of the functions in bump before to show shapes but I wasn't able to update them every frame. It was semi-useful. :)




Tagged:

Comments

  • olegoleg Member
    edited May 3
    GameScene:init= gideros.class(Sprite)


    function GameScene:init()

    GAME = self
    myNumber = 7
    self.myNumber = 7
    GameScene.myNumber = 7

    end

    ...

    function GameScene:printMyNumber(self)
    print(self.myNumber)
    print(GameScene.myNumber)
    end

    function GameScene:handleSelf(randomObject)
    print(self.myNumber) -- I gots nothin'!
    print(GameScene.myNumber) -- I gots nothin'!
    print(GAME.myNumber)
    end

    ---------------
    TEST1=GameScene.new()
    TEST1:printMyNumber(TEST1)
    or
    print(TEST1.myNumber)

    try this way

    Likes: Astirian

    +1 -1 (+1 / -0 ) Share on Facebook
  • keszeghkeszegh Member
    i think
    function GameScene:printMyNumber(self)
    is wrong and that
    function GameScene:printMyNumber()
    was good actually, or
    function GameScene.printMyNumber(self)
    is also good and means the same - notice the . instead of :

    Likes: Astirian

    +1 -1 (+1 / -0 ) Share on Facebook
  • antixantix Member
    edited May 3 Accepted Answer
    @Astirian with bump there is no inbuilt feature to draw collision data. If you want to you can use the Pixel class instead of the shape class. Pixels are fantastic because they are always rectangles, can be any color and have alpha. Pixels are WAY FAS?TER than shapes as well! Basically do something like..
    local player = Bitmap.new(Texture.new('someTexture.png'))
    local x, y = 160, 240
    local w, h = player:getWidth(), player:getHeight()
    BUMP:add(player, x, y, w, h)
    player:addChild(Pixel.new(0x00ff00, 0.5, w, h)
    This attaches a rectangle to the player that will move along with it so you can see it's collision size.

    Of course this is a little messy because you need to add this code to all game objects and then when you release.. you have to comment out or remove all of that code.

    Still, if you need it, then that's probably the best way I can think of at breakfast time ;)

    Likes: Apollo14, Astirian

    Follow me on FaceBook Check out my DevBlog, my GitHub, and try my games...
    Falling Animals | Breaky Wall | Exetor | Mini Putt Golfing | Ninja Fruit Master
    +1 -1 (+2 / -0 ) Share on Facebook
  • AstirianAstirian Member
    Thanks guys, and thanks again @Antix! I haven't played with Pixel yet (heh) but it looks incredibly useful! :D
  • antixantix Member
    @Astirian you can also use textures with pixels but I haven't tried that yet. For colored rectangles though they are very fast.
    Follow me on FaceBook Check out my DevBlog, my GitHub, and try my games...
    Falling Animals | Breaky Wall | Exetor | Mini Putt Golfing | Ninja Fruit Master
Sign In or Register to comment.