Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - jamesreg

#21
Thank you so much for this is working exactly the way I wanted.

I know that many times it is hard helping novice coders and even doing some of or in my case much of the coding yourself and think they are just getting freebies. The things that are learned and lessons are of great assistance.

More then just the specific things in this code I picked up shorter ways to do code, more cleaner and organized ways to do it and a few commands and functions I did not think I would be able to learn and tearing though this code and examining it will help me to improve and understand further.

I greatly thank you for the assistance and your time has not been wasted on me.
#22
I fixed that already still was not the issue with why a display statement has to be made after hitting the z hotkey to toggle the battle and cursor modes on and off.  That bug has been there in my old code before you guys helped and even now after we have tidy it up and tightened it up.
I don't know whats causing it. Id rather just hit z and toggle modes without any pop up.
#23
Good news Its working and everything seems fine and I even started using functions instead of a lot of repeated code and junk code thanks for the help.

I still have the bug where I have to use a display command and clear it when toggling between the battle mode and cursor mode.
I do not know why it is doing that.

Code: ags
// room script file

// Some handy variables
  function Nav_Mode () 
{
  Bridge_Battle=true;
  mouse.Visible=false;
  gGui2.Visible=true;
  gGui2.Centre();
  cEgo.Transparency=100;
 
   
}
  
function Cursor_Mode ()
{
  Bridge_Battle=false;
  Mouse.Mode=(eModePointer);
  mouse.Visible=true;
  gGui2.Visible=false;
  cEgo.Transparency=100;
  
}

int centerX, centerY,  wrapWidth=1, wrapHeight=1, viewportX, viewportY;
//BEFORE ROOM LOAD SCRIPTS
function room_Load()
{
 BattleMode=true;
  Nav_Mode();
  
 
  // Just calculate some useful values:
  
  centerX = System.ViewportWidth/2;
  centerY = System.ViewportHeight/2;
   wrapWidth = Room.Width - System.ViewportWidth;
   wrapHeight = Room.Height - System.ViewportHeight;
    
}
 
// Moved all the stuff to do with the battle into its own function, to keep things tidy
void updateBattle()
{
  // TODO: Update ships and stuff
 
  mouse.Update(); // This makes sure we get the most up-to-date mouse coordinates
  // Calculate viewport scrolling
  int moveX = mouse.x - centerX;
  int moveY = mouse.y - centerY;
 
  // Move viewport, wrapping around
  viewportX = (viewportX + moveX + wrapWidth) % wrapWidth;
  viewportY = (viewportY + moveY + wrapWidth) % wrapWidth;
  SetViewport(viewportX, viewportY);
  mouse.SetPosition(centerX, centerY);
}
 
//scripts that repeatedly fire
function room_RepExec()
{
  // Testing script to exit game 
  if (IsKeyPressed(eKeyEscape)) {
    QuitGame(0);
  }
  //End of Testing Script  
  
  if (Bridge_Battle==true) {
    Nav_Mode();
  }
  if (Bridge_Battle==false) {
    Cursor_Mode();
  }
  
  // If Z key is pressed and mode is battle mode
  if (IsKeyPressed(eKeyZ) && Bridge_Battle==true) {
      Cursor_Mode();
     
    Display("Navigation mode off."); // Display message that Scrolling mode is off
  }
 
  // If Z key is pressed and battle mode is off
  if (IsKeyPressed(eKeyZ) && Bridge_Battle==false) {
    Nav_Mode();
    Display("Navigation Mode on.");  //Display Message Scrolling mode is on
    
    mouse.SetPosition(centerX, centerY);
  }
 
  if(Bridge_Battle)
    updateBattle();
}
}
#24
yippie This compiled

But still some issues:

1) Screen is scrolling BY Itself all crazy the stars are just zipping by lol
2) The GUI target cursor is at top left side of window not centered
3) The mouse is viable on screen and do not think it is staying center because i can get the top pull down menu to pop up meaning its going up there.

It would seem it does indeed follow the mouse but it never stops moving that direction you are going.

I think I know what it is correct me if I am wrong but I have the code to change battle mode and cursor mode with the z button to switch back and forth in modes. But in rep execute I do not have it defined how to set up battle mode in the first place does this look to be the problem?

Code: ags
// room script file
 
// Some handy variables
  
int centerX, centerY,  wrapWidth=1, wrapHeight=1, viewportX, viewportY;
//BEFORE ROOM LOAD SCRIPTS
function room_Load()
{
 
  cEgo.Transparency=100; //Make Character invisible 
  Bridge_Battle=true;    //Put room in Battle mode starting
 
  // Just calculate some useful values:
  centerX = System.ViewportWidth/2;
  centerY = System.ViewportHeight/2;
   wrapWidth = Room.Width - System.ViewportWidth;
   wrapHeight = Room.Height - System.ViewportHeight;
}
 
// Moved all the stuff to do with the battle into its own function, to keep things tidy
void updateBattle()
{
  // TODO: Update ships and stuff
 
  mouse.Update(); // This makes sure we get the most up-to-date mouse coordinates
  // Calculate viewport scrolling
  int moveX = mouse.x - centerX;
  int moveY = mouse.y - centerY;
 
  // Move viewport, wrapping around
  viewportX = (viewportX + moveX + wrapWidth) % wrapWidth;
  viewportY = (viewportY + moveY + wrapWidth) % wrapWidth;
  SetViewport(viewportX, viewportY);
}
 
//scripts that repeatedly fire
function room_RepExec()
{
  // Testing script to exit game 
  if (IsKeyPressed(eKeyEscape)) {
    QuitGame(0);
  }
  //End of Testing Script  
  
  // If Z key is pressed and mode is battle mode
  if (IsKeyPressed(eKeyZ) && Bridge_Battle==true) {
 
    Display("Navigation mode off."); // Display message that Scrolling mode is off
    mouse.Visible=true;     // Make mouse visible
    gGui2.Visible=false;     // Make target sight invisible
    Bridge_Battle=false;    // Turn Battle mode off and restore full screen mouse movement
    Mouse.Mode=eModePointer; // Turns mouse back into pointer mode
  }
 
  // If Z key is pressed and battle mode is off
  if (IsKeyPressed(eKeyZ) && Bridge_Battle==false) {
    Display("Navigation Mode on.");  //Display Message Scrolling mode is on
    Bridge_Battle=true; //Turn battle mode and scrolling back on
 
    viewportX = GetViewportX();
    viewportY = GetViewportY();
 
    // Turn off mouse and turn on target sight
    gGui2.Visible=true;
    mouse.Visible = false;
    gGui2.Centre();
    // Center the (now invisible) mouse on the screen
    mouse.SetPosition(centerX, centerY);
  }
 
  if(Bridge_Battle)
    updateBattle();
}
#25
Current room code is this I may have missed a change or got confused in the two replies and was unsure which one to change
getting the

Failed to save room room1.crm; details below
room1.asc(16): Error (line 16): Variable 'wrapWidth' is already defined

I was confused rather to change this or not as you both spoke of it

Code: ags
// room script file
 
// Some handy variables
 int centerX, centerY, wrapWidth=1, wrapHeight=1, viewportX, viewportY;
 
//BEFORE ROOM LOAD SCRIPTS
function room_Load()
{
 
  cEgo.Transparency=100; //Make Character invisible 
  Bridge_Battle=true;    //Put room in Battle mode starting
 
  // Just calculate some useful values:
  centerX = System.ViewportWidth/2;
  centerY = System.ViewportHeight/2;
  int wrapWidth = Room.Width - System.ViewportWidth;
  int wrapHeight = Room.Height - System.ViewportHeight;
}
 
// Moved all the stuff to do with the battle into its own function, to keep things tidy
void updateBattle()
{
  // TODO: Update ships and stuff
 
  mouse.Update(); // This makes sure we get the most up-to-date mouse coordinates
  // Calculate viewport scrolling
  int moveX = mouse.x - centerX;
  int moveY = mouse.y - centerY;
 
  // Move viewport, wrapping around
  viewportX = (viewportX + moveX + wrapWidth) % wrapWidth;
  viewportY = (viewportY + moveY + wrapWidth) % wrapWidth;
  SetViewPort(viewportX, viewportY);
}
 
//scripts that repeatedly fire
function room_RepExec()
{
  // Testing script to exit game 
  if (IsKeyPressed(eKeyEscape)) {
    QuitGame(0);
  }
  //End of Testing Script  
  
  // If Z key is pressed and mode is battle mode
  if (IsKeyPressed(eKeyZ) && Bridge_Battle==true) {
 
    Display("Navigation mode off."); // Display message that Scrolling mode is off
    mouse.Visible=true;     // Make mouse visible
    gGui2.Visible=false;     // Make target sight invisible
    Bridge_Battle=false;    // Turn Battle mode off and restore full screen mouse movement
    Mouse.Mode=eModePointer; // Turns mouse back into pointer mode
  }
 
  // If Z key is pressed and battle mode is off
  if (IsKeyPressed(eKeyZ) && Bridge_Battle==false) {
    Display("Navigation Mode on.");  //Display Message Scrolling mode is on
    Bridge_Battle=true; //Turn battle mode and scrolling back on
 
    viewportX = GetViewportX();
    viewportY = GetViewportY();
 
    // Turn off mouse and turn on target sight
    gGui2.Visible=true;
    mouse.Visible = false;
    // Center the (now invisible) mouse on the screen
    mouse.SetPosition(centerX, centerY);
  }
 
  if(Bridge_Battle)
    updateBattle();
}
#26
Normal game size room is 480x270
scrolling background is 3000x3000
#27
I tried changing it to:

Code: ags
mouse.SetPosition(System.ViewportWidth / 2, System.ViewportHeight / 2); 

like the code above

I also tried changing it to
Code: ags
mouse.SetPosition(240, 135);

with the middle based on the 480x270 Game Background size

and also
Code: ags
mouse.SetPosition(1500, 1500);

the scrolling background size middle

I get this line error
Code: ags
viewportX = (viewportX + moveX + wrapWidth) % wrapWidth;


with this message
interger divided by zero

The code I posted myself above earlier was just borrowed from another forum post message.
I read though it and understand what part of it does and stuff like that but am not a good
enough coder to really understand it all. I normally do not need stuff this complex.

Bare with me even my failed attempts is teaching me new commands and things I never played with before.


#28
room1.asc(66): Error (line 66): variable 'Mouse::x' is read-only
#29
Failed to save room room1.crm; details below
room1.asc(107): Error (line 107): Variable 'wrapWidth' is already defined
#30
Ok to clarify as you asked the behavior I am wanting on the movement/mouse and such.

Basically in appearance I want it to appear there is a Target in the middle of the screen.
I want to be able to smoothly scroll around the screen.
I do not care if it is a cursor or a GUI as a target as long as I can still process mouse clicks on characters/objects in the room.
(So the idea you have of using a GUI, hiding the mouse, but centering it and still being able to process click sounds great but way to complicated for me to understand how to do. Most my game will be basic adventure game explore format which I can do but I really wanted to have this combat system in there which I admit is beyond my skills right now.)

What I will be doing in this scene is having Enemy ships (Characters or objects have not figured out which is best yet) Moving around randomly on the screen. You will hunt them down on the screen and when your target is on them you will fire your lasers/phasers with the left mouse click and fire torpedoes with the right mouse click. I will also have a hotkey that will change the cursor from target mode to scan mode where you will click and scan the object for additional information displayed. Most this you probably do not need to know but figured id explain the scene as much as possible so that if there is something I am wanting to do in the future your be seeing what I intend.


If I can get this working I already scripted arming the weapons, shields, torpedoes, Have code in there to take and give damage, drain weapons , repair them etc. It will be a nice little combat simulation thing if I get all this working.

---EDIT---
I removed the scripting to move the character around with the mouse.
I have restored a target GUI on the screen instead of the mouse being viable
Scene now scrolls smoothly.

Still need help with the centering the invisible mouse and that part
#31
Ok I have been working on this.

Here is what the scene currently is planned to do:

1) Room is currently set at 3000 x 3000 Scrolling loopable looking background

2) Normal Game room is is 480 x 270

3) The area within the viewscreen cutout gui which the mouse needs to stay in when scrolling is 437x209

3) The screen is a screen full of stars the mouse is set to scroll the screen around the stars with a GUI overlay of a view screen
     I tried different things along the way some suggest I use a centered gui and turn off the mouse. This does not work for me cause
     I want to process mouse clicks. So I used set it to follow the mouse as a target cursor. it looks to scroll more smoothly when I use a Gui
     I fixed this a bit by making the character invisible and having it follow the mouse to. But it is still a bit jerky around the mouse part not bad 
     but not as smooth looking as when i had the gui so if anyone has ideas on that part.

4) I have a hotkey by pressing the Z key is supposed to take me out of scrolling mode and restore the mouse to full screen mode to access GUI and such however I have a glitch and for some reason it will only work if in insert a Display command then cancle that text off the screen. So I have it saying "you are in scrolling mode" "You are out of scrolling mode" But I do not want any message at all just press Z and switch back and forth so If someone can see where my code is messed up at and why I need the display command to switch back and forth that be great.

4) I do not know how to wrap the screen around when you get to the top/bottom  left/write of screen I need to to wrap around to the opposite side of the screen. Can someone help with this.

Here is my room code

Code: ags
// room script file
int lastPositionX, lastPositionY;

//BEFORE ROOM LOAD SCRIPTS
function room_Load()
{
cEgo.Transparency=100; //Make Character invisible 
Bridge_Battle=true;    //Put room in Battle mode starting
}

//scripts that repeatidly fire
function room_RepExec()
{
  //Testing script to exit game 
  if (IsKeyPressed(eKeyEscape)) {
    QuitGame(0);
  }
  //End of Testing Script  
  
 //If Z key is pressed and mode is battle mode
  if (IsKeyPressed(eKeyZ) && Bridge_Battle==true) {
    
   Display("Navigation mode off."); //Display message that Scrolling mode is off
   mouse.Visible=true;     //Make mouse visable
   Bridge_Battle=false;    //Turn Battle mode off and restore full screen mose movement
  Mouse.Mode=eModePointer; //Turns mouse back into pointer mode
  //ReleaseViewport();
}
   // If Z key is pressed and battle mode is off
  if (IsKeyPressed(eKeyZ) && Bridge_Battle==false) {
   Display("Navigation Mode on.");  //Display Message Scrolling mode is on
   Mouse.Mode=eModeTarget; //Turns mouse back into a targeting cursor
   Bridge_Battle=true; //Turn battle mode and scrolling back on
   }
  
  //IF MODE IS Space Battle Mode
  //Scrolling script
  if (Bridge_Battle==true) {
     cEgo.x = mouse.x;
    cEgo.y = mouse.y;
    
    //Turn of Mouse Cursor and Turn on Targeting Cursor
    mouse.Mode=eModeTarget;
    mouse.Visible=true;
    gGui2.Visible=true;
    
  //Space Battle scrolling Mode
  //IF game is running in windowed mode
  if (System.Windowed) mouse.SetBounds(0, 0, System.ViewportWidth - 1, System.ViewportHeight - 1);
 
//Scrolling room script
int thisPositionX = mouse.x - System.ViewportWidth / 2;
  int thisPositionY = mouse.y - System.ViewportHeight / 2;
  // of course - AGS crashes if you don't check if the viewport is being changed beyond the boundaries
  int viewX = GetViewportX() + (thisPositionX - lastPositionX);
  int viewY = GetViewportY() + (thisPositionY - lastPositionY);
  if (viewX < 0) viewX = 0;
  else if (viewX >= Room.Width - System.ViewportWidth) viewX = Room.Width - System.ViewportWidth; 
  if (viewY < 0) viewY = 0;
  else if (viewY >= Room.Height - System.ViewportHeight) viewY = Room.Height - System.ViewportHeight;
  SetViewport(viewX, viewY);
  lastPositionX = thisPositionX;
  lastPositionY = thisPositionY;
 
  if (mouse.x < 118 || mouse.x > 236 || mouse.y < 118 || mouse.y > 236) {
    mouse.SetPosition(System.ViewportWidth / 2, System.ViewportHeight / 2);
    lastPositionX = 0;
    lastPositionY = 0;
    
   
  }
 if (mouse.x < 210 || mouse.x > 270 || mouse.y < 210 || mouse.y > 420) {
  mouse.SetPosition(System.ViewportWidth / 2, System.ViewportHeight / 2);
  lastPositionX = 0;
  lastPositionY = 0;
 }
 //End of Space Battle Scrolling mode


  }
}



Also I used the code for the scrolling from another forum post of someone doing the same thing. Some numbers need to be adjusted for my game but not sure how to make the conversion that area is here.

Code: ags
 if (mouse.x < 118 || mouse.x > 236 || mouse.y < 118 || mouse.y > 236) {
    mouse.SetPosition(System.ViewportWidth / 2, System.ViewportHeight / 2);
    lastPositionX = 0;
    lastPositionY = 0;
    
   
  }
 if (mouse.x < 210 || mouse.x > 270 || mouse.y < 210 || mouse.y > 420) {
  mouse.SetPosition(System.ViewportWidth / 2, System.ViewportHeight / 2);
  lastPositionX = 0;
  lastPositionY = 0;


#32
Quote from: Khris on Mon 04/02/2019 08:23:33
Scrolling the entire screen works like this:

The x viewport range is 0 to Room.Width - System.ViewportWidth
The y viewport range is 0 to Room.Height - System.ViewportHeight

The mouse's x range is 0 to System.ViewportWidth - 1
Same for y.

Which means you need this in the room's RepExec:
Code: ags
  int x = FloatToInt(IntToFloat(mouse.x) / IntToFloat(System.ViewportWidth - 1) * IntToFloat(Room.Width - System.ViewportWidth), eRoundNearest);
  int y = FloatToInt(IntToFloat(mouse.y) / IntToFloat(System.ViewportHeight - 1) * IntToFloat(Room.Heigth - System.ViewportHeight), eRoundNearest);
  SetViewport(x, y);


So your code above is all I need to make it scrolling?  I do not need what I had in there before which is this
Code: ags
if (System.Windowed) mouse.SetBounds(0, 0, System.ViewportWidth - 1, System.ViewportHeight - 1);
 
int thisPositionX = mouse.x - System.ViewportWidth / 2;
  int thisPositionY = mouse.y - System.ViewportHeight / 2;
  // of course - AGS crashes if you don't check if the viewport is being changed beyond the boundaries
  int viewX = GetViewportX() + (thisPositionX - lastPositionX);
  int viewY = GetViewportY() + (thisPositionY - lastPositionY);
  if (viewX < 0) viewX = 0;
  else if (viewX >= Room.Width - System.ViewportWidth) viewX = Room.Width - System.ViewportWidth; 
  if (viewY < 0) viewY = 0;
  else if (viewY >= Room.Height - System.ViewportHeight) viewY = Room.Height - System.ViewportHeight;
  SetViewport(viewX, viewY);
  lastPositionX = thisPositionX;
  lastPositionY = thisPositionY;
 
  if (mouse.x < 80 || mouse.x > 240 || mouse.y < 80 || mouse.y > 160) {
    mouse.SetPosition(System.ViewportWidth / 2, System.ViewportHeight / 2);
    lastPositionX = 0;
    lastPositionY = 0;
    mouse.Visible=false;
    gTargetCursor.Centre();
  }
 if (mouse.x < 80 || mouse.x > 240 || mouse.y < 80 || mouse.y > 160) {
  mouse.SetPosition(System.ViewportWidth / 2, System.ViewportHeight / 2);
  lastPositionX = 0;
  lastPositionY = 0;


I get this error when trying the smaller code:

The code I had above made it scroll but the smaller code you gave me it does not scroll at all.


Let me explain everything I am trying to do with this scene.


The above image is my background for space combat mode in which I will need the scrolling screen
It is 3000x3000


This is GUI sample art which I will overlay on top it is room size which is 480x270
The cut out viable area in middle is 437x208.
I am wanting the mouse to be confined to that 437x209 area and scroll from there so your locked into that area to contol movement.
I am told I must use a gui as a target cursor and make the mouse invisible. Ideally I would rather have the mouse visable as the target cursor
but it is very jumpy and stuff when scrolling so I guess thats why it was suggested to use a gui as target cursor. My next step after this is figuring a couple things out.

Like I would want to hit tab and break out of the confines of the viewscreen and have full screen mouse mode with no scrolling to access guis and other things. then tab to go back into scroll mode again.
Also unsure how to now be able to use that target cursor gui as if it was a mouse and be able to fire on ships and do other interactions like scanning or such I may want to do now that its a gui not a mouse.

I also need to get the screen to wrap around at the 4 edges to give a 3d look and feel to it.

Please forgive me I have put together a hell of a game so far with basic ags knowledge but am attempting a few things outside my ability to finish this project up. I do appreciate all help I have learned so much and been able to do more and more because of the support of this forum so please forgive me the help has been immensely appreciated

do I need to put the room diminsions in the setviewport part of the script you gave me?
#33
I know this is an old post I just posted a request to help with something similar to this but then found this post and the code seems to do some of what I need.

i used this code from this post

Code: ags
 int viewX = GetViewportX() + (thisPositionX - lastPositionX);
  int viewY = GetViewportY() + (thisPositionY - lastPositionY);
  if (viewX < 0) viewX = 0;
  else if (viewX >= Room.Width - System.ViewportWidth) viewX = Room.Width - System.ViewportWidth; 
  if (viewY < 0) viewY = 0;
  else if (viewY >= Room.Height - System.ViewportHeight) viewY = Room.Height - System.ViewportHeight;
  SetViewport(viewX, viewY);
  lastPositionX = thisPositionX;
  lastPositionY = thisPositionY;
 
  if (mouse.x < 80 || mouse.x > 240 || mouse.y < 80 || mouse.y > 160) {
    mouse.SetPosition(System.ViewportWidth / 2, System.ViewportHeight / 2);
    lastPositionX = 0;
    lastPositionY = 0;
  }
}
 


the above code was for 320x240 room but mine is default game 480x270 with a 2800x1400 scrolling background
so I changed the 80,240,80,160   numbers to 210, 270, 210, 420 which i think is correct change for my screen size.
is there away to scroll a 2800x1400 screen without picking up the mouse and putting it back down. I also need it to scroll and roll over and keep scrolling when it get to edges.

Also how do I take the gui target cursor and now let it act like a mouse when clicking on characters and objects on screen
I also need to be able to hit tab and break out of gui target mode and go back to mouse full screen mode to be able to access guis and such
#34
My default screen size is 480 x 270 but I am using a 1400 x 2800 background

Beings the background is larger then the room size it is automatically a scrolling background.

What I need to achieve with this scene is the following:

1) I need the cursor to be able to move freely around the screen like normal but to cause the room to scroll
2) I need it to scroll smoothly
3) I need the mouse buttons to function
4) I need to have a GUI which will look like a view screen with a cutout that mouse clicks can pass though it will be roughly the size of the normal background room of 480x270 minus a few pixels around the 4 borders
5) I need the mouse targeting mode to be confined within the borders of that gui cutout but still scroll the screen
6) I need to be able to hit tab key and break out of the border area and be able to access other guis and tab again to return to the targeting cursor within the borders.
7) I need the screen to wrap around and continue to scroll when it hits any of the four borders smoothly and instantly

I have seen a few examples of a couple of these things in forums but I am confused about how to get it to all work the way I want and that many do it various different ways so some help getting this going would help a lot.

Ok I added this code from another post

Code: ags
function room_RepExec()
{
//Bridge facing front view
if (Bridge_Scene_Front==true) {
SetViewport(0, 0);
SetBackgroundFrame(0);

}
//Bridge facing back view
if (Brige_Scene_Back==true) {
SetViewport(480, 0);
SetBackgroundFrame(0);

}
//Close up Viewscreen view
if (Bridge_Scene_Viewscreen==true) {
SetViewport(960, 0);
SetBackgroundFrame(0);

}
//full star backgound for battle mode
if (Bridge_Scene_Battlemode==true) {
SetBackgroundFrame(1); 
ReleaseViewport();  
gBridge_Viewer_Full.Visible=true;

if (System.Windowed) mouse.SetBounds(0, 0, System.ViewportWidth - 1, System.ViewportHeight - 1);

int thisPositionX = mouse.x - System.ViewportWidth / 2;
  int thisPositionY = mouse.y - System.ViewportHeight / 2;
  // of course - AGS crashes if you don't check if the viewport is being changed beyond the boundaries
  int viewX = GetViewportX() + (thisPositionX - lastPositionX);
  int viewY = GetViewportY() + (thisPositionY - lastPositionY);
  if (viewX < 0) viewX = 0;
  else if (viewX >= Room.Width - System.ViewportWidth) viewX = Room.Width - System.ViewportWidth; 
  if (viewY < 0) viewY = 0;
  else if (viewY >= Room.Height - System.ViewportHeight) viewY = Room.Height - System.ViewportHeight;
  SetViewport(viewX, viewY);
  lastPositionX = thisPositionX;
  lastPositionY = thisPositionY;
 
  if (mouse.x < 80 || mouse.x > 240 || mouse.y < 80 || mouse.y > 160) {
    mouse.SetPosition(System.ViewportWidth / 2, System.ViewportHeight / 2);
    lastPositionX = 0;
    lastPositionY = 0;
    mouse.Visible=false;
    gTargetCursor.Centre();
  }
 if (mouse.x < 80 || mouse.x > 240 || mouse.y < 80 || mouse.y > 160) {
  mouse.SetPosition(System.ViewportWidth / 2, System.ViewportHeight / 2);
  lastPositionX = 0;
  lastPositionY = 0;
}

}
}


I used a Gui as a target cursor and made the regular mouse cursor invisible.

I have to pick up the mouse and sit it back down to scroll over large areas. but i know the above code was for a game with 320x240 my base game is 480x270 and my scrolling background is 2800x1400  i think i changed the numbers of 80, 240, 80, 160  correctly I changed them to 210, 270, 210, 220 is that correct?

I also need to know how I would go about being able to use that GUI cursor to process clicks onto characters, objects etc like it is a mouse cursor.

I also need to be able to hit tab and restore normal mouse function over the entire screen or restore mouse function when on an open gui and tab again to return to gui target cursor mode.



#35
To
Quote from: Snarky on Thu 31/01/2019 15:05:25
What should happen if you try to fire while it is charging?

Yeah I got it working now.

To answer your question is the way I have it set up is you have two phaser banks.
Your go to a arming screen and arm them. Once armed they will charge up once
charged you can fire them at enemies and such and each fire will drain the power a little.
Once fully drained they will lose charge and disarm and you must wait for them to recharge
in order to use them again. If you attempt to fire while charging a message will be given
saying phasers offline. I also have a damage system here which can knock them offline
as well. Differences with the damage is the charging and rearming will not be automatic.
You actually have to have the engineer repair them which will take time or instantly repair
them by diverting power from other resources at a cost of sacrificing those other resources
such as engine speed or shields etc.
#36
Quote from: Khris on Wed 30/01/2019 20:12:38
That shouldn't be necessary; all you need is

Code: ags
  // damage
  Phaser1Charged -= 50;
  if (Phaser1Charged <= 0) {
    Phaser1Charged = 0;
    SetTimer(1, 600);
  }


So I would keep the other code and put this in when i script commands for damage to occur?
#37
Thanks

All of the suggestions has been a big help it was giving me a bit of a headache to figure but this will get me started pretty good.
#38
Thank you very much. I see what I did now. That worked how would I go about getting it to only start recharging when I hit 0.
Right now say I take 50 damage it starts recharging but I only want it to recharge if it is all the way to 0

#39
Ok,

I know this is simple but I am missing a few things I need to do with this.
I have a ship with phasers which the power level can be charged/drained etc.

I have a label on a button that tells the power level at the time.

Global variables I have set are:
Phaser1Charged (int set to 100 at start)

Labels are:
Lphaser1health

I have this code in my global execute always script

Code: ags
Lphaser1health.Text=String.Format("%d",Phaser1Charged); // to update label
 
 
  if(IsTimerExpired(1)){
  Phaser1Charged += 5; 
  SetTimer(1, 600);
  
 }
}


My label text does indeed say 100 at start I tested it by creating a by creating a button that drops Phaser1Charged to 0 when pushed and this works my label text then says zero. But after sitting around awhile the numbers never go back up or show a change in the label.
What am I missing or still need to do?  Also how do i take an Int  and define that the min amount I want it to ever be is 0 and the max amount to never go past 100
#40
Quote from: Khris on Tue 29/01/2019 14:25:52
So going from 009 to 040 is four over, three down.
Again, does the ship move in a beeline towards sector 040? Does it cross both 016 and 017?

I see what you are saying now.

I guess I had not really thought of it ideally you would take the shortest path there.
so going from 9 diagonal you would go 17,25,33 then 40 for 4 spaces.
if it went without diagonal moves all other possible moves would be 7 spaces.
It does not really matter me which way it is as long as some realistic difference is noticeable on fuel and travel time is made.

I guess I need another INT for speed as well if I am able to factor speed into this?

Thank you sorry I make things complicated in my answers sometimes. Many times I thought of going to another engine for one reason or another
but AGS community is the most amazing community in the world and so helpful. Even if one or two features is more advanced or some extra
bells and whistles in anything else the community here vs other places makes AGS the only real home to be at.
SMF spam blocked by CleanTalk