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
Show 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 @@
...
@@ -2,11 +2,11 @@
* Created by rockyl on 2018/7/12.
* Created by rockyl on 2018/7/12.
*/
*/
import
Bounds
from
"../support/Bounds"
;
import
HashObject
from
"../core/HashObject"
;
import
HashObject
from
"../core/HashObject"
;
import
{
createCanvas
}
from
"./context/RenderContext"
;
import
{
createCanvas
}
from
"./context/RenderContext"
;
import
{
Frame
}
from
"../ReType"
;
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 {
...
@@ -15,7 +15,23 @@ export default class Texture extends HashObject {
@
dirtyFieldDetector
@
dirtyFieldDetector
img
:
any
;
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
_cacheCanvas
;
private
_cacheContext
;
private
_cacheContext
;
...
@@ -23,9 +39,6 @@ export default class Texture extends HashObject {
...
@@ -23,9 +39,6 @@ export default class Texture extends HashObject {
super
();
super
();
this
[
'isDirty'
]
=
true
;
this
[
'isDirty'
]
=
true
;
this
.
_bounds
=
new
Bounds
(
0
,
0
,
0
,
0
,
()
=>
{
this
[
'isDirty'
]
=
true
;
});
}
}
/**
/**
...
@@ -33,8 +46,13 @@ export default class Texture extends HashObject {
...
@@ -33,8 +46,13 @@ export default class Texture extends HashObject {
* @param frame
* @param frame
*/
*/
setFrame
(
frame
:
Frame
)
{
setFrame
(
frame
:
Frame
)
{
let
{
x
,
y
,
w
,
h
}
=
frame
;
utils
.
injectProp
(
this
,
frame
);
this
.
_bounds
.
setTo
(
x
,
y
,
w
,
h
);
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 {
...
@@ -45,27 +63,6 @@ export default class Texture extends HashObject {
this
.
img
=
img
;
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 {
...
@@ -75,7 +72,7 @@ export default class Texture extends HashObject {
if
(
this
[
'isDirty'
])
{
if
(
this
[
'isDirty'
])
{
this
[
'isDirty'
]
=
false
;
this
[
'isDirty'
]
=
false
;
const
{
_bounds
:
{
width
,
height
}
}
=
this
;
const
{
width
,
height
}
=
this
;
if
(
!
canvas
)
{
if
(
!
canvas
)
{
canvas
=
this
.
_cacheCanvas
=
createCanvas
();
canvas
=
this
.
_cacheCanvas
=
createCanvas
();
...
@@ -89,8 +86,6 @@ export default class Texture extends HashObject {
...
@@ -89,8 +86,6 @@ export default class Texture extends HashObject {
canvas
.
width
=
width
;
canvas
.
width
=
width
;
canvas
.
height
=
height
;
canvas
.
height
=
height
;
this
.
drawToCanvas
(
context
);
this
.
drawToCanvas
(
context
);
this
.
drawToCanvas
(
context
);
}
}
return
canvas
;
return
canvas
;
...
@@ -107,9 +102,9 @@ export default class Texture extends HashObject {
...
@@ -107,9 +102,9 @@ export default class Texture extends HashObject {
* @param dh
* @param dh
*/
*/
drawToCanvas
(
context
,
dx
=
0
,
dy
=
0
,
sx
?,
sy
?,
dw
?,
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 {
...
@@ -117,7 +112,6 @@ export default class Texture extends HashObject {
*/
*/
destroy
()
{
destroy
()
{
this
.
img
=
null
;
this
.
img
=
null
;
this
.
_bounds
=
null
;
this
.
destroyCacheCanvas
();
this
.
destroyCacheCanvas
();
}
}
...
@@ -138,7 +132,7 @@ export default class Texture extends HashObject {
...
@@ -138,7 +132,7 @@ export default class Texture extends HashObject {
export
function
createTexture
(
img
,
frame
?:
Frame
):
Texture
{
export
function
createTexture
(
img
,
frame
?:
Frame
):
Texture
{
const
texture
=
new
Texture
();
const
texture
=
new
Texture
();
texture
.
setImg
(
img
);
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
;
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