-- require "Cocos2d" -- require "Cocos2dConstants" -- cclog = function(...) print(string.format(...)) end -- function __G__TRACKBACK__(msg) cclog("\n----------------------------------------") cclog("LUA ERROR: " .. tostring(msg)) cclog(debug.traceback()) cclog("----------------------------------------") return msg end collectgarbage("collect") -- collectgarbage("setpause", 100) collectgarbage("setstepmul", 5000) -- "src" "res" cc.FileUtils:getInstance():addSearchResolutionsOrder("src"); cc.FileUtils:getInstance():addSearchResolutionsOrder("res"); -- SCREEN_WIDTH = cc.Director:getInstance():getWinSize().width SCREEN_HEIGHT = cc.Director:getInstance():getWinSize().height local function main() print("Resolution: " .. SCREEN_WIDTH .. "x" .. SCREEN_HEIGHT) -- require "mainScene.lua" end -- main local status, msg = xpcall(main, __G__TRACKBACK__) if not status then error(msg) end
-- local NONE = 0 local ROTATION = 1 local SCALLING = 2 local MOVING = 3 -- local state, rotation, scale, ox, oy, delta, habrImage, moving -- local function onTouchBegan(touch, event) -- state = (state + 1) % 4 -- resetVariables() end -- , dt -- . dt == 1.0, -- local function update(dt) if state == ROTATION then -- rotation = rotation + delta * dt elseif state == SCALLING then -- scale = scale + dt * delta elseif state == MOVING then -- , : -- moving, -- -- moving = moving + delta * dt local radius = 50 ox = radius * math.sin(moving) oy = radius * math.cos(moving) end -- love2d -- -- -- habrImage:setScale(scale) -- habrImage:setRotation(rotation) -- habrImage:setPosition(cc.p(SCREEN_WIDTH / 2 + ox, SCREEN_HEIGHT / 2 + oy)) end local function init() print("Creating main scene") -- local mainScene = cc.Scene:create() -- -- -- 2 -- . 1) C++ cc.c4b(r,g,b,a) -- , C++ , -- cocos2d-x-js, .. cocos2d-x-lua -- C++, -- JavaScript , local gameLayer = cc.LayerColor:create(cc.c4b(255, 255, 255, 255)) -- habrImage = cc.Sprite:create("res/habr.png") -- habrImage:setAnchorPoint(0.5, 0.5) -- habrImage:setPosition(cc.p(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)) -- gameLayer:addChild(habrImage) state = 0 resetVariables() -- update , -- cc.Director:getInstance():getScheduler():scheduleScriptFunc(update, 0, false) -- . , -- . local listener = cc.EventListenerTouchOneByOne:create() -- , listener:registerScriptHandler(onTouchBegan, cc.Handler.EVENT_TOUCH_BEGAN ) -- local eventDispatcher = gameLayer:getEventDispatcher() eventDispatcher:addEventListenerWithSceneGraphPriority(listener, gameLayer) -- mainScene:addChild(gameLayer) -- - if cc.Director:getInstance():getRunningScene() then cc.Director:getInstance():replaceScene(mainScene) else cc.Director:getInstance():runWithScene(mainScene) end end function resetVariables() rotation = 0 scale = 1 ox = 0 oy = 0 delta = 20 moving = 0 end -- init()
Source: https://habr.com/ru/post/232013/
All Articles