flashcannonballlab.docx

上传人:b****3 文档编号:24900335 上传时间:2023-06-02 格式:DOCX 页数:19 大小:58.33KB
下载 相关 举报
flashcannonballlab.docx_第1页
第1页 / 共19页
flashcannonballlab.docx_第2页
第2页 / 共19页
flashcannonballlab.docx_第3页
第3页 / 共19页
flashcannonballlab.docx_第4页
第4页 / 共19页
flashcannonballlab.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

flashcannonballlab.docx

《flashcannonballlab.docx》由会员分享,可在线阅读,更多相关《flashcannonballlab.docx(19页珍藏版)》请在冰豆网上搜索。

flashcannonballlab.docx

flashcannonballlab

Flash5/MX:

CannonballlabUPDATESFORFLASH8

NOTE:

IhavemadeupdatestofitFlash8.Thechangesare

∙thattheuseofthevarnameforinputanddynamictextboxesdoesnotworkwiththeup-to-dateFlashplayers.Instead,theinstancenamemustbesetandthe.textpropertyused.

∙MyeducationalversionofFlash8didnotappeartohaveSoundsasoneoftheCommonLibraries.Idescribealternativewaystogetsounds.

∙Thestartdragfunctionwasusedinplaceofthestartdragmethod.

Animation(movementofimagesonthescreen)canbeproducedusingFlashinseveraldifferentways.Forthisapplication,yourcodewillsimulatetheballisticsofacannonballleavingthecannon,travelingina[parabolic]arc,andeitherhittingthegroundorhittingatarget.YouwillNOTuseframeanimation:

creategraphicsofacannonballindifferentpositionsinasequenceofframes.Youwillnotusetweening.

Thefollowingfigureshowstheapplicationafterafiringofthecannon.Noticethatthecannonballhasfallenontheground.Theapplicationbeginswiththecannonballoff-stage.YourcodewillmovetheballtotheendofthecannonwhentheFIREbuttonispressed.

Hereiswhatthescreenlookslikeafterahit(achievedbecausetheplayerhaschangedtheangleofthecannonandthespeed).

Herearethecriticalfeaturesrequiredtoimplementthisapplication:

1.Calculationoftheflightpathofthecannonballbasedontheinitialspeed,theangleofthecannonandtheeffectofgravity.Thecriticalconceptforballisticsinvolvesseparatingtheinitialmotionofthecannonballintoverticalandhorizontalcomponents(alsoknownasresolvingthevectors).Thecannonballleavesthecannonatanangle.Inthesimplifiedworldwesimulatehere(noairresistance,forexample)thehorizontalmotioncontinuesatthesamevelocity(speed).Theverticalmotion,however,isaffectedbygravity.Thisiswhatcausesthearc(theparabolic)path.Theequationsforthisturnouttobejustafewlinesofcodeinthefunctionthathandlestheon(release)eventfortheFirebuttonandafewmoreinascriptinframesonthemovietimeline.

2.Awaytomakeincrementalchangesinthepositionoftheballtosimulateflight.ThiswillbedonebyusingActionScripttowritewhataretermedframeactionstomakeadjustmentstothepositionofmovieclipwecallball.

3.Awaytocheckifthetargethasbeenhitoriftheballhasreachedgroundlevel.Itturnsoutthatthisisdoneinscriptintwodifferentplaces.Thecodetodetermineiftheballhashitthegroundisdoneinaframeaction.ThecodetodetermineiftheballhashitthetargetisdoneinwhatistermedtheenterFrameclipeventofthetarget.

4.Awayfortheplayertocontrolthepathbychangingthespeedandtheangleandtomovethetarget.Tomakethisagame,weneedtoprovideawaytogetinputfromtheplayer.WedothisusingInputTextfields.Thevaluestheplayerputsinthesefieldsareusedinthecalculationofthepath.

Note:

inourprojectthenameofthetargetinstanceistarget1.Thisistoinspireyoutothinkaboutmoreanddifferenttargets.Itcouldalsohavebeentarget.Inanycase,thereisnorelationshipbetweenthisspecificinstanceandtheTellTargetconstructionusedinolderversionsofFlash,butgenerallyunnecessaryinFlash5.

Thesegraphicsarequitestylized.Afteryougetsomethingworking,youcanenhancethelook-and-feeloftheapplication.

Preparethefollowingassymbolsandthencreateinstancesonstage.Givethesymbolsthenamesindicated(usingtheInstancepanelinFlash5andthePropertiespanelinFlashMX).Youmayaskwhy,withthegraphicsbeingsosimpleandonlyoneofeachthing,doIhavetomakeeachoneamovieclip?

Theansweristhatthisapproachmakesseveralthingspossible:

youcanrefertothesymbolsbyname,refertoandchangepropertiessuchas_x,_y,and_rotation,usethehitTestmethodandyoucanwriteeventhandlers.Thelattermeansyoucanarrangeforsomethingtohappeneachframeandsomethingtohappenwhentheplayerpressesdownorreleasesthemouse.Notetheregistrationpoint(alsocalledtheoriginorthenominalposition)forthegraphics.Positionandmovement,includingrotation,isintermsofthisregistrationpointshownascross-hairswhenyouselecttheobject.

Symbolname&type

Instancename

Graphics

Associatedevents,usage

ballmovieclip

ball

Circle,registrationpointupperleftcorner(notcenter)

Propertiesreferencedandmodifiedbyframescriptsandeventhandlers.

cannonmovieclip

cannon

Horizontalline,registrationpointleftend

_xand_yreferencedtopositionball.

_rotationchangedbasedonanInputtextfield;referencedtodetermineangle

groundmovieclip

ground

Two(thick,horizontal)lines,registrationpointmid-point.

_yreferencedduringflight

targetmovieclip

target1

Thereisonly1target,butyoumaychoosetoaddmore.

Rectangle,withregistrationpointatlowerleftcorner

Clipevent(enterFrame)usedfordetectingahit.

Clipeventsmousedownandmouseupusedindragging

firebuttonbutton

NeedtoplaceDynamicTextfieldnamedcaptiononthebutton.

oval,withDynamictextfield.

on(release)isacallto_root.firecannonlocatedinthefirstframe,actionslayer

Becauseofhowwewantthetargetrectangletotiltwhenitishit,youneedtomakesuretherectangle'sregistrationpointisthelowerleftcorner,asshownbelow:

Thiswillcausetherectangletopivotfromthelowerleftcorner.Donotthinkforamomentthatweknewthisaheadoftime.

Youneedtoputonthescreenthe4textfields:

REMEMBER:

forFLASH8,settheinstancenameNOTthevarnamefortheInputtextfields.

Name

Contents

Type

Usage

Speed

Static

Labelnextfield

speed

Initially10

Input

Playertypesinnewspeed

Degrees

Static

Labelnextfield

anglein

Initially45

Input

Playertypesinnewangle.

Weproposethatyouprogramthisapplicationinstages.Thisgivesyouachancetotesttheapplicationasyougoalong.

StageI.Maketheballmoveinanarconthescreen.

StageII.Addthetestforhittingthetarget.

StageIII.Addthecolorchangeandthesoundwhentheballhitsthetarget.

StageIV.Addthefeaturetomove(drag)thetarget.

StageV.Addthetargetleaningover.

CAUTION:

Whenyoucreateanewkeyframe,unlessyoucreateablankkeyframe,Flashwillcopyallthecontentthatwasinthepreviouskeyframe.Thisgenerallyiswhatyouwant.Ifyoulatergobackandaddsomethingtoanearlierframe,thiscontentdoesnotautomaticallygetaddedtotheexistingframesthatfollow.Ifyouwantthenewmaterialtobepartofotherframes,youmustdoadditexplicitly.Thecopyandpaste-in-placecommandscanbeused.Thisalsoappliestoobjectactioncode.Ifyouaddorchangeobjectactioncodeinoneframe,youmustdothesamethingfortheotherframes,ifthatiswhatyouwant.

StageI.Therequirementsforcodingdivideintowhatisdonetosetupthemotionoftheballandwhatisdonetomovetheballiterativelyalongitspath.ThesetupisdoneinresponsetopressingthebuttonlabeledFIRE.Theiterativemovementisdoneinframeactions.

DisplaytheActionspanel(Flash5:

Window/Actions)orExpandit(FlashMXandFlash8).IntheControldropdownmenu,makesureEnableSimpleButtonActionsisNOTchecked.Totesttheprogram,youmayneedtochangethistobeingchecked.ClickontheFirebuttoninstanceonthestage.IntheActionspanel,clickthearrowtogettoExpertModeandtypein:

on(release){

_root.firecannon();

}

Thismeans:

whenthebuttonisreleased(thatis,theplayerpressesdownwiththemouseoverthebuttonandthenreleasesit),callthefunctionfirecannonthatisdefinedinthemainmovie.Wecouldputthecodehere,butitisconsideredagoodpracticetocentralizethecode.Wewillgiveanexampleofanotherwaylater.Thefirecannonfunctionwillbedefinedinthefirstframe.Beforedoingthis,youneedtodosomesetupoflayersandframes.

Namethefirstandonlylayerofthemainmovieboard.Addanewlayerandnameitactions.Youwillputallthecodeintheactionslayer.Addanotherlayerandcallitlabels.Youneedtohave3keyframesineachlayer.Thismeansyouneedtoaddtwokeyframestoeachone.Flash8:

Insert/Timeline/Keyframe.

Clickinthesecondframeofthelabelslayer.Flash5:

intheFramespanel(Window/Panels/Frame),givethisframethelabelcontinue.FlashMXandFlash8:

inthepropertiespanel,typeincontinueintheFrametextbox.Aflagwillappearintheframe.

Youwillnowputcodeinthefirstframeoftheactionslayer.Thecodesetsupvariablesanddefinesthefirecannonfunction.Theinflightvariablewillbetrueorfalsedependingonwhethertheballisin-flight.Asyouwillsee,thefirecannonroutinesetsinflighttobetrue.Watchoutforwhereitissettofalse.Thenow,then,andelapsedvariablesareusedtocalculatethetime.NoticethatthenissetinfirecannonbyacalltogetTimer.

Recallfromtheintroductionthatthecharacteristicarcofprojectilemotionoccursbecausethehorizontalvelocityremainsthesamebuttheverticalvelocitychanges.Theballisshotfromthecannonatanangle.Yourcodewilldeterminetheinitialhorizontalandverticalcomponentsoftheball'smotionusingtrigonometry.

Thevariablehspeedissettothehorizontalcomponentinfirecannon.Youneedtwovariablesfortheverticalcomponentbecauseitischangingduetotheeffectsofgravity.Thevariablegravityholdsthevalueofgravityper1/12thofasecond.(Thisappearsmoreseriousthanitreallyis.Theunitscouldbewhateverwewant,butthisvalueseemstoworkoutwell.)Thevspeed1variablewillhold

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教学研究 > 教学案例设计

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1