
I don't know if it's clear for you that Croquet has 3 different "modes":
Our recomendation is that: when you are creating a Class for a piece, in Prive mode, you can create also a TEA file for this piece. To do it you need to add the bolded lines to the initialize method - by example:
initialize
| url |
open:=false.
super initialize.
url := 'http://www.dmu.com/TeaLand/spaces/wallDoor12x7x1.tea'.
tframe := (TLoad3DSMax new initializeWithFileName:
(FileDirectory pathFrom:
{FileDirectory default pathName. 'Content'. 'wallDoor12x7x1'. 'wallDoor12x7x1.ase'})
scale: 0.1 shadeAngle: 90.1 textureMode: GLReplace) frame.
tframe collapse.
tframe boundsDepth: 3.
tframe initBounds.
self addChild: tframe.
tframe objectOwner: self.
"Finding door"
door _ (tframe find:[:frm | frm objectName = 'door']) at: 1.
TExporter export: tframe asBinary:url.
inControl := false.
When you do an instantialization of the Class you will create a .TEA file of the piece that can be uploaded to your internet server, like we saw in a lesson of the previous course.To be used in the creation of a "Remote Space", by example.
But we have an important detail here : we are not defining the position of a piece inside the initialize. It needs to be defined inside the "make-file".
The "problem"(?) is that we are defining the final position of a piece in "execution time", not in "code time"!
So: our "strong" recomendation is to change the the keyDown method of Classes to:
keyDown: pointer | c | c := pointer event2D keyCharacter. "To move X+" c = $w ifTrue:[ tframe translation: tframe translation+( tframe localTransform column1*0.5). inControl := true. ]. "To move X-" c = $s ifTrue:[ tframe translation: tframe translation-( tframe localTransform column1*0.5). inControl := true. ]. "To turn left" c = $a ifTrue:[ tframe addRotationAroundY:-90. inControl := true. ]. "To turn right" c = $d ifTrue:[ tframe addRotationAroundY: 90. inControl :=true. ]. "To go up:Y+" c = $z ifTrue:[ tframe translation: tframe translation+( tframe localTransform column2*0.5). inControl := true. ]. "To go down (oops!):Y-" c = $x ifTrue:[ tframe translation: tframe translation-( tframe localTransform column2*0.5). inControl := true. ]. "To move Z+" c = $c ifTrue:[ tframe translation: tframe translation+( tframe localTransform column3*0.5). inControl:= true. ]. "To move Z-" c = $v ifTrue:[ "Z-" tframe translation: tframe translation-( tframe localTransform column3*0.5). inControl := true. ]. "To create a clone - if piece without interactivity or animation". (c = $r) ifTrue:[ tframe:=TransparentWallRound12x7x4 new. self addChild:tframe. tframe translationX: 50 y: 0 z: -50. inControl := true. ]. c = $l ifTrue:[ "Localization" Transcript show: tframe globalPosition. inControl := true. ].
CODE COMMENTS
Why is this so important?
Because, when we put the piece in its final position+rotation, we can to know their ultimate values.
This is VERY, VERY IMPORTANT!
Working in the "Private mode" we will change the lines of the initializeDefaultSpace method of the class Private defining the ultimate position+rotation of the piece:
... tW1:=TransparentWallRound12x7x4 new. space addChild:tW1. tW1 translationX: 35.5 y: 0 z: 26.5. tW1 rotationAroundY: +180. ...
This is VERY, VERY IMPORTANT because: we can add new pieces to an space and don't need to move all the pieces for their ultimate positions again! After defined the ultimate positions of the new pieces, we need to do the same thing for them, updating our initializeDefaultSpace.
And, if we are working for the creation of a Remote Space, we will define the "make-file" for this piece, including the position-rotation:
makeTWallR1: sp | tframe url | url := 'http://www.dmu.com/TeaLand/spaces/transparentWallRound12x7x4.tea'. tframe := self loadURL: url. tframe ifNil:[ tframe translationX: 35.5 y: 0 z: 26.5. tframe rotationAroundY: +180. tframe boundsDepth: 3. tframe initBounds. ]. sp addChild: tframe.
The initializeDefaultSpace method of the Class Solo (not the Class Private) will call all the "make-files" of all the pieces of the Remote Space.
IMPORTANT: In my opinion this is the more important lesson of our courses about Croquet. You need to understand the difference of a "Private mode" and of a "Solo mode" and the convergenge between them. If you are not understanding very well this concepts you need to read again the "Basic Tutorial for Beginners" and all the lessons of this new course.
PREVIOUS LESSON NEXT LESSON T. CONTENTS HOMEPAGE
