SOLVED: Walk to mouse x y+340 co-ords

Started by Slasher, Thu 05/09/2013 09:46:01

Previous topic - Next topic

Slasher

Hi

What I am trying to do is have the character cSpaceman walk to mouse x, mouse y+340

It is a 'scrolling' room and events are activated by a hotspot to throw a projectile straight up after cSpaceman has reached mouse x mouse y +340.
Code: ags

 cSpaceman.Walk(mouse.x+GetViewportX(), mouse.y+GetViewportY());

// Was using this but it ignores scrolling room.
 cSpaceman.Walk(mouse.x, mouse.y+340, eBlock, eWalkableAreas);



Will you assist me please.

cheers


Crimson Wizard

#1
Slasher, you are correctly using Viewport in the first line. You should use it in similar way in the second line:
Code: ags

cSpaceman.Walk(mouse.x + GetViewportX(), mouse.y + GetViewportY()+ 340, eBlock, eWalkableAreas);


Viewport should be used all time in the scrolling room when you use coordinates relative to screen (e.g. mouse position).

Gilbert

I don't quite understand the situation. What is supposed to mean by mouse.x + 340?

The problem is, when you click on a spot, the screen could have been scrolled beforehand, so if you use the coordinates (mouse.x, mouse.y+340), if you say, click at (100, 100) of the screen, the character will always walk to room coordinates (100, 440), no matter where the current viewport is at. If you want the destination room coordinates to have the same x-coordinates as before, and add 340 to the current y-coordinates, just straight forward make him walk to (mouse.x+GetViewportX(), mouse.y+GetViewportY()+340), though if the character is already close to the bottom edge of the room, the destination could be off-screen. Is this what you want? Otherwise please clarify your problem.

Edit: Ninja'd by Crimson Wizard, but I'll post anyway.

Slasher

Thank you so much for your help Crimson

It seems to do the trick (nod)

cheers


SMF spam blocked by CleanTalk