码迷,mamicode.com
首页 > 其他好文 > 详细

quick cocos collion

时间:2015-03-09 14:26:30      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

local scheduler = require(cc.PACKAGE_NAME .. ".scheduler")

local MainScene = class("MainScene", function()
    return display.newScene("MainScene")
end)

function MainScene:ctor()

    --add Plist
    display.addSpriteFrames("bandit.plist","bandit.png")
    display.addSpriteFrames("gun/guns.plist","gun/guns.png")
    display.addSpriteFrames("fx/fx.plist","fx/fx.png")
    display.addSpriteFrames("projectiles/projectiles.plist","projectiles/projectiles.png")
    display.addSpriteFrames("pickups/pickups.plist","pickups/pickups.png")

    local hero=display.newSprite("#player_idle1.png",display.cx,display.cy):addTo(self)
    local heroPosX,heroPosY=hero:getPosition()
    hero.CollionRect={x=-15,y=-28,width=30,height=38}
    local heroBox={
        x=heroPosX+hero.CollionRect.x,
        y=heroPosY+hero.CollionRect.y,
        width=hero.CollionRect.width,
        height=hero.CollionRect.height
    }   
    
    display.newSprite("res/test/mark.png",heroBox.x,heroBox.y):addTo(self)
    display.newSprite("res/test/mark.png",heroBox.x,heroBox.y+heroBox.height):addTo(self)
    display.newSprite("res/test/mark.png",heroBox.x+heroBox.width,heroBox.y):addTo(self)
    display.newSprite("res/test/mark.png",heroBox.x+heroBox.width,heroBox.y+heroBox.height):addTo(self)
    
 
    local coin=display.newSprite("#silver_coin1.png",display.cx-23,display.cy+20):addTo(self)
    local coinPosX,coinPosY=coin:getPosition()
    coin.CollionRect={x=-8,y=-12,width=16,height=15}
    local coinBox={
          x=coinPosX+coin.CollionRect.x,
          y=coinPosY+coin.CollionRect.y,
          width=coin.CollionRect.width,
          height=coin.CollionRect.height
    }   
    

    display.newSprite("res/test/mark.png",coinBox.x,coinBox.y):addTo(self)
    display.newSprite("res/test/mark.png",coinBox.x,coinBox.y+coinBox.height):addTo(self)
    display.newSprite("res/test/mark.png",coinBox.x+coinBox.width,coinBox.y):addTo(self)
    display.newSprite("res/test/mark.png",coinBox.x+coinBox.width,coinBox.y+coinBox.height):addTo(self)

 
    print(cc.rectIntersectsRect(heroBox,coinBox))

end

return MainScene

 

quick cocos collion

标签:

原文地址:http://www.cnblogs.com/yufenghou/p/4323354.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!