All,
I'm just starting to work on adding a mouse to my program. The setup seems easy enough on Allegro 5. I added a simple square cursor. When it wouldn't move I started to textf the event.mouse.x, event.mouse.y values for reference. The x value stays 0. The y value is about a 9+ digit number that constantly bounces whether the mouse is being moved or not. It even throws in a negative here and there.
Has anyone ever heard of this before? I don't have a compiler error or warning. The other events from the keyboard work fine. Its just the mouse.
I've installed the mouse, and registered it.
init_confirm(al_install_mouse(), "mouse");
al_register_event_source(queue, al_get_mouse_event_source());
I'm sure I've over looked something, but based on the various code examples and youtube items I've looked up, I don't know what it would be. Especially since I'm not getting error and warnings.
Thanks
You probably have to post code
Online example and YouTube videos?? And now you come to us? That’s it, I’m not helping you.
I want a divorce.
where are you getting x/y values of the mouse? Which mouse events?
Just know that the ALLEGRO_EVENT is a union of many different EVENT structs. If you try to get mouse.x and mouse.y values from a non-mouse event, it will be garbage.
Post some code.
Dizzy, I meant no offense . On most other specialized sites I frequent if you ask for help without exhausting ALL other avenues you get hit with a bunch of attitude meant to make you look stupid and lazy. “We answer this all the time” or “When are ppl going start putting forth effort without looking for a quick answer” or “Its all in the manual, that needs to be the first place you look.” Or “ Yes I know all there is to know on the subject. I am the reason they developed XXXXXXX, but don’t be fooled, just because I am on this Help site ALL THE TIME, I’m not here to answer questions!!!!” Ok I might have made up the last one, but you get the idea. I was trying to find it for myself before troubling anyone else. Plus I’ve been asking a lot of questions as of late.
As for code. It’s going to be a little hard to follow because I’m just patching stuff in. I’m trying to get familiar with A5. As I decide I want to learn a certain aspect, I graft it in to my current code which isn’t clear and organized. This could be the issue. I can include the individual functions if need be.
In the Solly’s Matches line, If I change the event.mouse.x/y I get the odd numbers I mentioned earlier, if I replace with pos_x / pos_y they stay at 0. Meaning they aren’t getting updated by the ALLEGRO_EVENT_MOUSE_AXES if.
Thanks for looking it over.
Haha that's ok, I was only joking!
We love helping out here
Your mouse event line on 102 is else-if'd with the checking of blocks; I'm guessing it should just be:
if(event.type == ALLEGRO_EVENT_MOUSE_AXES) { pos_y = event.mouse.y; pos_x = event.mouse.x; }
Without the else
EDIT: Oh no, that's wrong - I can see now it's else-if'd with the other event!
Back to the drawing board....
Well it's working now. Not sure why. I moved my text print line to my ALLEGRO_EVENT_MOUSE_AXES if section and it worked. The numbers were accurate to my mouse location and the "cursor" moved around with the system cursor. So I figure my drawing and flipping were conflicting somehow. So I put it back (uncommented it out) and it still works. Craziest thing. I've had this happen on rare occasions. Could be the IDE. Next time I'll do a CLEAN first and then build.
In any case. Thanks a lot. I'm sure I'll be back.
Oh well, glad it's working!
else is a special keyword. It links to the most recent if. In your case, you assumed it's the if for ALLEGRO_KEY_ESCAPE. However, it's linking to the if right above it. Fix it with braces or move it right beneath the if
****************************************
my current code which isn’t clear and organized
One way to help organize is have better indentation (line things up).
also, if you have multiple if/else statements, use a switch statement. By the time you get to the nth if/else, you've needlessly checked the every if before.
Actually you can't with your keykode checks. No need to write every case statement from A to X.
I like to line up by braces like this:
Thanks Daniel,
Typically I do a little better job making my code more easily readable. Maybe not as nice as you have it but I do align connected code. I also comment better. Again in this case I was just patch working. I didn't expect anyone to be looking at it .
Thanks again.