making objects move in unison: using lists · 13/7/2008 · making objects move in unison: using...
TRANSCRIPT
![Page 1: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/1.jpg)
MakingObjectsMoveinUnison:UsingLists
ByDeborahNelsonDukeUniversity
ProfessorSusanRodgerJuly13,2008UpdatedJune2014byYossra Hamid
EditedforAlice3usebyAnhTrinhJuly2016
![Page 2: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/2.jpg)
Overview•Thistutorialwillteachyouhowtouselists.Alistisasortofholdingplaceforarowofobjects.
•Withalist,youcanmakeseveralobjectsdothesamethingatthesametimewithouthavingtowriteoutcodeforeachone.Youcanalsohavethemdothesamethingoneobjectatatime.
•Wewillusealisttomakeagroupofstuffedtigerstoperformsomeactionsatthesametime,andthenoneatatime.
![Page 3: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/3.jpg)
LoadingtheWorld
• Openanewworld,withanytemplate.• Saveitinadirectorythatyoucanfindagain.• AfteryouhaveopenedthefilegointothelayoutmodebyclickingontheSetupScenebutton(bottomrightcornerofanimationscreen).
• ClickontheCameraMarkersmenu.ClickAddCameraMarker.NamethecameravieworiginalPosition
![Page 4: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/4.jpg)
AddingtheObjects
• GototheBipedclassesthenaddfourStuffedTiger objectstoyourworld.
• Addtwootherpeopletoyourworld.
• I’veaddedtheSnowMan andSnowWomanfromtheGallery.
![Page 5: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/5.jpg)
Part1:MakingaList
• Wewillusealist tomakeallfourofthetigersjumpupanddowntogetherandthenkickandspinoneatatime.
• ClickonScenetabinthetopoftheeditor,andthenclickonAddSceneProperty… undertheunmanagedsection.
• Onceaboxappears,setthevaluetypetoGalleryClass,thenclickonBipedintheSelection columninthemiddle.Youwillsee6checkmarksintheobjectcolumnontheleft.Thatmeansthelistcancontainsanybipedcharacterswehaveadded.ClickOK.
![Page 6: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/6.jpg)
![Page 7: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/7.jpg)
Makingalist(cont1)
• Checktheisarraybox• Namethelistastigers.• Clickontheinitializer ->CustomArray… ->addthefourtigersin
ØSeethescreenshotonthenextslideforanillustration.
![Page 8: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/8.jpg)
![Page 9: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/9.jpg)
Part2:Writingthemethod• Dragaeachin_togetherintomyFirstMethod.• Foritemtype:ChooseGalleryClassandcheckonBipedinthemiddlecolumnlikepreviouslythenclickOK.
• Nametheitematiger• Forarray:choosethis.characters,itwillshowasthis.tigers
![Page 10: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/10.jpg)
![Page 11: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/11.jpg)
Writingthemethod(cont1)
Ø Eachin_togethermeansthatalloftheitemsinthelistwillperformtheinstructionsthatwewilladdatthesametime.
![Page 12: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/12.jpg)
Eachin_together(cont 1)• Choose atiger inthedropdownmenuontheleft,dragturntofacetotheeachintogetherblock, andthenselectthis.camera.
• Clickonadddetail…tochangethedurationto0.25seconds.
• Enterinthecodebelowbyselectingthemovecommand,firstup1meter,thendown1meter.Makeeachcommand’sduration.25seconds.
• Playyourworld.Yourmethodshouldlooklikethis:
![Page 13: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/13.jpg)
Step2: inorder• Nowdragaforeachin_underneaththeeachin_together block, chooseBiped asitemtype,onetiger astheitemname,andthis.tigers asthearray
![Page 14: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/14.jpg)
Forallinorder(cont1)ØForeachin_meansthetigerswillperformalloftheinstructionsthatweaddinsideofit,onerightaftertheother(intheorderthattheywereaddedtothelist).
• Wewantthetigerstoeachturntheirleftlegandspinoneatatime.
• However,theonetiger isjustaplaceholder,sowecannottellonetiger toturnitsleftleg.
• Wewillhavetouseaclass-levelbuiltinfunctiontoturnonlyapartoftheobject.
![Page 15: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/15.jpg)
Foreachin_(cont 2)
• Selectonetiger intheobjecttree.• Hoveryourmouseattherightarrowsignnexttoonetiger intheobjecttree,thenclickononetiger getLeftHip
![Page 16: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/16.jpg)
![Page 17: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/17.jpg)
• Draginturn,thenbackward,then¼revolution.Setthedurationto.25seconds.
Ø Seethescreenshotonthenextslideforanillustration.
![Page 18: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/18.jpg)
![Page 19: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/19.jpg)
• Selectonetiger fromtheobjecttreeagain.• Drag intotheForeachin_ againbelowtheleftHip command,andselectturn,then right,then 1revolution.Setthedurationto.25seconds.
![Page 20: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/20.jpg)
Foreachin_(cont 2)• Thenchooseonetiger andselectonetigergetLeftHip likewedidpreviouslyanddraganotherturn,then forward,then ¼revolution.Setthedurationto.25seconds.
• YourForeachin_codeshouldlooklikethissofar:
![Page 21: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/21.jpg)
Thecompletemethod• Hereisthecompletemethod.Don’tforgettocommentyourcode!
![Page 22: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/22.jpg)
Playyourworldnow
![Page 23: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/23.jpg)
Step4:Objectswithdifferentparts• Sofar,ourlistonlyhastigersinit.Addthetwootherpeopleobjectstothelist:
1) ClickonScenetabonthetopoftheeditor2) Underunmanagedsection, clickonthebox
nexttothetigerslist3) ClickonCustomArray… andselecttheobject
youwanttoadd.Ø Seethescreenshotonthenextslideforan
illustration.
![Page 24: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/24.jpg)
![Page 25: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/25.jpg)
Warning• Youcan’taddanon-bipedobjecttoalistofBipedobjects
• Addingthesnowman andsnowwoman tothelistworksbecausetheyareBipedandbothhaveleftHip asthelabelforoneoftheirbodyparts.
• IfyourcharacterdoesnothaveapartnamedleftHip youmightgetanerrorbecausetheworldissearchingforaleftHip parttomovethatisnotthere.
![Page 26: Making Objects Move in Unison: Using Lists · 13/7/2008 · Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13 ... A list](https://reader036.vdocuments.us/reader036/viewer/2022071023/5fd851fa78c0af1b321df541/html5/thumbnails/26.jpg)
Recap• Listsareusefulforhavingmultiplecharactersperform
thesamesetofactions.• Eachin_together meanseverythinginthelistwill
performatthesametime.• Foreachin_meanseverythinginthelistwillperforman
actiononerightaftertheother.• Tofindthesub-partsofanobject,clickonthearrownext
totheobjectintheobjecttree.Makesureallofthecharactershavethesameparts,labeledthesameway.
• WARNING:Donotaddtoomanyobjectstoyourlist,becausedoingsowillslowyourworlddownsignificantly.