作者cjcat2266 (CJ Cat)
看板Flash
標題Re: [問題] 數學不好的煩腦, 排列檢定.
時間Sat Mar 15 15:34:54 2008
※ 引述《babyfaker (oooo)》之銘言:
: 請問各位一個問題.
: 假設總共有九張圖片,排列會隨著stage的寬度自動換行的數學式如何寫呢?
: 假設一張圖寬度為300
: stage寬度為2700
: P P P P P P P P P
: 當stage寬度變為900時自動換為.
: P P P
: P P P
: P P P
: 謝謝~~ T_T
columnCount為 "一列可以有幾個圖片"
所以columnCount = Math.ceil(stage.stageWidth / 300);
處理到第i個圖片的時候
用以下算式得知它是該行第幾個
i % columnCount
currentRow記錄目前正在處理第幾列
所以當處理到第i個圖片的時候
如果i是該列的最後一個,currentRow就要加一
if (i % columnCount ==0) currentRow++;
最後就是排列圖片的x, y座標位置
pic.x = 300 * (i % columnCount);
pic.y = 300 * currentRow;
AS3的code大致如下(未經過測試):
//假設你圖片名稱是p0, p1, p2,..., p8
import flash.display.*;
import flash.event.*;
stage.addEventListener(Event.RESIZE, onResize);
funciton onResize(e:Event):void {
var columnCount:Number = Math.ceil(stage.stageWidth / 300);
var currentRow:Number = 0;
for( var i:int = 0; i < 9; i++) {
this["p" + i].x = 300 * (i % columnCount);
this["p" + i].y = 300 * currentRow;
if (i % columnCount == 0) currentRow++;
}
}
--
CJ Cat = Croa'J Cat = Cockroach Cat = 西街凱特 = 蜚蠊貓 = 蟑螂貓
Gallery
http://cjcat2266.deviantart.com
ptt2 Board CJWorkshop - 阿多比閃光(Adobe Flash)研討區
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.136.69.83
※ 編輯: cjcat2266 來自: 220.136.69.83 (03/15 15:35)
推 etrexetrex:QQ 我慢了 03/15 15:40
→ cjcat2266: XD 我快了 03/15 15:42