Hey everyone,
I'm just getting started with Gideros Mobile to develop a game for a class. I followed some beginner tutorials and am getting a feel for it all. However, I have hit a wall and am not sure what is wrong...
--------------------------------
file: dog.lua
Dog = Core.class(Sprite)
function Dog:init()
self = Bitmap.new(Texture.new("dog.png"))
stage:addChild(self)
end |
--------------------------------
file: main.lua
require "dog"
local d = Dog.new()
print(d:getPosition())
-- As expected, this returns "0 0".
-- As expected, the "dog.png" image is displayed in the upper left corner.
d:setPosition(100,100)
print(d:getPosition())
-- As expected, this returns "100 100"
-- Not as expected, the "dog.png" image is still displayed in the upper left corner (didn't move) |
--------------------------------
So it seems setPosition() and getPosition() are reading values/writing values properly, but the image itself isn't moving. Could anybody point me in the right direction as to why?
Comments
Secondly, inside Dog:init method, you create bitmap and add it to the Stage, so bitmap is not associated with class Dog in any way, you give another meaning to variable self, which is now Bitmap instance, not Dog's instance. Thus when you move Dog's instance, it does not move the image.
What you wanted to do is: