It looks like you're new here. If you want to get involved, click one of these buttons!
-- camera testXX local function lerp(a, b, t) return a + (b-a) * t end -- camera local camera = Sprite.new() local bg = Sprite.new() local mg = Sprite.new() camera:addChild(bg) camera:addChild(mg) stage:addChild(camera) -- lerping switch local camswitch = true -- SPACE BAR local x, x2 = 0, 0 -- lerp between those 2 values local l = 0 -- lerping value? -- the scene camera:setPosition(96, 96) local pixelbg = Pixel.new(0xff00ff, 1, 64 * 8, 64 * 3) pixelbg:setPosition(256, 256) local playerA = Pixel.new(0x0, 1, 64, 64) playerA:setPosition(256 + 32, 256 + 64) local playerB = Pixel.new(0x00ff00, 1, 64, 64) playerB:setPosition(256 + 32 * 4, 256 + 64) bg:addChild(pixelbg) mg:addChild(playerB) mg:addChild(playerA) function onKeyUp(e) if e.keyCode == KeyCode.SPACE then camswitch = not camswitch print(camswitch) end end stage:addEventListener(Event.KEY_UP, onKeyUp) function onEnterFrame(e) x, y = playerA:getPosition() x2, y2 = playerB:getPosition() if camswitch then l = lerp(x, x2, 0.1) camera:setAnchorPosition(l, y) -- camera:setAnchorPosition(x, y) else l = lerp(x2, x, 0.1) camera:setAnchorPosition(l, y) -- camera:setAnchorPosition(x2, y2) end end stage:addEventListener(Event.ENTER_FRAME, onEnterFrame) |
Comments
Likes: MoKaLux
I need to try this and then update the wikiDONELikes: MoKaLux
Thank you once again. I will upload a demo soon to show my progress (liquidfun platformer).
PS: I want to keep the code as simple as possible for now
Thank you and Viva Gideros
Likes: MoKaLux
PS: wiki updated https://wiki.gideros.rocks/index.php/MovieClip.new#Example
Likes: pie