01219245/cocos2d/Platform1

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
This is part of 01219245.

This guide is very short. It only discuss various techniques in implementing platform games.

Here are a few useful links:

Collision detection: cc.Rect

Previously, we have implemented our own collision detection routine. However, Cocos2d-html5 has provided us with a few nice collision detection tools. See code here.

Related functions are:

  • Creation: cc.rect
  • Accessing functions: cc.rectGetMaxX, cc.rectGetMidX, cc.rectGetMinX, cc.rectGetMaxY, cc.rectGetMidY, cc.rectGetMinY
  • Testing:
    • cc.rectEqualToRect
    • cc.rectContainsRect
    • cc.rectContainsPoint
    • cc.rectIntersectsRect
    • cc.rectOverlapsRect
  • Manipulation:
    • cc.rectUnion
    • cc.rectIntersection

Bounding boxes and world co-ordinates

Intersection

Falling on top

Cocos-platform-fall-through.png

Example code

Cocos-jumper-platform.png

This is a sample Cocos2d-html5 project that has a jumper over a set of blocks. It implements simple physical movement and rectangular collision detection. View its source code at Bitbucket.