Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: nacltoons/data/res/util.lua

Issue 17743003: [nacltoons] Roll cocos2dx + two bug fixes (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 -- Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 -- Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 -- Use of this source code is governed by a BSD-style license that can be 2 -- Use of this source code is governed by a BSD-style license that can be
3 -- found in the LICENSE file. 3 -- found in the LICENSE file.
4 4
5 --- Utility functions and constants shared by nacltoons lua code 5 --- Utility functions and constants shared by nacltoons lua code
6 6
7 local yaml = require 'yaml' 7 local yaml = require 'yaml'
8 8
9 local util = {} 9 local util = {}
10 10
11 util.PTM_RATIO = 32 11 util.PTM_RATIO = 32
12 12
13 util.tags = { 13 util.tags = {
14 TAG_DYNAMIC_START = 0xff, 14 TAG_DYNAMIC_START = 0xff,
15 } 15 }
16 16
17 -- Convert a value from screen coordinate system to Box2D world coordinates 17 -- Convert a value from screen coordinate system to Box2D world coordinates
18 function util.ScreenToWorld(value) 18 function util.ScreenToWorld(value)
19 return value / util.PTM_RATIO 19 return value / util.PTM_RATIO
20 end 20 end
21 21
22 function util.WorldToScreen(value)
23 return value * util.PTM_RATIO
24 end
25
22 --- Log messages to console 26 --- Log messages to console
23 function util.Log(...) 27 function util.Log(arg)
24 print('LUA: ' .. string.format(...)) 28 print('LUA: ' .. tostring(arg))
25 end 29 end
26 30
27 function util.PointToString(point) 31 function util.PointToString(point)
28 return string.format('%dx%d', point.x, point.y) 32 return string.format('%dx%d', point.x, point.y)
29 end 33 end
30 34
35 function util.VecToString(v)
36 return string.format('%dx%d', util.WorldToScreen(v.x), util.WorldToScreen(v. y))
37 end
38
31 --- Create CCPoint from a lua table containing 2 elements. 39 --- Create CCPoint from a lua table containing 2 elements.
32 -- This is used to convert point data from .def files into 40 -- This is used to convert point data from .def files into
33 -- the cocos2dx coordinate space. 41 -- the cocos2dx coordinate space.
34 function util.PointFromLua(point, absolute) 42 function util.PointFromLua(point, absolute)
35 if absolute == nil then 43 if absolute == nil then
36 absolute = true 44 absolute = true
37 end 45 end
38 if abolute then 46 if absolute then
39 return ccp(point[1] + game_obj.origin.x, point[2] + game_obj.origin.y) 47 return ccp(point[1] + game_obj.origin.x, point[2] + game_obj.origin.y)
40 else 48 else
41 return ccp(point[1], point[2]) 49 return ccp(point[1], point[2])
42 end 50 end
43 end 51 end
44 52
45 --- Convert CCPoint to b2Vec. 53 --- Convert CCPoint to b2Vec.
46 function util.b2VecFromCocos(cocos_vec) 54 function util.b2VecFromCocos(cocos_vec)
47 return b2Vec2:new_local(util.ScreenToWorld(cocos_vec.x), 55 return b2Vec2:new_local(util.ScreenToWorld(cocos_vec.x),
48 util.ScreenToWorld(cocos_vec.y)) 56 util.ScreenToWorld(cocos_vec.y))
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 end 217 end
210 end 218 end
211 end 219 end
212 220
213 table.insert(sb, string.rep (' ', indent - 2)) 221 table.insert(sb, string.rep (' ', indent - 2))
214 table.insert(sb, '}\n') 222 table.insert(sb, '}\n')
215 return table.concat(sb) 223 return table.concat(sb)
216 end 224 end
217 225
218 return util 226 return util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698