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

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

Issue 15070003: [nacltoons] Add compound shapes. (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 7 years, 7 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
(...skipping 13 matching lines...) Expand all
24 print('LUA: ' .. string.format(...)) 24 print('LUA: ' .. string.format(...))
25 end 25 end
26 26
27 function util.PointToString(point) 27 function util.PointToString(point)
28 return string.format('%dx%d', point.x, point.y) 28 return string.format('%dx%d', point.x, point.y)
29 end 29 end
30 30
31 --- Create CCPoint from a lua table containing 2 elements. 31 --- Create CCPoint from a lua table containing 2 elements.
32 -- This is used to convert point data from .def files into 32 -- This is used to convert point data from .def files into
33 -- the cocos2dx coordinate space. 33 -- the cocos2dx coordinate space.
34 function util.PointFromLua(point) 34 function util.PointFromLua(point, relative)
35 return CCPointMake(point[1] + game_obj.origin.x, point[2] + game_obj.origin. y) 35 if relative then
36 return ccp(point[1], point[2])
37 else
38 return ccp(point[1] + game_obj.origin.x, point[2] + game_obj.origin.y)
39 end
36 end 40 end
37 41
38 --- Convert CCPoint to b2Vec. 42 --- Convert CCPoint to b2Vec.
39 function util.b2VecFromCocos(cocos_vec) 43 function util.b2VecFromCocos(cocos_vec)
40 return b2Vec2:new_local(util.ScreenToWorld(cocos_vec.x), 44 return b2Vec2:new_local(util.ScreenToWorld(cocos_vec.x),
41 util.ScreenToWorld(cocos_vec.y)) 45 util.ScreenToWorld(cocos_vec.y))
42 end 46 end
43 47
44 --- Load a yaml file and return a lua table that represents the data 48 --- Load a yaml file and return a lua table that represents the data
45 -- in the file. 49 -- in the file.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 table.insert(sb, string.format("%s,\n", tostring(value))) 203 table.insert(sb, string.format("%s,\n", tostring(value)))
200 else 204 else
201 table.insert(sb, string.format("'%s',\n", tostring(value))) 205 table.insert(sb, string.format("'%s',\n", tostring(value)))
202 end 206 end
203 end 207 end
204 end 208 end
205 209
206 table.insert(sb, string.rep (' ', indent - 2)) 210 table.insert(sb, string.rep (' ', indent - 2))
207 table.insert(sb, '}\n') 211 table.insert(sb, '}\n')
208 return table.concat(sb) 212 return table.concat(sb)
209
210 end 213 end
211 214
212 return util 215 return util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698