create a Type of that functionality

BlitzMax Forums/BlitzMax Beginners Area/create a Type of that functionality

Dezzo(Posted 2012) [#1]
Hi,

i try to make Roundedrectangle Class which draws the Rectangle according to its parameters.




I´m not shure if it´s efficient the way to make a snapshot of the Picture inside of the Create Function ?

I also look for a Method to tell the Object to resize itself.
Something like:
"If Keydown then height = newValue, width = newValue "
redraw Object.
Any Idea how to achieve that one ?
When i try to create a new Method just for that i would replicate some code which is already written.......

I´m struggling a bit here......

Thx,

D


col(Posted 2012) [#2]
Hiya,

GrabImage is incredibly inefficient, but if used during the creation of objects/graphics and kept out of the mainloop then its not usually a problem.

I personally only use Methods in a Type due to a Function being outside of the scope of that Type, but its entirely your personal preference ( there are easy ways of using a Method only approach to keep your exact same code structure ).

Anyway, this is one approach to 'Resize'....




Dezzo(Posted 2012) [#3]
Hi Dave,

thx fot the fast Reply ! I never used a create Method before and in that way there is no code Rep.
There is so much to learn still. The Resize Method is clever, checking that it stops at the edges, increment width or height and at the same time clearing/creating the Image.

Speed is not important for this one.

I got it now ! Great !

Dezzo


col(Posted 2012) [#4]
Thats cool.
There are always a thousand ways to do your code :D

To use a Method only approach...



And then you'd use:

Local obj:rect = New rect.Create(200,200,200,100,4)

to create an instance of the Type. Notice using this approach that the 'New' is used at the actual point you want a new instance and not inside the Type or a Function.


Jesse(Posted 2012) [#5]
.

Last edited 2012


Dezzo(Posted 2012) [#6]
Thank you for explaining !
The Method approach is also a bit clearer to me in terms of reading. Is there an example were it can get handy ? No code , just to know when to use it. Function Create vs Method Create ?

D


Dezzo(Posted 2012) [#7]
One Question left: When i draw a backgroundimage i get a flickerin thru the Buffer swapping.
Is there a way to get rid of ? My Method of grabing the Picture is then not useful ?

D

Last edited 2012


col(Posted 2012) [#8]
Using the exact code above ? If not, can you post what you have?


Dezzo(Posted 2012) [#9]
I only added a background image.



Last edited 2012


col(Posted 2012) [#10]
Play around with the order of drawing your images, ie try moving the 'DrawImage back,0,0' to AFTER the Resizing code and BEFORE the SetAlpha? Not on a pc at mo so can't test it, but I'm sure it will just be an draw ordering issue.


Dezzo(Posted 2012) [#11]
You´r absolutely right ! The Order was it......After a Quick Change, everything works as expected.
Thank you so much !

cheers,
Dezzo