Skip to content

Commit

Permalink
test:The test case modifies the anchor point usage method and modifie…
Browse files Browse the repository at this point in the history
…s the bitmap font loading method.

测试案例:测试案例修改锚点使用方式、修改位图字体加载方式.
  • Loading branch information
INEEDSSD committed Mar 31, 2023
1 parent 81d2f9a commit 561ce2e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
5 changes: 3 additions & 2 deletions src/samples/2d/Interaction_CustomEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ export class Interaction_CustomEvent {
private createSprite(): void {
this.sp = new Sprite();
this.sp.graphics.drawRect(0, 0, 200, 200, "#D2691E");
this.sp.pivot(100, 100);

this.sp.anchorX = 0.5;
this.sp.anchorY = 0.5;

this.sp.x = Laya.stage.width / 2;
this.sp.y = Laya.stage.height / 2;

Expand Down
3 changes: 2 additions & 1 deletion src/samples/2d/Interaction_Swipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export class Interaction_Swipe {

this.button = new Sprite();
this.button.graphics.drawRect(0, 0, w, h, "#FF7F50");
this.button.pivot(w / 2, h / 2);
this.button.anchorX = 0.5;
this.button.anchorY = 0.5;
//设置宽高(要接收鼠标事件必须设置宽高,否则不会被命中)
this.button.size(w, h);
this.button.x = (Laya.stage.width - this.TrackLength) / 2;
Expand Down
2 changes: 1 addition & 1 deletion src/samples/2d/Sprite_ScreenShot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default class Sprite_ScreenShot {
break;
case this.nameArr[1]:
var ddrt = new RenderTexture2D(Browser.clientWidth, Browser.clientHeight, RenderTargetFormat.R8G8B8A8, RenderTargetFormat.None);
Laya.stage.drawToTexture(Browser.clientWidth, Browser.clientHeight, 0, 0, ddrt, true);
Laya.stage.drawToTexture(Browser.clientWidth, Browser.clientHeight, 0, 0, ddrt);
var text:Texture = new Texture(ddrt);
this.drawSp.graphics.drawTexture(text,0,0,this.drawSp.width,this.drawSp.height);
break;
Expand Down
18 changes: 10 additions & 8 deletions src/samples/2d/Text_BitmapFont.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Laya } from "Laya";
import { Main } from "./../Main";
import { BitmapFont } from "laya/display/BitmapFont"
import { Stage } from "laya/display/Stage"
import { Text } from "laya/display/Text"
import { Browser } from "laya/utils/Browser"
import { Handler } from "laya/utils/Handler"
import { WebGL } from "laya/webgl/WebGL"
import { BitmapFont } from "laya/display/BitmapFont";
import { Stage } from "laya/display/Stage";
import { Text } from "laya/display/Text";
import { Browser } from "laya/utils/Browser";
import { WebGL } from "laya/webgl/WebGL";
import { Loader } from "laya/net/Loader";


export class Text_BitmapFont {
private fontName: string = "diyFont";
Expand All @@ -27,8 +28,9 @@ export class Text_BitmapFont {
}

private loadFont(): void {
var bitmapFont: BitmapFont = new BitmapFont();
bitmapFont.loadFont("res/bitmapFont/test.fnt", new Handler(this, this.onFontLoaded, [bitmapFont]));
Laya.loader.load("res/bitmapFont/test.fnt", Loader.FONT).then((res: BitmapFont) => {
this.onFontLoaded(res);
});
}

private onFontLoaded(bitmapFont: BitmapFont): void {
Expand Down
29 changes: 15 additions & 14 deletions src/samples/3d/LayaAir3D_Animation3D/SkeletonMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Browser } from "laya/utils/Browser"
import { BitmapFont } from "laya/display/BitmapFont";
import { Text } from "laya/display/Text";
import { Event } from "laya/events/Event";
import { Loader } from "laya/net/Loader";


export class SkeletonMask {
Expand All @@ -31,9 +32,9 @@ export class SkeletonMask {


private loadFont(): void {
var bitmapFont: BitmapFont = new BitmapFont();

bitmapFont.loadFont("res/threeDimen/LayaScene_MaskModelTest/font/fontClip.fnt", new Handler(this, this.onFontLoaded, [bitmapFont]));
Laya.loader.load("res/threeDimen/LayaScene_MaskModelTest/font/fontClip.fnt", Loader.FONT).then((res: BitmapFont) => {
this.onFontLoaded(res)
});
}
private onFontLoaded(bitmapFont: BitmapFont): void {
bitmapFont.setSpaceWidth(10);
Expand All @@ -56,9 +57,9 @@ export class SkeletonMask {
txt.fontSize = 10;
txt.zOrder = 999999999;
txt.scale(Browser.pixelRatio, Browser.pixelRatio);
txt.pos(Laya.stage.width / 2-50,Laya.stage.height/2);
Laya.stage.on(Event.RESIZE,txt,()=>{
txt.pos(Laya.stage.width / 2-50,Laya.stage.height/2);
txt.pos(Laya.stage.width / 2 - 50, Laya.stage.height / 2);
Laya.stage.on(Event.RESIZE, txt, () => {
txt.pos(Laya.stage.width / 2 - 50, Laya.stage.height / 2);
});
Laya.stage.addChild(txt);
}
Expand All @@ -68,16 +69,16 @@ export class SkeletonMask {
txt.wordWrap = true;
txt.text = "正常动画一";
txt.color = "#FFFFFFFF";
txt.size(200,300);
txt.size(200, 300);
txt.leading = 5;
txt.fontSize = 15;
txt.zOrder = 999999999;
txt.pos(Laya.stage.width / 2 - 240, Laya.stage.height/2);
Laya.stage.on(Event.RESIZE,txt,()=>{
txt.pos(Laya.stage.width / 2 - 240,Laya.stage.height/2);
txt.pos(Laya.stage.width / 2 - 240, Laya.stage.height / 2);
Laya.stage.on(Event.RESIZE, txt, () => {
txt.pos(Laya.stage.width / 2 - 240, Laya.stage.height / 2);
});
Laya.stage.addChild(txt);
}
}
createText2(font) {
var txt = new Text();
txt.width = 250;
Expand All @@ -87,9 +88,9 @@ export class SkeletonMask {
txt.leading = 5;
txt.zOrder = 999999999;
txt.fontSize = 15;
txt.pos(Laya.stage.width / 2 + 140, Laya.stage.height/2);
Laya.stage.on(Event.RESIZE,txt,()=>{
txt.pos(Laya.stage.width / 2 + 140,Laya.stage.height/2);
txt.pos(Laya.stage.width / 2 + 140, Laya.stage.height / 2);
Laya.stage.on(Event.RESIZE, txt, () => {
txt.pos(Laya.stage.width / 2 + 140, Laya.stage.height / 2);
});
Laya.stage.addChild(txt);
}
Expand Down

0 comments on commit 561ce2e

Please sign in to comment.