Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-libs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
劳工
zeroing-libs
Commits
f0f9841e
Commit
f0f9841e
authored
Aug 03, 2020
by
zjz1994
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码暂存
parent
38829cf5
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
325 additions
and
190 deletions
+325
-190
pintu.json
dist/customs/pintu.json
+7
-1
app.js
src/custom/pintu/debug/app.js
+1
-1
main.js
src/custom/pintu/debug/main.js
+110
-89
main.js.map
src/custom/pintu/debug/main.js.map
+1
-1
meta.json
src/custom/pintu/meta.json
+6
-0
GameView.ts
src/custom/pintu/src/game/GameView.ts
+52
-16
Tool.ts
src/custom/pintu/src/game/Tool.ts
+29
-0
qietu.ts
src/custom/pintu/src/game/qietu.ts
+100
-73
utils.ts
src/custom/pintu/src/game/utils.ts
+19
-9
No files found.
dist/customs/pintu.json
View file @
f0f9841e
This diff is collapsed.
Click to expand it.
src/custom/pintu/debug/app.js
View file @
f0f9841e
...
...
@@ -48,7 +48,7 @@ function launchWithCustomModule(customModule) {
setTimeout
(()
=>
{
engine
.
globalEvent
.
dispatchEvent
(
'pictures-initgame'
,
{
gameUrls
:[
"https://yun.duiba.com.cn/aurora/assets/5906e5670cb7061dfc77306087e9a79d4bbcb250.jpg"
,
"https://yun.duiba.com.cn/aurora/assets/5906e5670cb7061dfc77306087e9a79d4bbcb250
1
.jpg"
,
"https://yun.duiba.com.cn/aurora/assets/61fd0754d7924305fd2851be86a480d71d2c2981.jpg"
,
"https://yun.duiba.com.cn/aurora/assets/6b70d7ec626f35f21347bf5bc3e61bedc44167be.jpg"
],
...
...
src/custom/pintu/debug/main.js
View file @
f0f9841e
This diff is collapsed.
Click to expand it.
src/custom/pintu/debug/main.js.map
View file @
f0f9841e
This diff is collapsed.
Click to expand it.
src/custom/pintu/meta.json
View file @
f0f9841e
...
...
@@ -61,6 +61,12 @@
"url"
:
"//yun.duiba.com.cn/aurora/assets/1c384d986504d5aabfffeb5125dc67e73ce1b539.png"
,
"uuid"
:
"kuang4"
,
"ext"
:
".png"
},
{
"name"
:
"testimg"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/2628186c60c3b80013ae3178ff21a73ffbe71d43.jpg"
,
"uuid"
:
"morentu"
,
"ext"
:
".jpg"
}
],
"events"
:
{
...
...
src/custom/pintu/src/game/GameView.ts
View file @
f0f9841e
...
...
@@ -6,6 +6,7 @@ import { props } from "../props";
import
qietu
from
"./qietu"
;
import
{
getTexture
,
loadImageByUrl
,
getTextureByName
}
from
"./utils"
;
import
ObjectPool
=
engine
.
ObjectPool
;
import
Tool
from
"./Tool"
;
export
default
class
GameView
extends
engine
.
Container
{
rows
:
number
;
...
...
@@ -41,7 +42,7 @@ export default class GameView extends engine.Container {
gameUrls
:
Array
<
string
>
=
[];
gameTimes
:
Array
<
number
>
=
[];
onegamePics
:
Array
<
engine
.
Texture
>
=
[];
onegamePics
:
Array
<
any
>
=
[];
movesteps
:
number
=
0
;
startime
:
number
=
0
;
constructor
()
{
...
...
@@ -67,27 +68,46 @@ export default class GameView extends engine.Container {
this
.
linecont
.
addChild
(
this
.
lineShape
);
console
.
log
(
"拼图初始化完毕--------------"
);
//
console.log("拼图初始化完毕--------------");
engine
.
globalEvent
.
dispatchEvent
(
"pictures-time-initcomp"
,{});
this
.
removeEventListener
(
engine
.
Event
.
ADDED_TO_STAGE
,
this
.
initScene
,
this
);
}
// let testsuc = new engine.Label();
// testsuc.text = "直接成功";
// testsuc.size = 66;
// testsuc.fillColor = "red";
// this.addChild(testsuc);
// testsuc.y = 500;
// testsuc.width = 300;
// testsuc.height = 200;
// testsuc.addEventListener(engine.MouseEvent.CLICK,this.zhijieSuc,this);
}
// //测试直接成功
// zhijieSuc(){
// this.gameover(1);
// }
async
initgame
(){
console
.
log
(
"initgame---------"
);
this
.
gameUrls
=
props
.
gameUrls
;
this
.
gameTimes
=
props
.
gameTimes
;
//
console.log("initgame---------");
this
.
gameUrls
=
props
.
gameUrls
||
[
"https://yun.duiba.com.cn/db_games/activity/game/1596074071/resource/assets/ptimgs/28.jpg"
,
"https://yun.duiba.com.cn/db_games/activity/game/1596074071/resource/assets/ptimgs/29.jpg"
,
"https://yun.duiba.com.cn/db_games/activity/game/1596074071/resource/assets/ptimgs/30.jpg"
]
;
this
.
gameTimes
=
props
.
gameTimes
||
[
30
,
60
,
60
]
;
this
.
onegamePics
=
new
Array
();
for
(
let
l
=
0
;
l
<
this
.
gameUrls
.
length
;
l
++
){
let
lurl
=
this
.
gameUrls
[
l
];
let
lt
=
await
loadImageByUrl
(
lurl
)
as
engine
.
Texture
;
let
lt
=
await
loadImageByUrl
(
lurl
);
// console.log(lt);
if
(
lt
){
lt
=
lt
as
engine
.
Texture
}
else
{
lt
=
null
;
}
this
.
onegamePics
.
push
(
lt
);
if
(
this
.
onegamePics
.
length
==
1
){
//第一张图加载完毕,自动填充
this
.
startfirst
();
}
}
this
.
removeSelectImg
();
}
removeSelectImg
(){
if
(
this
.
selectimg3
){
...
...
@@ -97,8 +117,22 @@ export default class GameView extends engine.Container {
this
.
blockcont
.
removeChild
(
this
.
selectimg4
);
}
}
removeDiPics
(){
let
nume
=
this
.
dicont
.
children
.
length
;
for
(
let
i
=
nume
-
1
;
i
>=
0
;
i
--
){
let
ichild
=
this
.
dicont
.
getChildAt
(
i
)
as
engine
.
Container
;
if
(
ichild
){
ichild
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_DOWN
,
this
.
touchPic
,
this
);
this
.
dicont
.
removeChild
(
ichild
);
Tool
.
repushToPool
(
ichild
);
}
}
}
async
startfirst
(){
this
.
dicont
.
removeChildren
();
// this.dicont.removeChildren();
this
.
removeDiPics
();
this
.
movesteps
=
0
;
this
.
startime
=
Date
.
now
();
this
.
removeSelectImg
();
...
...
@@ -113,7 +147,7 @@ export default class GameView extends engine.Container {
engine
.
globalEvent
.
dispatchEvent
(
"pictures-time-passtime"
,{
passtime
:
this
.
passtime
});
console
.
log
(
"start-----------------"
,
actidx
);
//
console.log("start-----------------",actidx);
this
.
rows
=
3
;
this
.
cols
=
3
;
...
...
@@ -134,8 +168,9 @@ export default class GameView extends engine.Container {
let
type1
=
1
;
if
(
!
tex
){
tex
=
this
.
gameUrls
[
actidx
];
type1
=
2
;
type1
=
3
;
}
// type1 = 3;
let
result
=
await
qietu
(
tex
,
type1
,
this
.
rows
,
this
.
cols
,
this
.
dicont
);
let
res
=
result
.
res
;
if
(
res
){
...
...
@@ -190,7 +225,8 @@ export default class GameView extends engine.Container {
}
async
start
()
{
this
.
dicont
.
removeChildren
();
// this.dicont.removeChildren();
this
.
removeDiPics
();
this
.
movesteps
=
0
;
this
.
startime
=
Date
.
now
();
this
.
removeSelectImg
();
...
...
@@ -225,7 +261,7 @@ export default class GameView extends engine.Container {
let
type1
=
1
;
if
(
!
tex
){
tex
=
this
.
gameUrls
[
actidx
];
type1
=
2
;
type1
=
3
;
}
let
result
=
await
qietu
(
tex
,
type1
,
this
.
rows
,
this
.
cols
,
this
.
dicont
);
let
res
=
result
.
res
;
...
...
@@ -325,12 +361,12 @@ export default class GameView extends engine.Container {
}
pause
(){
this
.
ingame
=
false
;
console
.
error
(
"拼图暂停"
);
//
console.error("拼图暂停");
}
resume
(){
this
.
lastframetime
=
Date
.
now
();
this
.
ingame
=
true
;
console
.
error
(
"拼图继续"
);
//
console.error("拼图继续");
}
...
...
@@ -424,7 +460,7 @@ export default class GameView extends engine.Container {
}
let
isuc
=
this
.
checkSuccess
();
if
(
isuc
){
console
.
error
(
"成功过关"
);
//
console.error("成功过关");
this
.
gameover
(
1
);
}
}
...
...
src/custom/pintu/src/game/Tool.ts
0 → 100644
View file @
f0f9841e
export
default
class
Tool
{
static
picPool
:
Array
<
engine
.
Container
>
=
new
Array
();
static
getOnePic
(){
if
(
this
.
picPool
.
length
>
0
){
return
this
.
picPool
.
shift
();
}
else
{
let
ipic
=
new
engine
.
Container
();
let
isprite
=
new
engine
.
ScrollView
();
isprite
.
name
=
"iscrollv"
;
let
nsp
=
new
engine
.
Sprite
();
nsp
.
name
=
"isprite"
;
nsp
.
texture
isprite
.
addChild
(
nsp
);
ipic
.
addChild
(
isprite
);
isprite
.
mouseEnabled
=
false
;
nsp
.
mouseEnabled
=
false
;
return
ipic
;
}
}
static
repushToPool
(
icont
:
engine
.
Container
){
this
.
picPool
.
push
(
icont
);
}
}
\ No newline at end of file
src/custom/pintu/src/game/qietu.ts
View file @
f0f9841e
import
{
props
}
from
"../props"
;
import
{
loadImageByUrl
}
from
"./utils"
;
import
{
loadImageByUrl
,
getTextureByName
,
getTexture
}
from
"./utils"
;
import
qietu
from
"./qietu"
;
import
Tool
from
"./Tool"
;
const
urls
=
[];
const
picMap
=
{};
const
posMap
=
{};
...
...
@@ -9,69 +10,77 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin
let
t
:
engine
.
Texture
;
if
(
type1
==
1
){
t
=
url
;
}
else
{
t
=
await
loadImageByUrl
(
url
)
as
engine
.
Texture
;
}
else
if
(
type1
==
2
){
let
t1
=
await
loadImageByUrl
(
url
);
// as engine.Texture;
if
(
t1
){
t
=
t1
as
engine
.
Texture
;
}
}
else
if
(
type1
==
3
){
t
=
await
getTextureByName
(
"testimg"
)
as
engine
.
Texture
;
}
if
(
!
t
){
return
qietu
(
"testimg"
,
3
,
rows
,
cols
,
parent
);
}
let
setimgwid
=
612
;
let
mwid1
=
setimgwid
/
rows
;
let
mhei1
=
setimgwid
/
cols
;
let
mwid
=
t
.
width
;
let
mhei
=
t
.
height
;
if
(
mwid
<
10
||
mhei
<
10
){
await
new
Promise
(
res
=>
{
setTimeout
(
function
(){
res
();
},
200
);
})
return
qietu
(
t
,
1
,
rows
,
cols
,
parent
);
}
if
(
mwid
>
mhei
){
if
(
mhei
<
setimgwid
){
mwid
=
mwid
*
setimgwid
/
mhei
;
mhei
=
setimgwid
;
}
}
else
{
if
(
mwid
<
setimgwid
){
mhei
=
mhei
*
setimgwid
/
mwid
;
mwid
=
setimgwid
;
}
}
//
let mwid = t.width;
//
let mhei = t.height;
//
if(mwid<10||mhei<10){
//
await new Promise(res=>{
//
setTimeout(function(){
//
res();
//
},200);
//
})
//
return qietu(t,1,rows,cols,parent);
//
}
//
if(mwid>mhei){
//
if(mhei<setimgwid){
//
mwid = mwid*setimgwid/mhei;
//
mhei = setimgwid;
//
}
//
}else{
//
if(mwid<setimgwid){
//
mhei = mhei*setimgwid/mwid;
//
mwid = setimgwid;
//
}
//
}
let
picarr
=
{};
let
picnames
=
[];
let
chax
;
let
chay
;
let
startlix
;
let
addlix
;
let
startliy
;
let
addliy
;
let
twid1
;
let
thei1
;
if
(
mwid
>
mhei
){
chax
=
(
mwid
-
mhei
)
/
2
;
startlix
=
chax
/
mwid
;
addlix
=
(
mhei
/
cols
)
/
mwid
;
startliy
=
0
;
addliy
=
1
/
rows
;
twid1
=
mwid
*
setimgwid
/
mhei
;
thei1
=
setimgwid
;
}
else
{
startlix
=
0
;
addlix
=
1
/
cols
;
chay
=
(
mhei
-
mwid
)
/
2
;
startliy
=
chay
/
mhei
;
addliy
=
(
mwid
/
rows
)
/
mhei
;
thei1
=
mhei
*
setimgwid
/
mwid
;
twid1
=
setimgwid
;
}
let
startlix
=
0
;
let
addlix
=
1
/
rows
;
let
startliy
=
0
;
let
addliy
=
1
/
cols
;
let
twid1
=
setimgwid
;
let
thei1
=
setimgwid
;
//
if(mwid>mhei){
//
chax = (mwid-mhei)/2;
//
startlix = chax/mwid;
//
addlix = (mhei/cols)/mwid;
//
startliy = 0;
//
addliy = 1/rows;
//
twid1 = mwid*setimgwid/mhei;
//
thei1 = setimgwid;
//
}else{
//
startlix = 0;
//
addlix = 1/cols;
//
chay = (mhei-mwid)/2;
//
startliy = chay/mhei;
//
addliy = (mwid/rows)/mhei;
//
thei1 = mhei*setimgwid/mwid;
//
twid1 = setimgwid;
//
}
// console.log("切图准备",startlix,addlix,startliy,addliy,mwid,mhei);
// let txt1 = new engine.Label();
...
...
@@ -87,36 +96,46 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin
let
starty
=
startliy
+
addliy
*
c
;
let
endy
=
starty
+
addliy
;
let
uvs
=
new
Float32Array
([
starty
,
startx
,
endy
,
startx
,
endy
,
endx
,
starty
,
endx
])
// let uvs = new Float32Array([
// starty,
// startx,
// endy,
// startx,
// endy,
// endx,
// starty,
// endx
// ])
//方案1
// let isprite = new engine.Sprite(t);
// isprite.uvs = uvs;
let
nsprite
=
new
engine
.
Container
();
let
isprite
=
new
engine
.
ScrollView
();
let
nsp
=
new
engine
.
Sprite
(
t
);
isprite
.
addChild
(
nsp
);
//方案2
let
nsprite
=
Tool
.
getOnePic
();
let
isprite
=
nsprite
.
getChildByName
(
"iscrollv"
);
let
nsp
=
isprite
.
getChildByName
(
"isprite"
);
nsp
.
texture
=
t
;
nsp
.
width
=
twid1
;
nsp
.
height
=
thei1
;
isprite
.
mouseEnabled
=
false
;
isprite
.
mouseChildren
=
false
;
// let nsprite = new engine.Container();
// let isprite = new engine.ScrollView();
// let nsp = new engine.Sprite(t);
// isprite.addChild(nsp);
// nsp.width = twid1;
// nsp.height = thei1;
// isprite.mouseEnabled = false;
// isprite.mouseChildren = false;
nsp
.
x
=
-
starty
*
twid1
;
nsp
.
y
=
-
startx
*
thei1
;
isprite
.
width
=
mwid1
;
isprite
.
height
=
mhei1
;
nsprite
.
addChild
(
isprite
);
//
nsprite.addChild(isprite);
nsprite
.
width
=
mwid1
;
nsprite
.
height
=
mhei1
;
...
...
@@ -134,8 +153,16 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin
picnames
:
picnames
};
}
catch
(
e
){
return
{
res
:
false
};
//获取那图失败
// return {
// res:false
// };
await
new
Promise
(
res
=>
{
setTimeout
(
function
(){
res
();
},
200
);
})
return
qietu
(
"testimg"
,
3
,
rows
,
cols
,
parent
);
}
};
src/custom/pintu/src/game/utils.ts
View file @
f0f9841e
...
...
@@ -20,13 +20,23 @@ export function createSvga(name, anchorName?) {
}
export
async
function
loadImageByUrl
(
url
){
console
.
log
(
'loadImageByUrl----------:'
,
url
);
// console.log('loadImageByUrl----------:',url);
try
{
// console.log("尝试加载44");
return
new
Promise
((
resolve
)
=>
{
let
t1
=
setTimeout
(()
=>
{
return
resolve
(
null
);
},
2000
);
if
(
engine
.
TextureCache
[
url
])
{
clearTimeout
(
t1
);
resolve
(
engine
.
TextureCache
[
url
])
}
else
{
var
t
=
engine
.
Texture
.
from
(
url
);
t
.
addEventListener
(
"loaded"
,
()
=>
{
resolve
(
t
)
})
t
.
addEventListener
(
"loaded"
,
()
=>
{
clearTimeout
(
t1
);
resolve
(
t
)
});
}
})
}
catch
(
e
){
return
null
;
}
}
\ No newline at end of file
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