Inheritance

Hi All,

No I ain’t inherited millions, I’m just calling for help on property inheritance. Can’t seem to get a handle on this - lots of my code involves the inheritance of the fill() or stroke() properties from another object. It’s so frustrating !!! Any hints ?
Bri_G

yeah. you can type pushStyle() to save the current style (saves fill(), stroke(), strokeWith(), …), and popStyle() to set the saved style. means:

function draw()
     fill(0,0,0,255)
     -- everything here is filled black.
     pushStyle()
     -- everything here is filled black.
     fill(255,255,255,255)
     -- everything here is filled white.
     popStyle()
     -- everything here is filled black.
end

i hope this helped you!

maxiking

Hi Maxiking16,

Great - is that at rue stack ? What I mean do I have to remember the push an pop positions or can I name a style?

Bri_G

You have to remember, but thats a very Good idea!

@Bri_G you don’t have to remember the push and pop positions, all you have to do is ensure that you balance them.

For every class you create, ensure that its draw method follows this template:

function draw()
    pushStyle()
    pushMatrix()

    -- Set your necessary styles and transforms
    -- e.g.,
    fill( self.color )

    -- Draw here

    popMatrix()
    popStyle()
end

Hi Simeon,

Thanks for the feedback. Thanks to you and Maxiking16, together with one of your examples from the wiki, I think I have just realised what to do. I need to improve my coding style quite a bit.

Bri_G