动画背景
This commit is contained in:
50
assets/script/game/map/view/MoveUV.ts
Normal file
50
assets/script/game/map/view/MoveUV.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Texture2D } from 'cc';
|
||||
import { Enum } from 'cc';
|
||||
import { rect } from 'cc';
|
||||
import { Sprite } from 'cc';
|
||||
import { _decorator, Component } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('MoveUV')
|
||||
export class MoveUV extends Component {
|
||||
|
||||
@property
|
||||
moveSpeedX = 0;
|
||||
|
||||
@property
|
||||
moveSpeedY = 0;
|
||||
|
||||
@property({ type: Enum(Texture2D.WrapMode) })
|
||||
wrapMode = Texture2D.WrapMode.REPEAT;
|
||||
|
||||
private _sprite: Sprite;
|
||||
private _rect = rect();
|
||||
private _currentWrapMode: number;
|
||||
|
||||
getRect() {
|
||||
return this._rect;
|
||||
}
|
||||
|
||||
onLoad() {
|
||||
this._sprite = this.getComponent(Sprite);
|
||||
if (!this._sprite) {
|
||||
let tempStr = "获取Sprite失败";
|
||||
throw new Error(tempStr);
|
||||
}
|
||||
this._rect.set(this._sprite.spriteFrame.rect);
|
||||
this._sprite.spriteFrame.packable = false;
|
||||
}
|
||||
|
||||
update(dt: number) {
|
||||
if (this._currentWrapMode !== this.wrapMode) {
|
||||
this._currentWrapMode = this.wrapMode;
|
||||
this._sprite.spriteFrame.texture.setWrapMode(this.wrapMode, this.wrapMode);
|
||||
}
|
||||
this._rect.x += this.moveSpeedX * dt;
|
||||
this._rect.y += this.moveSpeedY * dt;
|
||||
|
||||
this._sprite.spriteFrame.rect = this._rect;
|
||||
this._sprite.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
}
|
||||
9
assets/script/game/map/view/MoveUV.ts.meta
Normal file
9
assets/script/game/map/view/MoveUV.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e399b82b-77ce-4ae0-bb2d-81ae88e3fc91",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user