Author Topic: fe.do_nut , fe.add_surface ?  (Read 3556 times)

jedione

  • Hero Member
  • *****
  • Posts: 1135
  • punktoe
    • View Profile
fe.do_nut , fe.add_surface ?
« on: January 27, 2017, 08:27:57 PM »

does any one happen to know it their would be be a way to

fe.do_nut("scripts/start.nut"); in the layout file,,,     and give it it's own "fe.add_surface"

so the surface can be adjusted " flx*0.148, fly*0.258," in the layout.nut ?

hope this makes sence.... thanks
help a friend....

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: fe.do_nut , fe.add_surface ?
« Reply #1 on: January 28, 2017, 06:56:12 AM »
This is where you might want to start looking at how classes work. You can make your own "object" as a class that has its own surface. The class code can be in your included .nut - then you can create as many instances of that class as you want.

Here's an example:

Code: [Select]
class ArtAndText {
    surface = null  //the surface we create that will hold our objects
    art_obj = null  //an art object we will add to the surface
    text_obj = null //a text object we will add to the surface
    constructor( x, y, width, height, parent = ::fe ) {
        //create the surface - parent could be another surface - if the parent isn't given, it creates its own surface using fe.add_surface
        surface = ( parent == ::fe ) ? parent.add_surface(::fe.layout.width, ::fe.layout.height) : parent.add_surface(parent.width, parent.height)
        create( x, y, width, height)
    }
   
    function create( x, y, width, height) {
        //create the art and text objects
        art_obj = surface.add_artwork("snap", 0, 0, surface.width, surface.height)
        text_obj = surface.add_text("[Title]", 0, 0, surface.width, 50)
        //set the surface position
        set_pos( x, y, width, height)
    }
   
    function set_pos(x, y, width, height) {
        surface.x = x
        surface.y = y
        surface.width = width
        surface.height = height
    }
}

That class can now be instantiated just like other objects in attract mode:
Code: [Select]
local myObject = ArtAndText(50, 50, 320, 240)
//we can access the functions in the class
myObject.set_pos(100, 100, 320, 240)