X-offset

Started by Vincent, Tue 30/09/2014 17:55:01

Previous topic - Next topic

Vincent

Good Evening To All Agser,

Noob Question, As Usual.

I re-searched the forum about this question, and I found a lot of answers about.
I searched in the manual also and I focused the solution.
But I'm not managing to make it work at all. GetViewportX ()
If mouse move to right or left side 'of the screen' and left click mouse is pushed,
if facing right player can shoot with his gun, and viceversa.
In a Room of 640x480, it's okay.
Now, i changed the room in a 2500x800, and i can't make it to work at all.

Here's the code that i have now :

Code: ags

void on_mouse_click (MouseButton button) 
{
  ///////////////// Right Side /////////////////////
  if (button == eMouseLeft && FacingRight) 
  {
    if (mouse.x > player.x) //640x480 it's okay here
    {
    Fire(true, false); //right
    }
  }
  ///////////////// Left Side /////////////////////
  if (button == eMouseLeft && FacingLeft)
  {
    if (mouse.x < player.x ) //640x480 it's okay here
    {
    Fire(false, true); //left
    }
  }
}


I hope for anyone who knows how to do here.
above all, I hope no one is offended by reading this post..

Crimson Wizard

#1
Conversion is done this way (example):
Code: ags

// Getting screen coords from room coords
screen_x = room_x - GetViewportX();
screen_y = room_y - GetViewportY();

// Getting room coords from screen coords
room_x = screen_x + GetViewportX();
room_y = screen_y + GetViewportY();


So, in your case:

Code: ags

void on_mouse_click (MouseButton button) 
{
  int click_at_room_x = mouse.x + GetViewportX();
  ///////////////// Right Side /////////////////////
  if (button == eMouseLeft && FacingRight) 
  {
    if (click_at_room_x > player.x)
    {
    Fire(true, false); //right
    }
  }
  ///////////////// Left Side /////////////////////
  if (button == eMouseLeft && FacingLeft)
  {
    if (click_at_room_x < player.x )
    {
    Fire(false, true); //left
    }
  }
}

Vincent

#2
Ciao Crimson Wizard, Grazie Mille !

You Are Kind As Usual. The conversion part and rest it was really substantial aid.

Still Thank You for being available to answer, and I hope you can spend a good day.

SMF spam blocked by CleanTalk