hello. im trying to make it so that in my game when a player clicks a sprite the sprite goes into a state of 'activated' and then moves mouse away and when he releases the left mouse button it sends the sprite flying off in that direction. i set it up so when the mouse sprite is colliding with the sprite and clicked the sprite is set into 'activated' and then called a method on that sprite.

everything seems to work untill i get to the if(!ZenGame.leftClick), inwhich does not run. i think the problem is that when the user moves the mouse away he is no longer colliding with the sprite so the if statement never gets teh chance to execute. what actually happens when i run teh game is once i click the sprite my mouse sprite freezes over the sprite and nothing happens.

maybe i should be going about this in a tottally diffrent way? any ideas?

static state tracking? (ZenGame.clickable) what would be your reason for doing that?

now, as for your problem:

in your class you only allows single-speed, 8-way directions. (combination of -1 and 1 for x and y) I doubt this is what you want to achieve.

you don't need to follow the mousepointer (as you are doing in the throwThis method), you are basically interested only in the current position of the sprite and the position of the mouse when the left mouse button is released. This, combined with the length of that vector and the time the mousebutton was held down will give you all the variables to calculate a proper motionVector. (i.e. motionVector = mouseVector / timeMouseButtonWasHeldDown. mouseVector is the vector from coordinates of the sprite to the coordinates of the mouse.)

the pieces (sprites) in my game are m1,m2,m3,m4 so yeah m is just a generic name for now, soon it will become a interface.

i know that i dont have it set to goto where the mouse was yet but that doesnt really matter yet cause i cant even get into the if statement where i check if left mouse was released. what am i doing wrong to make it so if(!ZenGame.leftMouse) doesnt run even when the leftMouse = false?

oh and if i change that to if(ZenGame.leftMouse) then everything runs fine.

The 'generic' stuff I'm talking about looks like List<T> or similar, and allows declaration of variables of type T without knowing exactly which class T actually is. It's something smart which means we won't have to make so many class casts. Just fix the class name

Advanced? That is not really the problem, the problam is that you can't just copy/paste a small part of your program and say "fix plz ktnx!".

As far as I can tell (and I only have the information you posted here) you are better of handling the problem differently. Don't use sprite collision for this one. If you are using java2d, check with a mouselistener wheter a sprite has been clicked upon. When a click occurs, set a variable to the currentTime (clickTime). Then, on the instance of your main class (don't use static variables, like your ZenGame.leftClick) set a variable like 'spriteClickedUpon' with that sprite. Now, when you get a mouseReleased event, you have the 2 points you need, together with the time the mouse was held down, to calculate the vector. I feel that this is a better way, but there could be others. If I missed anything or presumed something (for example, that you use java2d, not opengl), it is most likely because you didn't tell us yet.

I think the reason why your game is freezing is becuase when the activated state is set to true, you call the method throwThis, which then just loops while activated is true. As such it is busy waiting.Probably the thread that is now caught up in busy waiting is your event dispatch thread, or something similar. We can't actually tell from what you have posted the exact nature of your problems. Is you collision code called downstream from a mouseMoved event perhaps?

Runesketch: an Online CCG built on Google App Engine where players draw their cards and trade. Fight, draw or trade yourself to success.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org