zoukankan      html  css  js  c++  java
  • quick cocos collion

    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
  • 相关阅读:
    handsontable-developer guide-data binding,data sources
    Android版Web服务器实现(三)HTTP响应
    Android版Web服务器实现(二)使用服务来监听HTTP请求
    HTTP协议详解(很详细)
    Android版Web服务器实现(一)HTTP协议请求头解析
    HTTP协议中Content-Length的详细解读。
    Android基于SwiFTP开源库的FTP实现(FTP匿名登录)
    Android之查看Wifi密码
    道德经与抽象、接口及框架
    JAVA中利用JNI与VS2012实现C/C++的DLL调用
  • 原文地址:https://www.cnblogs.com/yufenghou/p/4323354.html
Copyright © 2011-2022 走看看