quick-cocos2d-x学习系列之十六塔防完结
1.math2d.lua文件
该文件实现了常用的数学函数
Dist函数实现两点的距离。
radians4point求两点的夹角(弧度)
pointAtCircle求圆上一个点的位置
pointAtLineToPoint求线段上与指定点距离最近的点
degrees2radians角度转换为弧度
radians2degrees弧度转换为角度
2.utils.lua文件
2.1drawCircle
返回newCircle.
根据utils.useNVGDrawNode变量采用不同的方式。
如果utils.useNVGDrawNode为true,则返回NVGDrawNode.
2.2drawRect
同drawCircle函数,返回矩形。
2.3drawPolygon
同drawCircle函数,返回多变形。
Editor文件夹
这个文件夹中都是和地图编辑相关的文件。
1.AutoLayout.lua
定义了函数function AutoLayout.alignItemsHorizontally(items,x,y,padding,lines)
用于实现Item水平对齐。
2.EditorConstants.lua
该文件定义里一个表结构EditorConstants
local EditorConstants={}
EditorConstants.CHECK_POINT_DIST=6 EditorConstants.SELECTED_COLOR={255,255,255,255} EditorConstants.SELECTED_LABEL_COLOR={0,0,255} EditorConstants.UNSELECTED_COLOR={180,180,180,180} EditorConstants.UNSELECTED_LABEL_COLOR={0,0,0} EditorConstants.LABEL_OFFSET_Y=4 EditorConstants.LABEL_FONT=display.DEFAULT_TTF_FONT EditorConstants.LABEL_FONT_SIZE=14 EditorConstants.LABEL_ZORDER=100 EditorConstants.POLYGON_ZORDER=1000 EditorConstants.CIRCLE_ZORDER=2000 EditorConstants.FLAG_ZORDER=3000 EditorConstants.RANGE_HANDLER_ZORDER=4000 EditorConstants.BINDING_LABEL_ZORDER=5000 EditorConstants.PANEL_ZORDER=10000
EditorConstants.MAP_PADDING=200 EditorConstants.MAP_TOOLBAR_HEIGHT=48 EditorConstan
ts.PROPERTY_PREFIX_LEN=16 EditorConstants.BEHAVIOR_LABEL_WIDTH=110 EditorConstants.INSPECTOR_WIDTH=360 EditorConstants.PANEL_BUTTON_SIZE=40 EditorConstants.PANEL_BUTTON_OFFSET=4 EditorConstants.PANEL_OFFSET=4
EditorConstants.PANEL_LABEL_FONT="Courier" EditorConstants.PANEL_LABEL_FONT_SIZE=13
EditorConstants.TOOLBAR_PADDING=40
return EditorConstants
3.EditorScene.lua
定义一个EditorScene类。是编辑类的入口。
ctor
构造函数,设置变量lbarLines=1图片编辑器app
self.editorUIScale=1
self.statusCount_=1,根据平台设置变量editorUIScale,toolbarLines。通过图片EditorBg创建newTile
sSprite。
创建mapLayer,包含地图的整个视图
self.mapLayer_=wNode()
self.mapLayer_:align(display.LEFT_BOTTOM,0,0)
self:addChild(self.mapLayer_)
创建touchLayer用于接收触摸事件
self:uchLayer_)
创建uiLayer用于显示编辑器的UI(工具栏等)
self.uiLayer_=wNode()
self.uiLayer_:,)
self:addChild(self.uiLayer_)
--创建地图对象,地图项次查看app.map.Map.lua文件
self.map_=require("app.map.Map").new(LEVEL_ID,true)--参数:地图ID,是否是编辑器模式
self.map_:init()
self.map_:createView(self.mapLayer_)
--创建工具栏
-
-创建工具栏的视图
"#ToolbarBg.png",EditorConstants.TOOLBAR_PADDING,self.editorUIScale, lbarLines)
--创建对象信息面板
local objectInspectorScale=1
self.objectInspector_=
require("editor.ObjectInspector").new(self.map_,objectInspectorScale, lbarLines)
self.objectInspector_:addEventListener("UPDATE_OBJECT", function(event)
end)
self.objectInspector_:createView(self.uiLayer_)
--创建地图名称文字标签
self.mapNameLabel_=cc.w({
text=string.format("module:%s,image:%s",
self.map_.mapModuleName_,self.map_.imageName_),
size=16*self.editorUIScale,
align=cc.ui.TEXT_ALIGN_LEFT,
x=display.left+10,
y=display.bottom+EditorConstants.MAP_TOOLBAR_HEIGHT* self.lbarLines+20,
}):align(display.CENTER)
self.mapNameLabel_:enableOutline(cc.c4b(255,0,0),2)
self.mapLayer_:addChild(self.mapNameLabel_)
--注册工具栏事件
end)
self.objectInspector_:setObject(event.object)
end)
end)
self:playMap()
end)
--创建运行地图时的工具栏
self.playToolbar_=wNode()
if(device.platform=="mac"or device.platform=="windows")then
cc.w({normal="#ToggleDebugButton.png",pressed ="#ToggleDebugButtonSelected.png"})
:onButtonClicked(function(event)
self.map_:setDebugViewEnabled(not
self.map_:isDebugViewEnabled())
end)
:align(display.CENTER,display.left+32*self.editorUIScale, p-32*self.editorUIScale)
:addTo(self.playToolbar_)
:setScale(self.editorUIScale)
cc.w({normal="#StopMapButton.png",pressed= "#StopMapButtonSelected.png"})
:onButtonClicked(function(event)
self:editMap()
end)
:align(display.CENTER,display.left+88*self.editorUIScale, p-32*self.editorUIScale)
:addTo(self.playToolbar_)
:setScale(self.editorUIScale)
else
:setButtonLabel(cc.w({text="开始性能测试",size=20, color=display.COLOR_BLACK}))
:setButtonSize(130,40)