03-07-2017 07:29 AM - edited 03-07-2017 07:32 AM
Hello.
I have been making this mini game where you have a black ball on a black canvas which moves according to the timer and gets brighter and brighter.
The user need to click on the ball (somewhere on it, it has a diameter of about 30) to stop the clock and end the game.
I've tried using GetRelativeMouseState to get the mouse coordinates and then comparing them to the x,y co of the ball.
Then checking if they match (or within the diameter) the ball and the timer should stop.
For some reason it doesn't work and I'm fairly new to using left mouse click and state.
here is the part of the code that I need help with:
int CVICALLBACK timerFunc (int panel, int control, int event, //circle game timer func (move ball)
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_TIMER_TICK:
circleCount=circleCount+0.01;
colorCirc=MakeColor (r, g, b);
SetCtrlAttribute (panelHandle_circ, PANEL_CIRC_CANVAS_CIRC, ATTR_PEN_COLOR, colorCirc);
SetCtrlAttribute (panelHandle_circ, PANEL_CIRC_CANVAS_CIRC, ATTR_PEN_WIDTH, 100);
CanvasStartBatchDraw (panelHandle_circ, PANEL_CIRC_CANVAS_CIRC);
CanvasClear (panelHandle_circ, PANEL_CIRC_CANVAS_CIRC, VAL_ENTIRE_OBJECT);
x=x+vx;
y=y+vy;
CanvasDrawPoint (panelHandle_circ, PANEL_CIRC_CANVAS_CIRC, MakePoint(x,y));
if(x>=canvasW-15)
{
vx=-(vx);
}
if(y>=canvasH-15)
{
vy=-(vy);
}
if(x<=15)
{
vx=-(vx);
}
if(y<=15)
{
vy=-(vy);
}
switch (event)
{
case EVENT_LEFT_CLICK:
GetRelativeMouseState (panelHandle_circ, 0, &mousePosX, &mousePosY, NULL, NULL, NULL);
if ((mousePosX<=x+15)&&(mousePosX>=x-15)&&(mousePosY<=y+15)&&(mousePosY>=y-15))
{
SetCtrlAttribute (panelHandle_circ, PANEL_CIRC_TIMER, ATTR_ENABLED, 0);
MessagePopup ("All Done!", "Good job! Play Another Game!");
}
}
break;
}
return 0;
}
03-08-2017 01:46 AM
Hello,
Timers can't fire EVENT_LEFT_CLICK event because you can't click on a timer. The right place to handle EVENT_LEFT_CLICK is on the panel callback.
Secondly, instead of GetRelativeMouseState() you can use eventData1 and eventData2 which are the mouse vertical/horizontal position.
03-12-2017 08:23 PM
I have not seen the circle draw and canvas updated.