Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
renderingEngine
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
王剑峰
renderingEngine
Commits
4e3fe988
Commit
4e3fe988
authored
Nov 07, 2019
by
wjf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
l
parent
c04ff844
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
24 deletions
+40
-24
Loader.ts
src/2d/loader/Loader.ts
+21
-24
RES.ts
src/zeroing/RES.ts
+19
-0
No files found.
src/2d/loader/Loader.ts
View file @
4e3fe988
import
{
EventDispatcher
}
from
"../events/EventDispatcher"
;
import
{
Parser
}
from
"../svga/parser"
;
import
{
VideoEntity
}
from
"../svga/VideoEntity"
;
import
{
EventDispatcher
}
from
"../events/EventDispatcher"
;
import
{
Parser
}
from
"../svga/parser"
;
import
{
VideoEntity
}
from
"../svga/VideoEntity"
;
export
class
Loader
extends
EventDispatcher
{
...
...
@@ -31,16 +31,26 @@ export class Loader extends EventDispatcher {
let
pngFile
=
url
.
substring
(
0
,
url
.
lastIndexOf
(
'.'
))
+
'.png'
;
this
.
loadImage
((
suc
,
data
)
=>
{
if
(
suc
)
{
this
.
cache
(
pngFile
,
data
);
if
(
this
.
caches
[
url
])
{
callback
(
true
,
{
json
:
this
.
caches
[
url
],
img
:
data
})
callback
(
true
,
{
json
:
this
.
caches
[
url
],
img
:
data
})
}
}
else
{
callback
(
false
,
data
)
}
},
pngFile
);
this
.
loadJson
((
suc
,
data
)
=>
{
if
(
suc
)
{
if
(
this
.
caches
[
pngFile
])
{
callback
(
true
,
{
json
:
data
,
img
:
this
.
caches
[
pngFile
]
})
}
}
else
{
callback
(
false
,
data
)
}
},
url
)
}
loadJson
(
callback
:
Function
,
url
:
string
)
{
//每次都要new
let
_req
;
if
(
window
[
"XMLHttpRequest"
])
{
...
...
@@ -56,41 +66,28 @@ export class Loader extends EventDispatcher {
_req
.
send
();
_req
.
onreadystatechange
=
()
=>
{
if
(
_req
.
readyState
==
4
&&
_req
.
status
==
200
)
{
// console.log(s._req.responseText);
// var obj = JSON.parse(_req.responseText);
// console.log(obj)
this
.
cache
(
url
,
_req
.
response
);
if
(
this
.
caches
[
pngFile
])
{
callback
(
true
,
{
json
:
_req
.
response
,
img
:
this
.
caches
[
pngFile
]})
}
callback
(
true
,
_req
.
response
)
}
};
_req
.
onerror
=
(
reason
):
void
=>
{
callback
(
false
,
reason
)
}
}
}
//暂时先不用fetch。safari兼容问题
// fetchAsync(url)
// .then((data) => {
// this.cache(url, data);
// if (this.caches[pngFile]) {
// callback(true, { json: data, img: this.caches[pngFile] })
// }
// // console.log(data)
// })
// .catch(reason => {
// callback(false, reason)
// // console.log(reason.message)
// })
loadTexture
(
url
:
string
)
{
this
.
loadImage
((
s
,
img
)
=>
{
if
(
s
)
this
.
cache
(
url
,
img
)
},
url
)
}
loadImage
(
callback
:
Function
,
url
:
string
,
crossOrigin
:
boolean
=
true
)
{
let
self
=
this
let
img
=
new
Image
();
if
(
crossOrigin
)
{
img
.
setAttribute
(
'crossOrigin'
,
'anonymous'
);
}
img
.
onload
=
function
(
e
)
{
self
.
cache
(
url
,
img
);
callback
(
true
,
img
);
};
img
.
onerror
=
function
(
e
)
{
...
...
src/zeroing/RES.ts
0 → 100644
View file @
4e3fe988
import
{
Loader
}
from
"../2d/loader/Loader"
;
import
{
Texture
}
from
"../2d/texture"
;
const
loader
=
new
Loader
;
const
caches
=
{}
export
function
loadTexture
(
url
:
string
)
{
loader
.
loadImage
(()
=>
{
},
url
,)
}
//loadText和loadJson
export
function
getRes
()
{
}
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