Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: cAlien_Interact on Sat 13/02/2021 01:41:00

Title: Drawing inside the game
Post by: cAlien_Interact on Sat 13/02/2021 01:41:00
Code (ags) Select

function FE4_Interact()
{

if (Mouse.IsButtonDown(eMouseLeft))
     {
          DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
          ds.DrawingColor = Game.GetColorFromRGB(255,100,255);
          ds.DrawRectangle(mouse.x - 1, mouse.y - 1, mouse.x + 1, mouse.y + 1);
          ds.Release();
     }

}
//and next

function g5g_AnyClick()
{
  aBlop.Play();
  Display("Nice drawing...you dig great");
  player.ChangeRoom(1, 90, 160, eDirectionRight);

}


this is the code I have for drawing on my surface, it does not let me draw, only click-draw, pixel by pixel(click by click)
How do i change this so u can draw holding down leftmousebutton as you would in Mspaint, instead of clicking pixel by pixel?

If anyone knows, that could help out, thanks alot!!! :cheesy:
Title: Re: Drawing inside the game
Post by: Crimson Wizard on Sat 13/02/2021 01:43:55
I have no idea what "FE4_Interact" is or how is it called. But usually you put code like this in "repeatedly execute" room event.

If you want this to happen only under certain conditions, then you have to do some adjustments, but that's another question.
Title: Re: Drawing inside the game
Post by: cAlien_Interact on Sun 14/02/2021 20:54:10
it's just a wall i have inside a room. i want to be able to draw on it
Title: Re: Drawing inside the game
Post by: Crimson Wizard on Mon 15/02/2021 02:48:21
Quote from: cAlien_Interact on Sun 14/02/2021 20:54:10
it's just a wall i have inside a room. i want to be able to draw on it

You want to draw on a room background or room object?

If you want to draw only on a part of room background, then it may be better to put an object there, create DynamicSprite, assign to that object, and draw on that DynamicSprite instead.

Otherwise you will have to also put additional condition there that will prevent from drawing outside certain area.
Title: Re: Drawing inside the game
Post by: cAlien_Interact on Tue 16/02/2021 01:18:51
The wall is an object, and it works to draw on it, not outside it, problem is the lines drawn is not continous, cant hold down...click click
Title: Re: Drawing inside the game
Post by: Crimson Wizard on Tue 16/02/2021 01:26:21
Quote from: cAlien_Interact on Tue 16/02/2021 01:18:51
The wall is an object, and it works to draw on it, not outside it, problem is the lines drawn is not continous, cant hold down...click click

To fix that you'd simply need to move the drawing code into room's "repeatedly execute" event.

But then you also need to test if the mouse is above this object:
Code (ags) Select

     if (Mouse.IsButtonDown(eMouseLeft) && Object.GetAtScreenXY(mouse.x, mouse.y) == FE4)
     {
          DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
          ds.DrawingColor = Game.GetColorFromRGB(255,100,255);
          ds.DrawRectangle(mouse.x - 1, mouse.y - 1, mouse.x + 1, mouse.y + 1);
          ds.Release();
     }


Here I assume that the object is called FE4, if not, just change the name in condition.
Title: Re: Drawing inside the game
Post by: cAlien_Interact on Wed 17/02/2021 09:33:56
Yes FE4 is correct, will try it out, thanks

Quote from: Crimson Wizard on Tue 16/02/2021 01:26:21
Quote from: cAlien_Interact on Tue 16/02/2021 01:18:51
The wall is an object, and it works to draw on it, not outside it, problem is the lines drawn is not continous, cant hold down...click click

To fix that you'd simply need to move the drawing code into room's "repeatedly execute" event.

But then you also need to test if the mouse is above this object:
Code (ags) Select

     if (Mouse.IsButtonDown(eMouseLeft) && Object.GetAtScreenXY(mouse.x, mouse.y) == FE4)
     {
          DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
          ds.DrawingColor = Game.GetColorFromRGB(255,100,255);
          ds.DrawRectangle(mouse.x - 1, mouse.y - 1, mouse.x + 1, mouse.y + 1);
          ds.Release();
     }


Here I assume that the object is called FE4, if not, just change the name in condition.