[英]Processing, Mirroring or Flipping an Image without affecting others
我正在開發使用Java處理(例如Mario)的小型平台游戲。
我正在用箭頭或WASD移動角色,我想知道scale(-1,1);
是否有替代方法scale(-1,1);
鏡像角色/圖像時。 (默認情況下它是向右看,或者當您按D時,它是向左翻轉的)。
如果這是最好或最簡單的方法,我也想知道如何使比例尺方法不影響所有其余圖像 ,因為我想放置一些平台,但隨着比例尺的增加,它們會在角色移動時不斷翻轉...
我也在聽有關處理和Javascript的精靈/聲音用法的任何信息。 我已經嘗試了一些庫,但是它們僅在我切換到Java模式時才起作用。
在此先感謝Maral。
由於以前的帖子,我使用了比例鏡像。 是否在x軸上處理鏡像?
“ dreta”是“ Right”,“ esquerre”是“ Left”,兩者均由WASD或Keys控制,它們在按下時將每個布爾值更改為true,而在釋放時為false。 我沒有發布所有代碼,但這是我想要修復的基本動作。
void draw() {
pushMatrix();
if (iniciar == true) {
inici();
}
if (dreta == true && esquerre != true) {
movDret(backgroundimg[2]);
}
if (esquerre == true && dreta != true) {
movEsquerre(backgroundimg[2]);
}
}
void platformndBackground(PImage b){
background(b);
popMatrix();
image(imgGrass[0], 50, 50);
if (esquerre == true) {
scale(-1,1);
}
}
void inici() {
movDret(backgroundimg[2]);
iniciar = false;
}
void movDret(PImage b) {
//Colisió extrem Esquerre.
if (posicio > 1024-imgJugador[5].width) {
posicio = posicio - imgJugador[tipusMoviment].width/2;
movEsquerre(backgroundimg[2]);
} else {
bothMoviments(b);
image(imgJugador[tipusMoviment], posicio, posicioSalt);
posicio = posicio + 3;
}
}
void movEsquerre(PImage b) {
//Colisió extrem Dret.
if (posicio < 0) {
posicio = posicio + imgJugador[tipusMoviment].width/2;
popMatrix();
movDret(backgroundimg[2]);
} else {
bothMoviments(b);
image(imgJugador[tipusMoviment], ((-imgJugador[tipusMoviment].width)-posicio), posicioSalt);
posicio = posicio - 3;
}
}
void bothMoviments(PImage b) {
if (esquerre == true) {
scale(-1, 1);
}else{
popMatrix();
}
if (tipusMoviment < imgJugador.length-1) {
tipusMoviment++;
} else {
tipusMoviment = 5;
}
platformndBackground(b);
}
如果您不想鏡像您的子畫面,則可以只使用兩套子畫面:一組用於右移,一組用於左移。
但是,如果使用scale()函數鏡像子畫面,則需要使用pushMatrix()
和popMatrix()
這樣縮放不會影響其他所有子畫面。 像這樣:
public void draw(){
background(0);
pushMatrix(); //save current "default" matrix
scale(-1,1); //scale the matrix
image(img,-img.width,img.height); //draw the image using the scaled matrix
popMatrix(); //go back to the saved "default" matrix
//draw non-mirrored sprites
image(img2,img2.width,img2.height);
}
在此處的參考中可以找到更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.