surfaces

Posted by Kaz on July 31, 2006, 4:15 p.m.

So Ive been using surfaces lately. Im trying to figure how to make undos+redos but I cant quite get it.

I draw on the surface in the mouse left button event. I make a new surface each time I realease it, storing the previous surface in an array. I then draw the previous surface onto the new surface, setting the new one to the currently drawn surface. But when going back the drawing never changes. Here my code-

Create-

surs=1

cur_sur=1

sur[cur_sur]=surface_create(room_width,room_height)

surface_set_target(sur[cur_sur])

draw_clear(c_white)

surface_reset_target()

Global left-

surface_set_target(sur[cur_sur])

draw_circle(mouse_x,mouse_y,5,0)

surface_reset_target()

Global left released-

surs+=1

cur_surs=surs

sur[cur_surs]=surface_create(room_width,room_height)

surface_set_target(sur[cur_surs])

draw_surface(sur[cur_surs-1],0,0)

surface_reset_target()

Draw-

draw_surface(sur[cur_sur],0,0)

Down-

cur_sur-=1

<a href='http://64digits.com/users/Kaz/undo.gm6'>File</a>

Anyone care to help?

If you remember I was going on a trip to NJ. But my moms been busy and hasnt been able to look at the train schedule yet. So Im going after the concert(August 7th).

Comments

melee-master 18 years, 3 months ago

I should probably learn to use surfaces… Hmm… Nah. Right now I'm working on data structures. Sorry I can't help.

Kaz 18 years, 3 months ago

Wheres FredFredrickson when you need him?

cbdman25 18 years, 3 months ago

Taking a quick glance at the coding and it all seems perfect.

Maybe there's another way of doing undos and redos.

Kaz 18 years, 3 months ago

Yes the code looks fine, but when you try it its definetly not fine.

<a href='http://64digits.com/users/Kaz/undo.gm6'>File</a>

cbdman25 18 years, 3 months ago

I would try it out by computer is Game Makerless.

FredFredrickson 18 years, 3 months ago

Worked just fine for me after I implemented the code into a very early version of my Linked paint program, but I had to press down twice before it started subtracting versions of my work.

FredFredrickson 18 years, 3 months ago

Try <a href="http://www.64digits.com/download.php?name=undo_fix.gm6&id=7426">this</a>

I hacked up your code a little bit, and the up arrow no longer works, but if you draw a few lines and then press down it will indeed get rid of them. My theory is that somewhere you've jacked up the current vs number of surfaces. I would recommend using lists or something besdies arrays though, which would let you more easily (and quickly) add and remove instances of surfaces in the memory, so you only have about 10 undo levels max.

Kaz 18 years, 3 months ago

Quote:
but I had to press down twice before it started subtracting versions of my work.
Thats exactly what happened before. Im working on a new way to do it, the only problem is that the first click goes to the previous surface. Hopefilly Ill figure it out.

grayfox 18 years, 3 months ago

Quote:

…which would let you more easily (and quickly) add and remove instances of surfaces in the memory, so you only have about 10 undo levels max.

Because you would have more and more surfaces stored in memory, and since your VRAM sucks Kaz, that wouldn't be too good.

If you don't know lists and want me to teach you those too then I will.