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
  • 相关阅读:
    git cmd 命令在已有的仓库重新添加新的文件夹
    google guava Multimap的学习介绍
    JavaScript笔记基础版
    初识hive
    深入学习HBase架构原理
    初识Azkaban
    MapReduce工作流多种实现方式
    Hive 分组问题
    sqoop使用中的小问题
    Sqoop 结合多种系统的具体应用
  • 原文地址:https://www.cnblogs.com/yufenghou/p/4323354.html
Copyright © 2011-2022 走看看