Hi everyone,
I am trying to figure out how everything works in Gideros, so this is most likely a stupid beginner question. I am trying to implement an infinitely scrolling background using the Pixel class in 2016.10. It was easy when doing everything just in the main.lua file "by hand" (as long as the texture has power-of-two size :-) ). However, then I tried about wrapping everything in a class but it does not seem to work:
ScrollingBackground = Core.class(Pixel)
function ScrollingBackground:init(texturePath, x, y, width, height, scrollx, scrolly)
self:setPosition(x, y)
self:setWidth(width)
self:setHeight(height)
self:setTexture(Texture.new(texturePath, false, {wrap = Texture.REPEAT}))
self.scrollx = scrollx or 0
self.scrolly = scrolly or 0
self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end
function ScrollingBackground:setScrollSpeed(dx, dy)
self.scrollx = dx
self.scrolly = dy
end
function ScrollingBackground:getScrollSpeed()
return self.scrollx, self.scrolly
end
function ScrollingBackground:onEnterFrame(event)
local tx, ty = self:getTexturePosition()
tx = tx + self.scrollx * event.deltaTime
ty = ty + self.scrolly * event.deltaTime
self:setTexturePosition(tx, ty)
end |
When just trying to create an instance in main.lua like so:
bg = ScrollingBackground.new("flowers_bg.jpg", 0, 0, 320, 480, 0, 1)
stage:addChild(bg) |
I get the error:
[string "property.lua"]:46: bad argument #1 to '__new' (number expected, got string)
stack traceback:
[string "property.lua"]:46: in function '__new'
[string "property.lua"]:59: in function 'new'
main.lua:2: in main chunk |
Although the class is super simple, I can't seem to be able to spot the mistake. Any help would be really appreciated.
Thanks in advance!
Comments
Likes: stetso, antix
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Thanks a lot @keszegh!
Likes: keszegh, stetso, hgy29, chuz0, pie
Then use the TileMap feature to render these images using smaller cells. Because this is made into a mesh of cells that is the size of the display screen then it will take less time to draw as the clipping area will effectively be smaller and less memory accessed by the gpu.
Likes: MoKaLux
https://deluxepixel.com