LoginSignup
0
0

More than 5 years have passed since last update.

[Lua] CCPointで四則演算子を使う

Last updated at Posted at 2014-11-21

Cocos2d-x Luaバインディングで、

local p = ccp(10, 20) + ccp(100, 200)
print(p.x, p.y)  -- 110  220

のようなことをする方法.

local ccpmt = getmetatable(ccp(0,0))
function ccpmt.__add(a, b)
  return ccp(a.x+b.x, a.y+b.y)
end

同じように、__sub, __mul, __div, __lenあたりを定義すれば-, *, /, #
CCPointに対して使えるようになる.

Cocos2d-x3の場合はccpをcc.pに.

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0