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
  • 相关阅读:
    定时器Timer的使用
    Queue和BlockingQueue的使用以及使用BlockingQueue实现生产者-消费者
    ReentrantReadWriteLock读写锁的使用
    利用Lucene与Nutch构建简单的全文搜索引擎
    再见了,DM
    互联网公司高并发图片(缩略图)处理中间层服务架构设计一
    poj 3131 双向搜索+hash判重
    [置顶] linux常用命令大全
    堆排序
    iOS UIView非常用方法及属性详解
  • 原文地址:https://www.cnblogs.com/yufenghou/p/4323354.html
Copyright © 2011-2022 走看看