2009年4月20日 星期一

HTML 常用特殊字元

Script結果描述
&lt;<小於號或顯示標記
&gt;>大於號或顯示標記
&amp;&可用於顯示其它特殊字元
&quot;"引號
&reg;®己注冊
&copy;©版權
&trade;商標
&ensp;半方大的空白
&emsp;全方大的空白
&nbsp;不斷行的空白


For All Reference -
HTML Symbol Entities Reference

重要公式 - 碰撞檢測

距離碰撞檢測:
//從spriteA 和 spriteB開始
//如果使用一個空白影片,或影片沒有半徑(radius)屬性
//可以用寬度與高度除以2

var dx:Number = spriteB.x - spriteA.x;
var dy:Number = spriteB.y - spriteA.y;
var dist:Number = Math.sqrt(dx * dx + dy * dy);
if(dist < spriteA.radius + spriteB.radius)
{
   //處理碰撞
}


多物體碰撞檢測:
var numObjects:uint = 10;
for(var i:uint = 0; i < numObjects - 1; i++)
{
   //使用變量 i 提取引用
   var objectA = objects[i];
   for(var j:uint = i + 1; j < numObjects - 1; j++)
   {
      //使用變量 j 提取引用
      var objectB = objects[j];
      //在 objectA 與 objectB 之間進行碰撞檢測
   }
}



參考書目:Keith Peters.《Function Actionscript 3.0 Animation》.Friends of ED

2009年4月16日 星期四

重要公式 - 緩動與彈性運動

簡單緩動,長形:
var dx:Number = targetX - sprite.x;
var dy:Number = targetY - sprite.y;
vx = dx * easing;
vy = dy * easing;
sprite.x += vx;
sprite.y += vy;


簡單緩動,中形:
vx = (targetX - sprite.x) * easing;
vy = (targetY - sprite.y) * easing;
sprite.x += vx;
sprite.y += vy;


簡單緩動,短形:
sprite.x += (targetX - sprite.x) * easing;
sprite.y += (targetY - sprite.y) * easing;


簡單彈性,長形:
var ax:Number = (targetX - sprite.x) * spring;
var ay:Number = (targetY - sprite.y) * spring;
vx += ax;
vy += ay;
vx *= friction;
vy *= friction;
sprite.x += vx;
sprite.y += vy;


簡單彈性,中形
vx += (targetX - sprite.x) * spring;
vy += (targetY - sprite.y) * spring;
vx *= friction;
vy *= friction;
sprite.x += vx;
sprite.y += vy;


簡單彈性,短形:
vx += (targetX - sprite.x) * spring;
vy += (targetY - sprite.y) * spring;
sprite.x += (vx *= friction);
sprite.y += (vy *= friction);


偏移彈性運動:
var dx:Number = sprite.x - fixedX;
var dy:Number = sprite.y - fixedY;
var angle:Number = Math.atan2(dy, dx);
var targetX:Number = fixedX + Math.cos(angle) * springLength;
var targetY:Number = fixedY + Math.sin(angle) * springLength;



參考書目:Keith Peters.《Function Actionscript 3.0 Animation》.Friends of ED

2009年4月15日 星期三

Idiom

touch base - 與…連絡
to talk to someone in order to find out how they are or what they think about something

pick (someone's) brain - 聽取專家的的建議;向專家求救
to ask for information or advice from someone who knows more about a subject than you do

up to speed - 掌握並精通最新資訊
to have all the latest information about a subject or an activity

at random - 隨機地;任意地
without choosing intentionally; by chance

get a kick out of - 得到極大的樂趣
to enjoy doing something very much

the ticket - 正是所需之物
very suitable and exactly what is needed

foot the bill - 負擔費用;付帳
to pay for something

save for a rainy day - 未雨綢繆;存錢以備不時之需
to keep an amount of money for a time in the future when it might be needed

on the line - 置身於危險之中
in a dangerous situation in which something could be lost or harmed

in-your-face - 挑釁的;明目張膽的
shocking or annoying in a way that is difficult to ignore

(beauty is) in the eye of the beholder - 因各人觀點不同而有所差異;(情人)眼裡出西施
author Margaret Wolfe Hungerford is credited ith coining this saying which means each person has his or her own opinion about what or who is beautiful

... keep update ...

2009年4月9日 星期四

TinyXml element value保護

在TinyXml中,如果要取得一個Element的value
可以使用GetText(),但如果這是一個空的element,
TinyXml的傳回值是0,所以如果要用string直接接的話
就會發生錯誤,一定要加一層保護
string xml = "<test>"
" <empty></empty>"
" <more>i has value.</more>"
"</test>";
string value = "";
TiXmlDocument xmlDoc;
xmlDoc.Parse(xml);

TiXmlElement *rootEl = xmlDoc.rootElement();
TiXmlElement *emptyEl = rootEl->FirstChildElement("empty");

const char *check = emptyEl->GetText();
if(check != NULL)
value = check;

...
...

2009年4月8日 星期三

C++ string傳遞的保護

在使用string 當參數在傳遞時
為保護參數傳為NULL,所以必需要多加一層保護
如:
#include <string>

use namespace std;

void check(const string &input)
{
// implements...
}

void check(const char *input){
if(input != NULL)
check(string(input));
}

int main(){
check(NULL);
}

目前找到的方法,似乎只有用多型的方式去做
但這樣,變成每個function都要寫兩個,實在也不是那麼的方便