quick cocos2d-x 实现划线轨迹,精灵匀速跟随移动的效果
2014-12-03 19:08
288 查看
local MainScene = class("MainScene", function() return display.newScene("MainScene") end) local CURRENT_MODULE_NAME = ... local Queue = import("./Queue", CURRENT_MODULE_NAME) function MainScene:ctor() local draw_node = CCDrawNode:create() self:addChild(draw_node) local sp = display.newSprite("res/res.png", 0, 0) self:addChild(sp) self.myQueue = Queue.new(100) self.layer = display.newLayer() self.layer:setTouchEnabled(true) self.layer:setTouchMode(cc.TOUCH_MODE_ONE_BY_ONE) self.layer:addNodeEventListener(cc.NODE_TOUCH_EVENT, function(event) if event.name == "began" then sp:setPosition(event.x,event.y) return true elseif event.name == "moved" then draw_node:drawDot(ccp(event.x, event.y), 3, ccc4f(220, 10, 10, 222)) local point = ccp(event.x, event.y) self.myQueue:enQueue(point) print("ENQUEUE: "..point.x.." , "..point.y) elseif event.name == "ended" then end end) self:addChild(self.layer) CCDirector:sharedDirector():getScheduler():scheduleScriptFunc(function(dt) if self.point == nil and self.myQueue:isEmpty() == false then self.point = self.myQueue:deQueue() print("DEQUEUE"..self.point.x.." , "..self.point.y) end if self.point ~= nil then if math.floor(self.point.x) - math.floor(sp:getPositionX()) < 0 then self.x= -1 elseif math.floor(self.point.x) - math.floor(sp:getPositionX()) > 0 then self.x= 1 else self.x = 0 end if math.floor(self.point.y) - math.floor(sp:getPositionY()) < 0 then self.y=-1 elseif math.floor(self.point.y) - math.floor(sp:getPositionY()) > 0 then self.y= 1 else self.y= 0 end local spX = sp:getPositionX() + self.x local spY = sp:getPositionY() + self.y sp:setPosition(ccp(spX, spY)) if math.floor(spX) == math.floor(self.point.x) and math.floor(spY) == math.floor(self.point.y) then self.point = nil end end end, 0.01, false) end function MainScene:onEnter() end function MainScene:onExit() end return MainScene
代码还有一个队列,直接拿我以前写的一个Queue。地址在:http://www.cnblogs.com/vokie/p/4110003.html
效果就是画出轨迹线路,精灵可以沿着轨迹线路匀速运动起来。代码基于quick 2.2.5
效果图片
相关文章推荐
- javascript实现图片跟随鼠标移动效果的方法
- 实现ViewPager新手引导页的指示点跟随移动的效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- Android实现View拖拽跟随手指移动效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- javascript实现图片跟随鼠标移动效果的方法
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- Android最简单的实现View拖拽跟随手指移动效果
- 完整的html+css+javascript实现跟随鼠标移动显示选中效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- 在一个Activity页面中View跟随手指移动,并且能实现点击效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- quick-cocos2d-x(lua) 拖动精灵使其在屏幕移动的效果实现
- 安卓仿手机QQ消息BadgeView气泡跟随手指移动,并实现进出动画效果。
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果