2013-02-08 2 views
0

Javascript로 포팅 된 처리 스케치에서 마우스 움직임을 추적하는 데 문제가 있습니다. 내가 말할 수있는 한, 프로그램은 이벤트 나 논리 연산으로 mouseMoved를 활성화하지 않는다는 점을 제외하고는 정상적으로 실행됩니다. 나는 또한 pMousex를 시도했다! = mouseX 그리고 그것은 또한 작동하지 않았다. 어떤 도움이 필요합니까?Processing.js : mouseMoved()를 추적하지 않습니까?

color[] palette = new color[5]; 
color c1; 
color c2; 
color c3; 
color c4; 
color c5; 
color bgColor; 

int swarmSize; 
int xVariance; 
int yVariance; 
int maxSize; 
int maxOpacity; 
int maxStroke; 

//Non-definables for swarm gen 
int sideMod; 
int sSize; 
int opacity; 
int stroke; 

void setup() { 
size(600, 400); 

c1= #BF2633; 
c2= #A6242F; 
c3= #D9CEAD; 
c4= #C0B18F; 
c5= #011C26; 

bgColor = color(23, 76, 79); 

palette[0] = c1; 
palette[1] = c2; 
palette[2] = c3; 
palette[3] = c4; 
palette[4] = c5; 

swarmSize = 1; 
xVariance = 60; 
yVariance = 60; 
maxSize = 30; 
maxOpacity = 255; 
maxStroke = 4; 

}

void draw() { //tried tracking pMouse != mouse here, no dice 
} 

void drawSwarm() { 
    for (int i = 0; i < swarmSize; i++) 
{ 
if (random(1, 10) < 5) { 
    sideMod = -1; 
} 
else { 
    sideMod = 1; 
} 
stroke = int(random(1, maxStroke)); 
sSize = int(random(1, maxSize)); 
opacity = int(random(0, maxOpacity)); 

strokeWeight(stroke); 
stroke(palette[int(random(1, 5))], opacity); 
fill(palette[int(random(1, 5))], opacity); 

// strokeWeight(int(random(1, 7))); 
ellipse(mouseX + int(random(1, xVariance)) * sideMod, mouseY+ int(random(1, yVariance)), sSize, sSize); 

} }

void mouseMoved() { //Doesn't work in processing.js 
drawSwarm(); 
} 

void keyPressed() { 
background(bgColor); 
} 

답변

0

다음 코드는 잘 작동

int x,y; 
void draw() { 
    point(x,y); 
} 
void mouseMoved() { 
    x = mouseX; 
    y = mouseY; 
    redraw(); 
} 

일반적으로, A의 지침을 그릴 (http://jsfiddle.net/qPpRQ/ 참조) 마우스 처리기가 잘 작동하지 않는다면 일반적으로 마우스 위치를 기반으로 상태를 설정 한 다음 이벤트가 아닌 draw에서 호출되는 화면에 실제로 그리는 코드로 redraw()를 호출해야합니다. 매니저.

관련 문제