- 注册时间
- 2014-8-11
- 最后登录
- 2017-6-11
- 阅读权限
- 20
- 积分
- 198
- 精华
- 0
- 帖子
- 39
|
测试的时候 往右点一下就可以了 球会在画布上画线 然后超过画布长800的时候转成bitmap 作为第二个场景的背景
init(1000 / 60, 'legend', 800, 700, main);
var bg, cir, x, y, runTween, zhi;
var ctx, cl, fps;
var timer, Bigcon;
function main() {
Bigcon = new LSprite();
addChild(Bigcon);
Ballcon = new LSprite();
addChild(Ballcon)
bg = new LSprite();
bg.graphics.drawRect(1, "black", [0, 0,800,800], true, "black");
Bigcon.addChild(bg);
fps = new FPS();
addChild(fps)
initGame()
}
function initGame() {
cir = new LShape();
cir.graphics.drawArc(1, "red", [0, 0, 10, 0, Math.PI * 2], true, "black");
cir.x = 400;
cir.y = 350;
Ballcon.addChild(cir);
LGlobal.stage.addEventListener(LMouseEvent.MOUSE_DOWN, setXY);
LGlobal.stage.addEventListener(LEvent.ENTER_FRAME, collect);
zhi = new LSprite();
Bigcon.addChild(zhi);
ctx = LGlobal.canvas;
timer = setInterval(function() {
ballRun();
bgMove();
aa();
}, 30)
}
var startX = 400, startY = 350, endX = 400, endY = 350, speedX = 5, speedY = 5, v = 5;
var clickX, clickY, bitmapData, bitmap;
function setXY(e) {
clearInterval(timer);
clickX = e.selfX - Bigcon.x;
clickY = e.selfY - Bigcon.y;
var Vradio = Math.abs(clickX - endX) / Math.abs(clickY - endY);
var vy = Math.sqrt((v * v * Math.pow(clickY - endY, 2)) / (Math.pow(clickX - endX, 2) + Math.pow(clickY - endY, 2)));
var vx = Math.abs(vy * ((clickX - endX) / (clickY - endY)));
speedX = clickX - endX > 0 ? vx : -vx;
speedY = clickY - endY > 0 ? vy : -vy;
timer = setInterval(function() {
ballRun();
bgMove();
aa();
}, 30)
}
function ballRun() {
cir.x += speedX;
cir.y += speedY;
}
function bgMove() {
LGlobal.stage.x -= speedX;
LGlobal.stage.y -= speedY;
fps.x += speedX;
fps.y += speedY
}
function aa() {
endX += speedX;
endY += speedY;
zhi.graphics.drawLine(1, "red", [startX, startY, endX, endY]);
startX = endX;
startY = endY;
}
var page = 1;
var bitmapData,bitmap
var iscreate = true;
function collect() {
LGlobal.destroy = false;
x = cir.x;
y = cir.y;
if (x > 800 * page) {
bitmapData = new LBitmapData(null, (800 * (page - 1)), 0, 800 + (800 * (page)), 1400);
bitmapData.draw(Bigcon);
bitmap = new LBitmap(bitmapData);
Bigcon.addChildAt(bitmap, 0);
zhi.graphics.clear()
Bigcon.removeChildAt(1);
bitmap.x = 800 * page;
page += 1;
LGlobal.destroy = false;
}
} |
|