Quick cocos2d-x to achieve the dash track, the ELF uniform speed following the effect of movement

Source: Internet
Author: User
Tags addchild

1 LocalMainscene = Class ("Mainscene",function()2     returnDisplay.newscene ("Mainscene")3 End)4 LocalCurrent_module_name = ...5 LocalQueue = Import ("./queue", Current_module_name)6 functionMainscene:ctor ()7 8     LocalDraw_node =ccdrawnode:create ()9 self:addchild (Draw_node)Ten  One     LocalSP = Display.newsprite ("Res/res.png",0,0) A Self:addchild (SP) -Self.myqueue = Queue.new ( -) -  theSelf.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) +         ifEvent.name = ="began"  Then - sp:setposition (EVENT.X,EVENT.Y) +             return true A         ElseIfEvent.name = ="moved"  Then atDraw_node:drawdot (CCP (Event.x, Event.y),3, ccc4f ( -,Ten,Ten,222)) -             LocalPoint =CCP (Event.x, Event.y) -  - Self.myQueue:enQueue (point) -             Print("ENQUEUE:".. Point.x." ,  ".. POINT.Y) -         ElseIfEvent.name = ="ended"  Then in         End -     End) to self:addchild (Self.layer) +  -Ccdirector:shareddirector (): Getscheduler (): Schedulescriptfunc (function(DT) the         ifSelf.point = =Nil  andSelf.myQueue:isEmpty () = =false  Then *Self.point =Self.myQueue:deQueue () $             Print("DEQUEUE".. Self.point.x." ,  ".. SELF.POINT.Y)Panax Notoginseng         End     -  the         ifSelf.point ~=Nil  Then +             if Math.floor(self.point.x)-Math.floor(Sp:getpositionx ()) <0  Then ASelf.x=-1 the             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 theself.y=-1 -             ElseIf Math.floor(SELF.POINT.Y)-Math.floor(Sp:getpositiony ()) >0   ThenWuyiself.y=1 the             Else -self.y=0 Wu             End -  About             LocalSpX = Sp:getpositionx () +self.x $             LocalSpY = Sp:getpositiony () +Self.y -  - sp:setposition (CCP (SpX, SpY)) -  A             if Math.floor(SpX) = =Math.floor(Self.point.x) and Math.floor(SpY) = =Math.floor(SELF.POINT.Y) Then +Self.point =Nil the             End -         End $     End,0.01,false) the End the  the functionMainscene:onenter () the End -  in functionmainscene:onexit () the End the  About returnMainscene

The code also has a queue that directly takes the one I wrote previously. Address in: http://www.cnblogs.com/vokie/p/4110003.html

The effect is to draw the trajectory line, the genie can uniform motion along the track line. Code based on Quick 2.2.5

Chip

Quick cocos2d-x to achieve the dash track, the ELF uniform speed following the effect of movement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.