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

Side by Side Diff: nacltoons/data/res/drawing.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 -- Functions for drawing new sprites using a brush. 5 -- Functions for drawing new sprites using a brush.
6 -- This module defines a single 'drawing' global containing the following 6 -- This module defines a single 'drawing' global containing the following
7 -- functions: 7 -- functions:
8 -- - SetBrush 8 -- - SetBrush
9 -- - CreateShape 9 -- - CreateShape
10 -- - CreateSprite 10 -- - CreateSprite
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 local brush_color = ccc3(255, 100, 100) 51 local brush_color = ccc3(255, 100, 100)
52 52
53 -- Callbacks that are registered for drawn objects. The game 53 -- Callbacks that are registered for drawn objects. The game
54 -- can register its own callbacks here to add behavior for 54 -- can register its own callbacks here to add behavior for
55 -- drawn objects. 55 -- drawn objects.
56 drawing.handlers = {} 56 drawing.handlers = {}
57 57
58 --- Create a b2Vec from a lua list containing 2 elements. 58 --- Create a b2Vec from a lua list containing 2 elements.
59 -- This is used to convert point data from .def files directly 59 -- This is used to convert point data from .def files directly
60 -- to the box2dx coordinate system 60 -- to the box2dx coordinate system
61 local function b2VecFromLua(point) 61 local function b2VecFromLua(luapoint)
62 return util.b2VecFromCocos(util.PointFromLua(point)) 62 ccpoint = util.PointFromLua(luapoint)
binji 2013/06/25 22:17:21 local ccpoint?
Sam Clegg 2013/06/26 00:01:25 Done.
63 rtn = util.b2VecFromCocos(ccpoint)
binji 2013/06/25 22:17:21 local rtn?
Sam Clegg 2013/06/26 00:01:25 Done.
64 return rtn
63 end 65 end
64 66
65 local function CreateBrushBatch(parent) 67 local function CreateBrushBatch(parent)
66 local node = CCSpriteBatchNode:createWithTexture(brush_tex, DEFAULT_BATCH_CO UNT) 68 local node = CCSpriteBatchNode:createWithTexture(brush_tex, DEFAULT_BATCH_CO UNT)
67 assert(node) 69 assert(node)
68 parent:addChild(node, 1, TAG_BATCH_NODE) 70 parent:addChild(node, 1, TAG_BATCH_NODE)
69 return node 71 return node
70 end 72 end
71 73
72 --- Create a fixed pivot point between the world and the given body. 74 --- Create a fixed pivot point between the world and the given body.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 end 260 end
259 elseif shape_def.type == 'line' then 261 elseif shape_def.type == 'line' then
260 local pos = util.PointFromLua(shape_def.start) 262 local pos = util.PointFromLua(shape_def.start)
261 shape = CreatePhysicsNode(pos, shape_def.dynamic, shape_def.tag) 263 shape = CreatePhysicsNode(pos, shape_def.dynamic, shape_def.tag)
262 CreateBrushBatch(shape) 264 CreateBrushBatch(shape)
263 AddChildShape(shape, shape_def, true) 265 AddChildShape(shape, shape_def, true)
264 elseif shape_def.type == 'edge' then 266 elseif shape_def.type == 'edge' then
265 local body_def = b2BodyDef:new_local() 267 local body_def = b2BodyDef:new_local()
266 local body = level_obj.world:CreateBody(body_def) 268 local body = level_obj.world:CreateBody(body_def)
267 local b2shape = b2EdgeShape:new_local() 269 local b2shape = b2EdgeShape:new_local()
268 b2shape:Set(b2VecFromLua(shape_def.start), b2VecFromLua(shape_def.finish )) 270 local start = b2VecFromLua(shape_def.start)
271 local finish = b2VecFromLua(shape_def.finish)
272 util.Log('Create edge from: ' .. util.VecToString(start) .. ' to: ' .. u til.VecToString(finish))
273 b2shape:Set(start, finish)
269 body:CreateFixture(b2shape, 0) 274 body:CreateFixture(b2shape, 0)
270 return 275 return
271 elseif shape_def.type == 'image' then 276 elseif shape_def.type == 'image' then
272 local pos = util.PointFromLua(shape_def.pos) 277 local pos = util.PointFromLua(shape_def.pos)
273 shape = CreatePhysicsNode(pos, shape_def.dynamic, shape_def.tag) 278 shape = CreatePhysicsNode(pos, shape_def.dynamic, shape_def.tag)
274 AddChildShape(shape, shape_def, true) 279 AddChildShape(shape, shape_def, true)
275 else 280 else
276 assert(false, 'invalid shape type: ' .. shape_def.type) 281 assert(false, 'invalid shape type: ' .. shape_def.type)
277 end 282 end
278 283
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 333
329 -- Create the box2d physics body to match the sphere. 334 -- Create the box2d physics body to match the sphere.
330 local fixture = AddSphereToBody(node:getB2Body(), center, radius, false) 335 local fixture = AddSphereToBody(node:getB2Body(), center, radius, false)
331 SetCategory(fixture, DRAWING_CATEGORY) 336 SetCategory(fixture, DRAWING_CATEGORY)
332 return node 337 return node
333 end 338 end
334 339
335 function drawing.DrawEndPoint(node, location, color) 340 function drawing.DrawEndPoint(node, location, color)
336 -- Add visible sprite 341 -- Add visible sprite
337 local child_sprite = CCSprite:createWithTexture(brush_tex) 342 local child_sprite = CCSprite:createWithTexture(brush_tex)
338 location = node:convertToNodeSpace(location) 343 child_sprite:setPosition(node:convertToNodeSpace(location))
339 child_sprite:setPosition(location)
340 child_sprite:setColor(color) 344 child_sprite:setColor(color)
341 node:addChild(child_sprite) 345 node:addChild(child_sprite)
342 346
343 -- Add collision info 347 -- Add collision info
344 local body = node:getB2Body() 348 local body = node:getB2Body()
345 local fixture = AddSphereToBody(body, location, brush_thickness, false) 349 local fixture = AddSphereToBody(body, location, brush_thickness, false)
346 SetCategory(fixture, DRAWING_CATEGORY) 350 SetCategory(fixture, DRAWING_CATEGORY)
347 end 351 end
348 352
349 function drawing.AddLineToShape(sprite, from, to, color) 353 function drawing.AddLineToShape(sprite, from, to, color)
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 MakeBodyDynamic(current_shape.node:getB2Body()) 454 MakeBodyDynamic(current_shape.node:getB2Body())
451 455
452 local rtn = current_shape 456 local rtn = current_shape
453 last_pos = nil 457 last_pos = nil
454 start_pos = nil 458 start_pos = nil
455 current_shape = nil 459 current_shape = nil
456 return rtn 460 return rtn
457 end 461 end
458 462
459 return drawing 463 return drawing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698