Colouring Book / Drawing Board

Started by Cpt Ezz, Thu 30/04/2009 13:38:09

Previous topic - Next topic

Cpt Ezz

Hi guys
I want to make a drawing board / colouring book
now i have read the othe thread (http://http://www.adventuregamestudio.co.uk/yabb/index.php?topic=31837.0/)about a colouring book but it is not what i want.
i want to make a brush so when you select a colour then click and drag (like Paint) it draws, basicly a very simple paint program inside a game
is it possible??
if so how

GarageGothic

#1
It's perfectly possible (SSH's Walkcycle Generator is an example of a very basic implementation), but far from easy. I recommend you start looking into DrawingSurface functions in the AGS manual and once you know how to use those, you can start coding the interface (using on_mouse_click events and checking the current cursor coordinates in repeatedly_execute).

The most simple way to allow freehand pixel drawing would be something like:
1) Register mouse click (on_mouse_click event), set a variabel (for example "bool isdrawing = true")store mouse.x and mouse.y coordinates (let's call them prevx, prevy).
2) In repeatedly_execute, check if "isdrawing == true", if so, check if mouse button is still down - if not set "isdrawing = false", otherwise call DrawingSurface.DrawLine(mouse.x, mouse.y, prevx, prevy). Update prevx, prevy to current mouse coordinates.

If you want to go beyond simple pixel drawing, you'll also have to code a few of your own drawing functions such as line drawing (for use with sprite brushes) and flood fill.


Cpt Ezz

hi
it is not working here is my script


In Room script

// room script file
bool IsDrawing = true;

function room_RepExec()
{
  mouse.IsButtonDown(eMouseLeft);
  DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  surface.DrawLine(mouse.x, mouse.y, mouse.x, mouse.y, 5);

}

In Global Script

function on_mouse_click(MouseButton button) {
  //bool for drawing
  bool IsDrawing = true;
  {
  mouse.Update();
 
  }

the weird bit is in the screen shot, the line i draw (move the mouse around) is blotchy if i move it fast
what em i doing wrong??

Gilbert

#3
You have to release the surface to update it.
Code: ags

function room_RepExec()
{
  mouse.IsButtonDown(eMouseLeft);
  DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  surface.DrawLine(mouse.x, mouse.y, mouse.x, mouse.y, 5);
  surface.Release();
}

Also, if you want to draw continuous lines you need to memorise the position of the mouse in the last frame and draw a line from there.

GarageGothic

#4
It seems that you are using two different IsDrawing variables with the same name, one defined in the room script, the other in the global script (within a function - which means it doesn't exist outside that function). Try sticking to one or the other. Here's an example using only global script, but it can be moved to a room script as well:

Code: ags
bool IsDrawing;
int prevx;
int prevy;

function repeatedly_execute() {
  if (IsDrawing == true) {
    if (Mouse.IsButtonDown(eMouseLeft) == true) {
      DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
      surface.DrawLine(mouse.x, mouse.y, prevx, prevy, 5);
      surface.Release();
      prevx = mouse.x;
      prevy = mouse.y;
      }
    else IsDrawing = false;
    }
  }

function on_mouse_click(MouseButton button) {
  if (button == eMouseLeft) {
    IsDrawing = true;
    prevx = mouse.x;
    prevy = mouse.y;
    }
  }


In your example you only draw a pixel, not a line (because you draw it from the current mouse coordinate to the same coordinate, thus plotting a single pixel). This is why it looks blotchy when you draw too fast.

Cpt Ezz

Thank you guys
you have been a great help
i haven't been able to try out the script yet
but it looks good so Thanks

SMF spam blocked by CleanTalk