Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SSIWB2504
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
SSIWB2504
Commits
1f40bad1
Commit
1f40bad1
authored
Aug 04, 2025
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
基本处理完成
parent
02315afe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
243 additions
and
35 deletions
+243
-35
API文档.md
API文档.md
+41
-16
play.component.ts
src/app/play/play.component.ts
+202
-19
No files found.
API文档.md
View file @
1f40bad1
...
@@ -2,19 +2,45 @@
...
@@ -2,19 +2,45 @@
## 目录
## 目录
-
[
基础工具库 (Unit.ts)
](
#基础工具库-unitts
)
-
[
East\_L210 游戏引擎 API 文档
](
#east_l210-游戏引擎-api-文档
)
-
[
精灵类
](
#精灵类
)
-
[
目录
](
#目录
)
-
[
文本渲染
](
#文本渲染
)
-
[
基础工具库 (Unit.ts)
](
#基础工具库-unitts
)
-
[
形状绘制
](
#形状绘制
)
-
[
精灵类
](
#精灵类
)
-
[
动画控制
](
#动画控制
)
-
[
Sprite
](
#sprite
)
-
[
工具函数
](
#工具函数
)
-
[
MySprite
](
#mysprite
)
-
[
游戏框架 (Cartoon.ts)
](
#游戏框架-cartoontss
)
-
[
ColorSpr
](
#colorspr
)
-
[
资源管理
](
#资源管理
)
-
[
GrayscaleSpr
](
#grayscalespr
)
-
[
元素创建与管理
](
#元素创建与管理
)
-
[
文本渲染
](
#文本渲染
)
-
[
坐标系统
](
#坐标系统
)
-
[
Label
](
#label
)
-
[
动画控制
](
#动画控制-1
)
-
[
BitMapLabel
](
#bitmaplabel
)
-
[
动画控制器 (CartoonAnimation.ts)
](
#动画控制器-cartoonanimationts
)
-
[
RichText
](
#richtext
)
-
[
游戏内容容器 (player-content-wrapper)
](
#游戏内容容器-player-content-wrapper
)
-
[
形状绘制
](
#形状绘制
)
-
[
ShapeRect
](
#shaperect
)
-
[
ShapeRectNew
](
#shaperectnew
)
-
[
ShapeCircle
](
#shapecircle
)
-
[
动画控制
](
#动画控制
)
-
[
MyAnimation
](
#myanimation
)
-
[
工具函数
](
#工具函数
)
-
[
动画工具
](
#动画工具
)
-
[
数学工具
](
#数学工具
)
-
[
特效工具
](
#特效工具
)
-
[
游戏框架 (Cartoon.ts)
](
#游戏框架-cartoonts
)
-
[
资源管理
](
#资源管理
)
-
[
音频管理
](
#音频管理
)
-
[
图像管理
](
#图像管理
)
-
[
元素创建与管理
](
#元素创建与管理
)
-
[
坐标系统
](
#坐标系统
)
-
[
动画控制
](
#动画控制-1
)
-
[
动画控制器 (CartoonAnimation.ts)
](
#动画控制器-cartoonanimationts
)
-
[
游戏内容容器 (player-content-wrapper)
](
#游戏内容容器-player-content-wrapper
)
-
[
组件结构
](
#组件结构
)
-
[
使用示例
](
#使用示例
)
-
[
基础精灵创建与动画
](
#基础精灵创建与动画
)
-
[
文本与形状绘制
](
#文本与形状绘制
)
-
[
自定义动画
](
#自定义动画
)
-
[
坐标系统使用
](
#坐标系统使用
)
-
[
特效使用
](
#特效使用
)
-
[
在Angular应用中集成
](
#在angular应用中集成
)
## 基础工具库 (Unit.ts)
## 基础工具库 (Unit.ts)
...
@@ -49,7 +75,7 @@
...
@@ -49,7 +75,7 @@
-
`anchorX`
,
`anchorY`
: 锚点位置
-
`anchorX`
,
`anchorY`
: 锚点位置
**方法:**
**方法:**
-
`init(img
)`
: 使用图像初始化精灵
-
`init(img
,anchorX, anchorY)`
: 使用图像初始化精灵,如果是矩形等,img传入null
-
`setScaleXY(scale)`
: 设置统一缩放
-
`setScaleXY(scale)`
: 设置统一缩放
-
`addChild(child)`
: 添加子精灵
-
`addChild(child)`
: 添加子精灵
-
`removeChild(child)`
: 移除子精灵
-
`removeChild(child)`
: 移除子精灵
...
@@ -607,4 +633,4 @@ import { PlayerContentWrapperComponent } from './common/player-content-wrapper/p
...
@@ -607,4 +633,4 @@ import { PlayerContentWrapperComponent } from './common/player-content-wrapper/p
bootstrap
:
[
AppComponent
]
bootstrap
:
[
AppComponent
]
})
})
export
class
AppModule
{
}
export
class
AppModule
{
}
```
```
\ No newline at end of file
src/app/play/play.component.ts
View file @
1f40bad1
...
@@ -259,21 +259,23 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -259,21 +259,23 @@ export class PlayComponent implements OnInit, OnDestroy {
initGame
()
{
initGame
()
{
// 初始化游戏背景
// 初始化游戏背景
this
.
initBackground
()
this
.
initBackground
()
// 初始化标题
this
.
initTitle
();
this
.
initListPage
();
// 初始化退出按钮
// // 初始化标题
this
.
initBtnBack
();
// this.initTitle();
const
partXList
=
this
.
g_formData
.
type
==
0
?
[
300
*
this
.
g_mapScale
,
700
*
this
.
g_mapScale
,
1100
*
this
.
g_mapScale
]
:
[
700
*
this
.
g_mapScale
,
300
*
this
.
g_mapScale
,
1100
*
this
.
g_mapScale
];
// // 初始化退出按钮
// 初始化第一部分内容(字母块)
// this.initBtnBack();
this
.
initPart1
(
partXList
[
0
]);
// const partXList = this.g_formData.type == 0 ? [300 * this.g_mapScale, 700 * this.g_mapScale, 1100 * this.g_mapScale] : [700 * this.g_mapScale, 300 * this.g_mapScale, 1100 * this.g_mapScale];
// 初始化第二部分内容(字母块)
// // 初始化第一部分内容(字母块)
this
.
initPart2
(
partXList
[
1
]);
// this.initPart1(partXList[0]);
// 初始化第三部分内容(字母块)
// // 初始化第二部分内容(字母块)
this
.
initPart3
(
partXList
[
2
]);
// this.initPart2(partXList[1]);
// 初始化文字
// // 初始化第三部分内容(字母块)
this
.
initWords
();
// this.initPart3(partXList[2]);
// 初始化连接线
// // 初始化文字
this
.
drawConnectionLines
();
// this.initWords();
// // 初始化连接线
// this.drawConnectionLines();
}
}
/**
/**
...
@@ -338,6 +340,180 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -338,6 +340,180 @@ export class PlayComponent implements OnInit, OnDestroy {
this
.
render
(
element
.
ref
,
zIndexMap
.
background
)
this
.
render
(
element
.
ref
,
zIndexMap
.
background
)
}
}
/**
* 初始化列表页面
* 创建一个可滑动的列表页面,包含多个子节点
*/
initListPage
()
{
// 创建layout_page空节点作为页面容器
const
layoutPage
=
this
.
g_cartoon
.
createCartoonElement
(
'
layout_page
'
,
'
ShapeRectNew
'
);
layoutPage
.
ref
.
init
(
null
);
layoutPage
.
ref
.
x
=
this
.
g_canvasWidth
/
2
;
layoutPage
.
ref
.
y
=
this
.
g_canvasHeight
/
2
;
layoutPage
.
ref
.
fillColor
=
'
rgba(0, 0, 0, 0)
'
;
// // 创建list_item节点作为滑动列表容器
const
listItem
=
this
.
g_cartoon
.
createCartoonElement
(
'
list_item
'
,
'
ShapeRectNew
'
);
// 设置固定高度为800
const
listHeight
=
800
;
// 每列最多2个子节点
const
maxItemsPerColumn
=
2
;
// 子节点数量
const
totalItems
=
20
;
// 计算需要的列数
const
columnsNeeded
=
Math
.
ceil
(
totalItems
/
maxItemsPerColumn
);
// 每个子节点的宽度和高度
const
itemWidth
=
300
;
const
itemHeight
=
300
;
// 子节点之间的间距
const
itemSpacing
=
50
;
// 计算list_item的总宽度
const
listWidth
=
columnsNeeded
*
(
itemWidth
+
itemSpacing
)
-
itemSpacing
;
// 初始化list_item - 将锚点设置为左侧 (0, 0.5)
listItem
.
ref
.
init
(
null
,
0
,
0.5
);
listItem
.
ref
.
x
=
0
;
//listWidth / 2; // 设置初始位置,使列表居中显示
listItem
.
ref
.
y
=
this
.
g_canvasHeight
/
2
;
listItem
.
ref
.
fillColor
=
'
rgba(231, 193, 193, 0.5)
'
;
// 设置list_item的宽高
listItem
.
ref
.
setSize
(
listWidth
,
listHeight
);
// 记录初始位置,用于滑动计算
let
startX
=
0
;
let
startY
=
0
;
let
isDragging
=
false
;
let
isPressed
=
false
;
// 新增管控变量,控制move事件的触发
let
listItemStartX
=
listItem
.
ref
.
x
;
// 创建子节点
for
(
let
i
=
0
;
i
<
totalItems
;
i
++
)
{
// 计算当前子节点所在的列和行
const
column
=
Math
.
floor
(
i
/
maxItemsPerColumn
);
const
row
=
i
%
maxItemsPerColumn
;
// 创建子节点
const
itemNode
=
this
.
g_cartoon
.
createCartoonElement
(
`list_item_
${
i
}
`
,
'
MySprite
'
);
// 使用pao_pao_da_png作为临时资源
itemNode
.
ref
.
init
(
this
.
g_cartoon
.
images
.
get
(
'
pao_pao_da_png
'
));
// 计算子节点位置 - 基于左锚点的坐标计算
// X坐标:从左到右排列,考虑间距,基于listItem的左边界
const
itemX
=
listItem
.
ref
.
x
+
(
column
*
(
itemWidth
+
itemSpacing
))
+
(
itemWidth
/
2
);
// Y坐标:从上到下排列,考虑间距,基于listItem的中心
const
itemY
=
listItem
.
ref
.
y
+
(
row
*
(
itemHeight
+
itemSpacing
))
+
(
itemHeight
/
2
)
-
(
listHeight
/
2
);
// 设置子节点位置和缩放
itemNode
.
ref
.
x
=
itemX
;
itemNode
.
ref
.
y
=
itemY
;
itemNode
.
ref
.
scaleX
=
itemWidth
/
itemNode
.
ref
.
width
;
itemNode
.
ref
.
scaleY
=
itemHeight
/
itemNode
.
ref
.
height
;
// 为每个itemNode添加序号文字子节点
const
textElement
=
this
.
g_cartoon
.
createCartoonElement
(
`list_item_text_
${
i
}
`
,
'
Label
'
);
// 设置文字内容为对应的序号(从1开始)
textElement
.
ref
.
text
=
(
i
+
1
).
toString
();
// 设置字号为80,颜色为黑色
textElement
.
ref
.
fontSize
=
80
*
this
.
g_mapScale
;
textElement
.
ref
.
fontColor
=
'
#000000
'
;
// 设置文字位置与itemNode相同
textElement
.
ref
.
x
=
itemX
;
textElement
.
ref
.
y
=
itemY
;
// 设置文本对齐方式为居中
textElement
.
ref
.
textAlign
=
'
center
'
;
// 为子节点添加点击事件
this
.
m_mapDownQueue
[
`list_item_
${
i
}
`
]
=
()
=>
{
if
(
!
isDragging
)
{
// 播放音效
this
.
g_cartoon
.
playAudio
(
'
click
'
);
// 添加果冻动画效果
}
};
// 渲染子节点和文字
this
.
render
(
itemNode
.
ref
,
zIndexMap
.
card
);
this
.
render
(
textElement
.
ref
,
zIndexMap
.
card
+
1
);
}
// 添加滑动功能
// 订阅按下事件
this
.
subscribeMapDownEvent
(
'
list_item
'
,
(
e
)
=>
{
console
.
log
(
"
list_item_down
"
,
e
);
isDragging
=
false
;
isPressed
=
true
;
// 设置按下状态为true
startX
=
this
.
g_clickX
;
startY
=
this
.
g_clickY
;
listItemStartX
=
listItem
.
ref
.
x
;
// 重新启用事件处理
this
.
g_enableMapDown
=
true
;
this
.
g_enableMapMove
=
true
;
this
.
g_enableMapUp
=
true
;
});
// 订阅移动事件
this
.
subscribeMapMoveEvent
(
'
list_item
'
,
(
e
)
=>
{
// 只有在按下状态时才处理移动事件
if
(
!
isPressed
)
{
return
;
}
console
.
log
(
"
list_item_move
"
,
e
)
// 计算移动距离
const
deltaX
=
this
.
g_clickX
-
startX
;
// 如果移动距离超过阈值,标记为拖拽状态
if
(
Math
.
abs
(
deltaX
)
>
10
)
{
isDragging
=
true
;
}
if
(
isDragging
)
{
// 计算新位置 - 基于左锚点的位置计算
let
newX
=
listItemStartX
+
deltaX
;
// 限制滑动范围,防止滑出边界 - 基于左锚点的边界计算
const
minX
=
0
;
// 左边界:列表左边缘不能超出画布左边
const
maxX
=
this
.
g_canvasWidth
-
listWidth
;
// 右边界:列表右边缘不能超出画布右边
newX
=
Math
.
max
(
minX
,
Math
.
min
(
newX
,
maxX
));
// 更新list_item位置
listItem
.
ref
.
x
=
newX
;
// 更新所有子节点位置 - 基于新的listItem位置重新计算
for
(
let
i
=
0
;
i
<
totalItems
;
i
++
)
{
const
column
=
Math
.
floor
(
i
/
maxItemsPerColumn
);
const
row
=
i
%
maxItemsPerColumn
;
const
itemNode
=
this
.
g_cartoon
.
getCartoonElement
(
`list_item_
${
i
}
`
);
const
textElement
=
this
.
g_cartoon
.
getCartoonElement
(
`list_item_text_
${
i
}
`
);
if
(
itemNode
)
{
const
itemX
=
listItem
.
ref
.
x
+
(
column
*
(
itemWidth
+
itemSpacing
))
+
(
itemWidth
/
2
);
itemNode
.
ref
.
x
=
itemX
;
// 同时更新对应的文字位置
if
(
textElement
)
{
textElement
.
ref
.
x
=
itemX
;
}
}
}
}
// 重新启用移动事件
this
.
g_enableMapMove
=
true
;
});
// 订阅抬起事件
this
.
subscribeMapUpEvent
(
'
list_item
'
,
(
e
)
=>
{
console
.
log
(
"
list_item_up
"
,
e
)
isDragging
=
false
;
isPressed
=
false
;
// 设置按下状态为false,停止move事件处理
// 重新启用事件处理
this
.
g_enableMapUp
=
true
;
});
// 渲染list_item
this
.
render
(
listItem
.
ref
,
zIndexMap
.
card
);
// 渲染layout_page
this
.
render
(
layoutPage
.
ref
,
zIndexMap
.
card
);
}
/**
/**
* 更新字母卡片的显示状态
* 更新字母卡片的显示状态
...
@@ -1210,10 +1386,17 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -1210,10 +1386,17 @@ export class PlayComponent implements OnInit, OnDestroy {
// 预加载资源
// 预加载资源
this
.
g_cartoon
.
loadResources
().
then
(()
=>
{
this
.
g_cartoon
.
loadResources
().
then
(()
=>
{
window
[
"
air
"
].
hideAirClassLoading
(
this
.
g_KEY
,
this
.
g_data
);
try
{
this
.
initSystem
();
// 确保window["air"]存在
this
.
update
();
if
(
window
[
"
air
"
]
&&
typeof
window
[
"
air
"
].
hideAirClassLoading
===
'
function
'
)
{
this
.
systemReady
()
window
[
"
air
"
].
hideAirClassLoading
(
this
.
g_KEY
,
this
.
g_data
);
}
this
.
initSystem
();
this
.
update
();
this
.
systemReady
();
}
catch
(
error
)
{
console
.
error
(
'
初始化系统时出错:
'
,
error
);
}
});
});
this
.
initListener
();
this
.
initListener
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment