Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scilla-core
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
劳工
scilla-core
Commits
36e5daf3
Commit
36e5daf3
authored
Jul 10, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
offX和offY应用上去
parent
5352e9ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
36 deletions
+30
-36
Texture.ts
src/core/Texture.ts
+30
-36
No files found.
src/core/Texture.ts
View file @
36e5daf3
...
...
@@ -2,11 +2,11 @@
* Created by rockyl on 2018/7/12.
*/
import
Bounds
from
"../support/Bounds"
;
import
HashObject
from
"../core/HashObject"
;
import
{
createCanvas
}
from
"./context/RenderContext"
;
import
{
Frame
}
from
"../ReType"
;
import
{
dirtyFieldDetector
}
from
"../tools/decorators"
;
import
{
dirtyFieldDetector
,
dirtyFieldTrigger
}
from
"../tools/decorators"
;
import
{
utils
}
from
"../tools"
;
/**
* 纹理类
...
...
@@ -15,7 +15,23 @@ export default class Texture extends HashObject {
@
dirtyFieldDetector
img
:
any
;
private
_bounds
:
Bounds
;
@
dirtyFieldTrigger
x
:
number
;
@
dirtyFieldTrigger
y
:
number
;
@
dirtyFieldTrigger
width
:
number
;
@
dirtyFieldTrigger
height
:
number
;
@
dirtyFieldTrigger
offX
:
number
=
0
;
@
dirtyFieldTrigger
offY
:
number
=
0
;
@
dirtyFieldTrigger
sourceW
:
number
;
@
dirtyFieldTrigger
sourceH
:
number
;
private
_cacheCanvas
;
private
_cacheContext
;
...
...
@@ -23,9 +39,6 @@ export default class Texture extends HashObject {
super
();
this
[
'isDirty'
]
=
true
;
this
.
_bounds
=
new
Bounds
(
0
,
0
,
0
,
0
,
()
=>
{
this
[
'isDirty'
]
=
true
;
});
}
/**
...
...
@@ -33,8 +46,13 @@ export default class Texture extends HashObject {
* @param frame
*/
setFrame
(
frame
:
Frame
)
{
let
{
x
,
y
,
w
,
h
}
=
frame
;
this
.
_bounds
.
setTo
(
x
,
y
,
w
,
h
);
utils
.
injectProp
(
this
,
frame
);
if
(
!
frame
.
hasOwnProperty
(
'sourceW'
))
{
frame
.
sourceW
=
frame
.
width
;
}
if
(
!
frame
.
hasOwnProperty
(
'sourceH'
))
{
frame
.
sourceH
=
frame
.
height
;
}
}
/**
...
...
@@ -45,27 +63,6 @@ export default class Texture extends HashObject {
this
.
img
=
img
;
}
/**
* 获取纹理宽度
*/
get
width
()
{
return
this
.
_bounds
.
width
;
}
/**
* 获取纹理高度
*/
get
height
()
{
return
this
.
_bounds
.
height
;
}
/**
* 获取边界
*/
get
bounds
():
Bounds
{
return
this
.
_bounds
;
}
/**
* 产生一个缓存画布
*/
...
...
@@ -75,7 +72,7 @@ export default class Texture extends HashObject {
if
(
this
[
'isDirty'
])
{
this
[
'isDirty'
]
=
false
;
const
{
_bounds
:
{
width
,
height
}
}
=
this
;
const
{
width
,
height
}
=
this
;
if
(
!
canvas
)
{
canvas
=
this
.
_cacheCanvas
=
createCanvas
();
...
...
@@ -89,8 +86,6 @@ export default class Texture extends HashObject {
canvas
.
width
=
width
;
canvas
.
height
=
height
;
this
.
drawToCanvas
(
context
);
this
.
drawToCanvas
(
context
);
}
return
canvas
;
...
...
@@ -107,9 +102,9 @@ export default class Texture extends HashObject {
* @param dh
*/
drawToCanvas
(
context
,
dx
=
0
,
dy
=
0
,
sx
?,
sy
?,
dw
?,
dh
?)
{
const
{
_bounds
:
{
x
,
y
,
width
,
height
}
}
=
this
;
const
{
x
,
y
,
width
,
height
,
offX
,
offY
}
=
this
;
context
.
drawImage
(
this
.
img
,
sx
||
x
,
sy
||
y
,
width
,
height
,
dx
,
dy
,
dw
||
width
,
dh
||
height
);
context
.
drawImage
(
this
.
img
,
sx
||
x
,
sy
||
y
,
width
,
height
,
dx
+
offX
,
dy
+
offY
,
dw
||
width
,
dh
||
height
);
}
/**
...
...
@@ -117,7 +112,6 @@ export default class Texture extends HashObject {
*/
destroy
()
{
this
.
img
=
null
;
this
.
_bounds
=
null
;
this
.
destroyCacheCanvas
();
}
...
...
@@ -138,7 +132,7 @@ export default class Texture extends HashObject {
export
function
createTexture
(
img
,
frame
?:
Frame
):
Texture
{
const
texture
=
new
Texture
();
texture
.
setImg
(
img
);
texture
.
setFrame
(
frame
||
{
x
:
0
,
y
:
0
,
w
:
img
.
width
,
h
:
img
.
height
});
texture
.
setFrame
(
frame
||
{
x
:
0
,
y
:
0
,
w
idth
:
img
.
width
,
height
:
img
.
height
});
return
texture
;
}
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