標題可能有點混淆,但即時通訊試圖從精靈表獲取步行動畫。它有8個不同的步行位置,它似乎每次它改變,我必須再次加載精靈表格作爲剛剛裁剪原始,如果你得到我的意思,否則它不會顯示。處理,加載圖像,並顯示每次更改
PImage Body;
int WidthSpacing = 64;
int HeightSpacing = 64;
int XCharacter = 1;
int YCharacter = 10;
int WalkingCounter = 0;
int WalkingSpeed = 2;
void setup()
{
background(200);
size (350, 240);
Body = loadImage("\\Sprites\\Player\\Male\\Default\\Light.png");
}
void draw()
{
WalkAnimation();
}
void WalkAnimation()
{
WalkingCounter++;
if (WalkingCounter == 1 * WalkingSpeed) { XCharacter = 1; LoadBody(); }
if (WalkingCounter == 2 * WalkingSpeed) { XCharacter = 2; LoadBody(); }
if (WalkingCounter == 3 * WalkingSpeed) { XCharacter = 3; LoadBody(); }
if (WalkingCounter == 4 * WalkingSpeed) { XCharacter = 4; LoadBody(); }
if (WalkingCounter == 5 * WalkingSpeed) { XCharacter = 5; LoadBody(); }
if (WalkingCounter == 6 * WalkingSpeed) { XCharacter = 6; LoadBody(); }
if (WalkingCounter == 7 * WalkingSpeed) { XCharacter = 7; LoadBody(); }
if (WalkingCounter == 8 * WalkingSpeed) { XCharacter = 8; LoadBody(); WalkingCounter = 0; }
}
void LoadBody()
{
background(200);
Body = loadImage("\\Sprites\\Player\\Male\\Default\\Light.png");
int X = XCharacter * WidthSpacing;
int Y = YCharacter * HeightSpacing;
Body = Body.get(X, Y, WidthSpacing, HeightSpacing);
Body.resize(200, 200);
image(Body, 150, 5);
}
,如果它不是爲處理取約20幀所以它不可能在圖像中加載我順利拿到了行走速度這將是確定的。任何想法appriciated
謝謝,我將它們放在數組列表,但加載圖像時,精靈變化,每5幀所以它不加載相同的圖像不止一次如果你看到我的意思 – Will
纔會被調用@會的,它會多次加載相同的圖像。您應該只爲每個圖像調用一次'loadImage()'。這裏你每次改變它都會加載它,這實際上效率很低。只需將圖像保存在內存中,並在需要時將其交換出去。即使你只改變每5幀,每秒仍然有12個不必要的負載。 –
哦,我明白你的意思了,是的,我現在在設置中加載一次,每當它改變而不是我上面發佈的代碼時,就裁剪它,謝謝:) – Will