Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Continuous MousePRessedEvent  (Read 1580 times)
0 Members and 1 Guest are viewing this topic.
Offline hammad28

Senior Newbie




Java games rock!


« Posted 2003-12-02 02:44:08 »

Hi,
I need to move the camera on MousePressedEvent in such a manner that the camera keeps on moving while the Mouse Button is pressed,
The problem is that the event is fired only once i.e the camera moves only once although the button is pressed for a long period, how can I make it to be fired conituously.
I have seen this thing in J3D FlyThrough Demo, but I am failed to figure out the way it is implemented

Take Care
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #1 - Posted 2003-12-02 03:31:36 »

You don't want to fire the mouse button event continuously.  You want to move the camera on Mouse Dragged events.

You want a MouseMotionListener.

Offline hammad28

Senior Newbie




Java games rock!


« Reply #2 - Posted 2003-12-02 04:30:30 »

Hi,
Sir I am very much sure about my application's requirment and I need to implement the camera movement on MousePressedEvent and not on the MouseMotion Event , you can try this thing in FlyThrough demo, the user dont have to drag the mouse to fly or Hoover, It is done on a single moue click.

Take good care of yourself.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #3 - Posted 2003-12-02 06:32:12 »

Does not make too much sense to me. Flythrough use the common MouseBehaviours AFAIK.


For sure no 'continuous MousePressedEvent' - whatever that should be.

MouseDragged or MouseDown+MouseMotion are the ways to go.


HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #4 - Posted 2003-12-02 06:45:04 »

You could always listen for MousePressed and MouseReleased and set a flag. Then in your behaviour that handles the tracking just check the flag.

Of course as stated above, if you do this when you press the mouse button and move the mouse you won't have access to the new mouse pointer location but just the original press location.

Kev

Offline Breakfast

Senior Member




for great justice!


« Reply #5 - Posted 2003-12-02 09:50:59 »

If I was looking for the continuous mousepressed event I would follow kev's suggestion, but be aware that sometimes Java3D can be busy and not always pick up an event, especially mouse or key release events for some reason, so you probably want to do some kind of poll to make sure it is still checked periodically.
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #6 - Posted 2003-12-03 02:07:45 »

Quote
If I was looking for the continuous mousepressed event I would follow kev's suggestion,


Continuous MousePressed events make no sense.  A MousePress event represents a change in the state of a mouse button.. if you are holding it down the button is not changing state and therefore there should be no events.  That is what a "Drag" is.. use the interface for getting drag events.
You can monitor the state of the button with a flag as kev suggests, but you will still need a MouseMotionListener to get updates on the mouse cursor's position... effectively you will re-write MouseDrag detection using slightly lower level events.

Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #7 - Posted 2003-12-03 02:12:31 »

Quote
you can try this thing in FlyThrough demo, the user dont have to drag the mouse to fly or Hoover, It is done on a single moue click.


I find this statement confusing.  Above you mentioned
Quote
the button is pressed for a long period


What is it a "click"  - press and release, then move), or a "drag" - press and hold while moving?

Offline Breakfast

Senior Member




for great justice!


« Reply #8 - Posted 2003-12-03 10:51:49 »

Quote
Continuous MousePressed events make no sense.

You are quite right of course. I meant a continuous mousepressed effect based on mouse pressed and mouse released events. I maintain that there can be problems with release events being lost in J3D.
Offline zingbat

Senior Member




Java games rock!


« Reply #9 - Posted 2003-12-03 19:59:09 »

I think the guy in the first post wants something like a FPS game, when you have for instance the WASD keys for direction and while the player presses the key the avatar is moving. Except that he wants this with the mouse. Some game require the player to move the mouse to one of the borders of the screen and its there the mouse pointer changes to a left, right, direction arrow depending on which side of the screen. Then while the player keeps the mouse button pressed the avatar moves in that direction.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #10 - Posted 2003-12-03 22:46:53 »

Ok, I think I get it.

Press and hold on the left side off the screen and you turn left as long as the button is down.  You stop turning when the button is released.  Top of the screen could move forward, bottom could move backward, etc.

If that is the case then when you get the MousePressed event start a timer that will generate a continuous stream of TimerEvents and step the motion based on those events.  When you get the Mouse Released event kill the timer.

That keeps everything event-based.  the alternative is if you have an active rendering loop then you don't need the timer, you can just step you motion on each iteration of the game loop based on the state of the mouse button as recorded from events, or polled with JInput.

Offline hammad28

Senior Newbie




Java games rock!


« Reply #11 - Posted 2003-12-11 05:32:24 »

Hi to all,
I have implemented the thing i needed succesfully, I'd like to share the logic with you guys as well , so following is the code snippet of my application :-

public VisualizerCameraBehavior() {

   WakeupOnAWTEvent wakeuponawtevent = new WakeupOnAWTEvent(33L);
   WakeupOnAWTEvent wakeuponawtevent1 = new WakeupOnAWTEvent(16L);
   WakeupOnAWTEvent wakeuponawtevent2 = new WakeupOnAWTEvent(8L);
   WakeupOnElapsedFrames wakeuponelapsedframes = new WakeupOnElapsedFrames(0);
   bothCondition = new WakeupOr(new WakeupCriterion[] {
                          wakeuponawtevent,   wakeuponawtevent1, wakeuponawtevent2, wakeuponelapsedframes
   });
   awtCondition = new WakeupOr(new WakeupCriterion[] {
                               wakeuponawtevent, wakeuponawtevent1, wakeuponawtevent2
   });

 }

public void processStimulus(Enumeration enumeration) {
   while(enumeration.hasMoreElements())
   {
     WakeupCondition wakeupcondition = (WakeupCondition)enumeration.nextElement();
     if(wakeupcondition instanceof WakeupOnAWTEvent)
     {
      processAWTEvents(((WakeupOnAWTEvent) wakeupcondition).getAWTEvent());
     }
     else   if(wakeupcondition instanceof WakeupOnElapsedFrames)
       {
/// do what you want to do. Move the camera on values calulated in processmouseevent() func
  }
   if(motion)
     wakeupOn(bothCondition);
   else
     wakeupOn(awtCondition);
 }

private void processAWTEvents(AWTEvent aawtevent[])
 {
   for(int i = 0; i < aawtevent.length; i++)
   {
     if(aawtevent instanceof MouseEvent)
     {
     if((aawtevent.getID() == 506 || aawtevent.getID() == 501 || aawtevent.getID() == 502) /*&& !ignoreMouseMotion*/)
     {
        processMouseEvent((MouseEvent)aawtevent);

   }
 }
}

protected void processMouseEvent(MouseEvent mouseevent)
{
 float XValue = (float)mouseevent.getX();
 float YValue = (float)mouseevent.getY();
 if(SwingUtilities.isLeftMouseButton(mouseevent))
 {
  if(mouseevent.getID() == 502)
   {
     motion = false;
     m_Movement = false;
   } else
   {
     motion = true;
     m_Movement = true;
// calculate and decide the direction of movement on basis of Xvalue and YValue

}
}
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #12 - Posted 2003-12-11 12:58:50 »

What are all those hardcoded numbers?? 501, 506, 502??

You don't seriously code like that do you?

MouseEvent.MOUSE_PRESSED, MOUSE_RELEASED or  MOUSE_DRAGGED (told you!) is too clear, you needed to obfuscate your code?  Tongue

Offline hammad28

Senior Newbie




Java games rock!


« Reply #13 - Posted 2003-12-12 02:58:58 »

Dear Sir,
If you Decompile the flybehavior.class, MouseBehaviour.class files of J3Dflythorugh then you will find the code in the same manner in those classes, I have just copied it from there in my mail with little bit editing, I hope my position is cleared now.
Take good care of your self
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #14 - Posted 2003-12-12 06:46:30 »

For what its worth,

The hardcoded numbers only come up if you decompile the source, when it was original coded they would have used symbols he mentions aboved. Decompilers just can't do the mapping back..

Thanks for the code tho,

Kev

PS. Useful tip? When you post code to the forums you can use the [ code ] [ /code ] tags to format it.

EDIT: doh!

Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #15 - Posted 2003-12-16 21:40:18 »

You didn't initially say that you got that code from decompiling... in any case if you had followed the initial advice given you would have found the symbols that those constant represent and hopefully would learn the APIs better than taking the code from decompiled classes.

You do realize that you are effectively implementing a MouseMotionListener and processing MouseDragged events exactly as I originally suggested?

If you had taken the advice you would be 1 week ahead Smiley

Quote
... following is the code snippet of my application

You mean that it was code you got by decompiling someone else's application.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (55 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!