Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Question about 30Log
Started by Blex Dec 02 2018 06:10 PM

3 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

I've looked at the documentation for 30log and I've been trying it out and it works really well. However, I am just having some trouble wrapping my head around how to turn the class into an object. (sorry if I sound kinda dumb here)

 

Like for example, how would I create a display object and giving physics and collision to it? That's not mentioned on the 30log Wiki.

 

Thank you.



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

That isn't really how it works.

 

A 30log class is used to create an instance of a class, which is an object. 

 

That object is a Lua table with functions and fields attached to it.

 

When creating a object you can also create and manage a display object(s), but that display object(s) is separate and NOT the same as a class instance.

 

Here is some old code based an older version of 30Log that makes buttons:

 

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/03/oop_img_button.zip

 

 

This is why I steer folks away from using 30log and other solutions.  They don't add anything of value for basic game development and in fact add several layers of complexity and places where errors can occur.

 

 

If you're making a RPG or other data-intensive game or a game with hierarchical systems then using OOP practices may have value, but most games you'll make to start don't need them.

 

 

PS - So, for learning sake, playing around with 30log is great, but I don't think you'll need it for game dev (at least not to start).


Edited by roaminggamer, 02 December 2018 - 06:53 PM.


[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

In the code I linked, pushButtonClass.lua is the base class.

 

imgPushButtonClass.lua and toggleButtonClass.lua are derived from pushButtonClass.lua

 

See how I just override those parts of the class that are different?

 

For instance. This is the entire class definition for imgPushButtonClass.lua:

class = require 'scripts.30log'
require "scripts.pushButtonClass"


ImagePushButton = PushButton:extends()
ImagePushButton.__name = 'ImagePushButton'
ImagePushButton.selFill = {1,1,1,1}
ImagePushButton.unselFill = {1,1,1,1}
ImagePushButton.strokeWidth = 0

function ImagePushButton:draw( group, x, y, labelText, listener, params)   
     -- Build the button parts from display object(s)
     --
   self.unselRect = display.newImageRect( group, params.unselImg, self.width, self.height )
   self.unselRect.x = self.x
   self.unselRect.y = self.y
   self.unselRect:setFillColor( unpack(self.unselFill) )
   self.unselRect:setStrokeColor( unpack(self.unselStroke) )
   self.unselRect.strokeWidth = self.strokeWidth

   self.selRect = display.newImageRect( group, params.selImg, self.width, self.height )
   self.selRect.x = self.x
   self.selRect.y = self.y
   self.selRect:setFillColor( unpack(self.selFill) )
   self.selRect:setStrokeColor( unpack(self.selStroke) )
   self.selRect.strokeWidth = self.strokeWidth

   self.label = display.newText( group, self.labelText, self.x, self.y, self.labelFont, self.labelSize )
   self.label:setFillColor( unpack( self.labelColor) )

   self.unselRect.isHitTestable = true   
   self.selRect.isVisible = false
   self.unselRect:addEventListener( "touch", self )
end



[TOPIC: post.html]
#4

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

Oh, I see, ok. I'll stick with what I know. Thanks!




[topic_controls]
[/topic_controls]