Moving character with the mouse

Started by jamesreg, Thu 03/12/2009 14:16:23

Previous topic - Next topic

jamesreg

I have a scene where I need to move a scope around the screen my normal backgrounds are 800*600 I have selected a much larger background for this scene
So that I can have a scrolling room.

I have created a character and set his view to an 800*600 transparent image of a scope.

this all works find except I need to figure out how to make the character/scope image follow the mouse when moving it so that it appears the scope is moving around the screen by use of the mouse.


tzachs

In repeatedly execute, set the x & y of your character to the x & y of the mouse... 

Khris

I'd use a GUI instead of a character.

It looks like you want to move the scenery while the "hole" is fixed, so you need to translate the mouse coords into viewpoint coordinates and position the room background using SetViewPoint(x, y);

The GUI method is the easiest and safest because GUIs are positioned using screen coordinates, so they can stay at (0; 0).

If you need help regarding the maths involved, tell us the exact dimensions of the background and hole.

jamesreg

Hi thanks,

My main background is 4200*600  (my normal other background in game if this matters are 800*600)

I played with putting a 800*600 character with a demo scope sprite as view to test it out and it works except
I did not like that I could not move up and down only side to side

so I made another graphic background which is 4200*800 and kept the 800*600 character/scope sprite and it had the desired effect
I needed moved up just enough and side to side enough to do what I wanted it to do.

So I will let you guys take that information and tell me which ones you think are best for me to use or if it needs to be changed.

I would need to control it by moving mouse around and disable the mouse buttons and other interactions and create a custom mouse buttons interaction which would be the fire and reload buttons and then easily switch it back to what the settings was again.

Khris

In the room script of the room, add this:

Code: ags
function on_key_press(eKeyCode keycode) {
  ClaimEvent();

  ...
}

function on_mouse_click(MouseButton button) {
  ClaimEvent();

  ...
}


In there, put the reactions to key presses and mouse clicks.
ClaimEvent(); prevents AGS from calling the function in the global script, i.e. the usual behaviour is skipped.

SMF spam blocked by CleanTalk