用 HTML5 + LufyLegend 引擎復刻 iOS 開機畫面:金屬機身、動態壁紙、鎖屏時間、滑動解鎖滑塊。純 Web 技術還原原生體驗,展示 Canvas 遊戲引擎在 UI 重現上的表現力。

線上體驗:https://www.cnblogs.com/yorhom/articles/3163078.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>iPhone Boot</title>
<script src="./lufylegend-1.7.7.min.js"></script>
<script src="./js/Main.js"></script>
</head>
<body>
<div id="mylegend">loading...</div>
</body>
</html>
init(50, "mylegend", 450, 640, main); // 50fps, 容器, 寬, 高, 入口
LGlobal.setDebug(true);
const loadData = [
{path: "./js/Shape.js", type: "js"},
{path: "./js/BootPage.js", type: "js"},
{name: "wallpaper", path: "./images/wall_paper.jpg"}
];
let datalist = {}, backLayer, iosShape, bootPage;
function main() {
LLoadManage.load(loadData, null, gameInit);
}
function gameInit(result) {
datalist = result;
initLayer();
addShape();
addBack();
}
function initLayer() {
backLayer = new LSprite();
addChild(backLayer);
}
function addShape() {
iosShape = new Shape("IPHONE", 400, 600);
iosShape.x = 15; iosShape.y = 5;
backLayer.addChild(iosShape);
}
function addBack() {
bootPage = new BootPage();
bootPage.x = 40; bootPage.y = 40;
const w = iosShape.getScreenWidth();
const h = iosShape.getScreenHeight();
bootPage.addWallPaper(new LBitmapData(datalist["wallpaper"], 200, 480, w, h));
bootPage.addTime();
bootPage.addSlider();
iosShape.addChild(bootPage);
}
function Shape(type, w, h) {
base(this, LSprite, []);
this.deviceWidth = w; this.deviceHeight = h; this.type = type;
this.shapeLayer = new LSprite(); this.addChild(this.shapeLayer); // 外殼層
this.homeButtonLayer = new LSprite(); this.addChild(this.homeButtonLayer); // Home鍵層
this.screenLayer = new LSprite(); this.addChild(this.screenLayer); // 螢幕層
this._showSelf();
}
Shape.prototype._showSelf = function() {
if(this.type === "IPHONE") {
// 外殼圓角矩形 + 陰影
const shadow = new LDropShadowFilter(15, 45, "black", 20);
this.shapeLayer.graphics.drawRoundRect(10, "black", [0,0,this.deviceWidth,this.deviceHeight,15], true, "black");
this.shapeLayer.filters = [shadow];
// 螢幕區域
this.screenLayer.graphics.drawRect(0, "black", [this.deviceWidth/10, this.deviceWidth/10, this.deviceWidth*0.8, this.deviceHeight*0.8], true, "white");
// Home 鍵:圓形 + 圓角方塊
this.homeButtonLayer.graphics.drawArc(1, "black", [this.deviceWidth/2, this.deviceHeight*0.87+this.deviceWidth/10, this.deviceWidth/16, 0, 2*Math.PI], true, "#191818");
this.homeButtonLayer.graphics.drawRoundRect(3, "white", [this.deviceWidth/2-10, this.deviceHeight*0.87+this.deviceWidth/10-10, 20,20,5]);
}
};
Shape.prototype.getScreenWidth = function() { return this.deviceWidth * 0.8; };
Shape.prototype.getScreenHeight = function() { return this.deviceHeight * 0.8; };
LBitmap 繪製,縮放填滿螢幕層LTextField + ENTER_FRAME 事件每幀更新,陰影濾鏡增強可讀性MOUSE_DOWN/MOVE/UP,拖動跟隨手指,釋放時判斷距離:足夠 → 解鎖動畫;不足 → 彈回彈性動畫 (LTweenLite)BootPage.prototype.addSlider = function() {
this.sliderLayer = new LSprite(); this.addChild(this.sliderLayer);
// 背景條
const barBorder = new LSprite(); barBorder.x = 35; barBorder.y = this.getScreenHeight()-70;
this.addChild(barBorder);
// 提示文字
const txt = new LTextField(); txt.size=12; txt.x=80; txt.y=10; txt.color="white"; txt.text="Slide to unlock.";
barBorder.addChild(txt);
// 滑塊
const bar = new LSprite(); bar.x = 35; bar.y = this.getScreenHeight()-70; bar.canMoveBar = false;
bar.addEventListener(LMouseEvent.MOUSE_DOWN, e => { bar.canMoveBar = true; });
bar.addEventListener(LMouseEvent.MOUSE_UP, e => {
if (bar.x > 200) { // 解鎖閾值
LTweenLite.to(bar, 0.5, {x: 300, onComplete: () => this.unlock()});
} else {
LTweenLite.to(bar, 0.5, {x: 35}); // 彈回
}
bar.canMoveBar = false;
});
bar.addEventListener(LMouseEvent.MOUSE_MOVE, e => {
if (bar.canMoveBar) bar.x = e.selfX - 35;
});
this.addChild(bar);
};
LLoadManage 統一管理圖片/JS 模組載入ENTER_FRAME 實現時鐘即時更新LTweenLite 處理滑塊彈回/解鎖滑出動畫此專案展示 HTML5 遊戲引擎構建高保真 UI 原型的可行性,代碼結構清晰,易於擴充完整 iOS 模擬器雛形。