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
b4f552ef
Commit
b4f552ef
authored
Apr 18, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改tween
parent
b807e097
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
19 deletions
+33
-19
Tween.ts
src/support/Tween.ts
+31
-16
math.ts
src/tools/math.ts
+2
-3
No files found.
src/support/Tween.ts
View file @
b4f552ef
/**
* Created by rockyl on 2018/11/8.
*
* 补间动画
*/
import
{
Component
}
from
"../core"
;
import
{
lerp
,
lerpObj
}
from
"../tools/math"
;
import
{
injectProp
}
from
"../tools/utils"
;
import
HashObject
from
"../core/HashObject"
;
...
...
@@ -18,14 +18,13 @@ enum STATUS {
}
export
interface
ITweenPlugin
{
//resolveLerp(fromValue, toValue, ratio, allowOutOfBounds):
any;
resolveLerp
(
fromValue
,
toValue
,
ratio
,
allowOutOfBounds
):
any
;
}
export
interface
TweenOptions
{
loop
?:
number
;
autoPlay
?:
boolean
;
initFields
?:
string
[];
clazz
?:
any
;
fields
?:
string
[];
}
...
...
@@ -85,7 +84,6 @@ export class Tween extends HashObject {
startTime
;
plugins
:
ITweenPlugin
[];
clazz
;
fields
;
autoPlay
:
boolean
;
...
...
@@ -102,7 +100,6 @@ export class Tween extends HashObject {
this
.
target
=
target
;
this
.
loop
=
options
?
options
.
loop
:
0
;
this
.
autoPlay
=
options
?
(
options
.
hasOwnProperty
(
'autoPlay'
)
?
options
.
autoPlay
:
true
)
:
true
;
this
.
clazz
=
options
?
options
.
clazz
:
null
;
this
.
fields
=
options
?
options
.
fields
:
null
;
this
.
plugins
=
plugins
;
...
...
@@ -112,11 +109,29 @@ export class Tween extends HashObject {
}
}
private
resolveLerp
(
fromValue
,
toValue
,
ratio
)
{
let
currentValue
;
if
(
this
.
plugins
.
length
>
0
)
{
for
(
let
plugin
of
this
.
plugins
)
{
currentValue
=
plugin
.
resolveLerp
(
fromValue
,
toValue
,
ratio
,
true
);
}
}
else
{
if
(
typeof
toValue
==
'object'
)
{
let
{
fields
}
=
this
;
currentValue
=
lerpObj
(
fromValue
,
toValue
,
ratio
,
fields
||
Object
.
keys
(
toValue
),
true
);
}
else
{
currentValue
=
lerp
(
fromValue
,
toValue
,
ratio
,
true
);
}
}
return
currentValue
;
}
onUpdate
=
(
t
)
=>
{
this
.
t
=
t
;
switch
(
this
.
status
)
{
case
STATUS
.
DO_TO
:
var
{
target
,
startTime
,
fromProps
,
toProps
,
duration
,
ease
,
clazz
,
fields
}
=
this
;
var
{
target
,
startTime
,
fromProps
,
toProps
,
duration
,
ease
,}
=
this
;
var
passTime
=
t
-
startTime
;
let
timeRatio
=
Math
.
min
(
1
,
passTime
/
duration
);
...
...
@@ -131,16 +146,16 @@ export class Tween extends HashObject {
let
currentValue
;
if
(
timeRatio
<
1
)
{
if
(
typeof
toValue
==
'object'
)
{
currentValue
=
lerpObj
(
fromValue
,
toValue
,
ratio
,
clazz
,
fields
||
Object
.
keys
(
toValue
),
true
);
}
else
{
currentValue
=
lerp
(
fromValue
,
toValue
,
ratio
,
true
);
}
currentValue
=
this
.
resolveLerp
(
fromValue
,
toValue
,
ratio
);
}
else
{
currentValue
=
toValue
;
}
target
[
key
]
=
currentValue
;
if
(
typeof
currentValue
===
'string'
){
injectProp
(
target
[
key
],
currentValue
);
}
else
{
target
[
key
]
=
currentValue
;
}
}
if
(
timeRatio
>=
1
)
{
...
...
@@ -209,14 +224,14 @@ export class Tween extends HashObject {
killTweens
(
this
.
target
);
}
if
(
delay
>
0
)
{
if
(
delay
>
0
)
{
setTimeout
(
this
.
_doPlay
,
delay
,
resetLoopCounting
)
}
else
{
}
else
{
this
.
_doPlay
(
resetLoopCounting
);
}
}
private
_doPlay
=
(
resetLoopCounting
)
=>
{
private
_doPlay
=
(
resetLoopCounting
)
=>
{
addTween
(
this
.
target
,
this
);
this
.
_start
(
resetLoopCounting
);
};
...
...
@@ -266,7 +281,7 @@ export class Tween extends HashObject {
_start
(
resetLoopCounting
:
boolean
=
true
)
{
this
.
status
=
STATUS
.
PENDING
;
if
(
resetLoopCounting
)
{
if
(
resetLoopCounting
)
{
this
.
loopCounting
=
0
;
}
this
.
host
.
callOnNextTick
(
this
.
_readyStart
);
...
...
src/tools/math.ts
View file @
b4f552ef
...
...
@@ -34,18 +34,17 @@ export function lerp(begin, end, t, allowOutOfBounds = false) {
* @param begin
* @param end
* @param t
* @param clazz
* @param fields
* @param allowOutOfBounds
* @return
*/
export
function
lerpObj
(
begin
,
end
,
t
,
clazz
,
fields
,
allowOutOfBounds
=
false
)
{
export
function
lerpObj
(
begin
,
end
,
t
,
fields
,
allowOutOfBounds
=
false
)
{
const
type
=
typeof
begin
;
if
(
type
!==
typeof
end
)
{
console
.
error
(
'begin and end need same type'
)
}
const
temp
=
new
clazz
()
;
const
temp
=
{}
;
for
(
let
field
of
fields
)
{
temp
[
field
]
=
lerp
(
begin
[
field
],
end
[
field
],
t
,
allowOutOfBounds
);
}
...
...
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