cocos2dx 物理世界

cocos2dx 物理世界,第1张

概述local MainScene = class("MainScene", function() return display.newPhysicsScene()end)function MainScene:onTouch(eventType,x,y) print("the name is---"..eventType.."--x--"..x.."--y--"..y)
local MainScene = class("MainScene",function()    return display.newPhysiCSScene()end)function MainScene:ontouch(eventType,x,y)    print("the name is---"..eventType.."--x--"..x.."--y--"..y)    if eventType=="began" then        self:createCoin(x,y)    endendfunction MainScene:ctor()    self.layer=display.newLayer():addTo(self)    self.layer:addNodeEventListener(cc.NODE_touch_EVENT,function(event)        return self:ontouch(event.name,event.x,event.y)    end)    self.world=self:getPhysicsWorld()    self.world:setGravity(cc.p(0,-200))    --    local Box=display.newNode()    Box:setAnchorPoint(cc.p(0.5,0.5))    Box:setPhysicsBody(cc.PhysicsBody:createEdgeBox(cc.size(800,600)))    Box:setposition(cc.p(480,320))    self:addChild(Box,10)    self:getPhysicsWorld():setDeBUGDrawMask(true and cc.PhysicsWorld.DEBUGDRAW_ALL or cc.PhysicsWorld.DEBUGDRAW_NONE)endfunction MainScene:createCoin(x,y)    -- add sprite to scene    local coinsprite = display.newSprite("button.png")    self:addChild(coinsprite)    local coinBody = cc.PhysicsBody:createBox(coinsprite:getBoundingBox(),cc.PhysicsMaterial(46,0.8,0.8))    coinBody:setMass(100)    coinsprite:setPhysicsBody(coinBody)    coinsprite:setposition(x,y)endfunction MainScene:onEnter()    endfunction MainScene:onEnterFrame(dt)    -- bodyendfunction MainScene:onExit()endreturn MainScene
总结

以上是内存溢出为你收集整理的cocos2dx 物理世界全部内容,希望文章能够帮你解决cocos2dx 物理世界所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1058220.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存