.
103 Construct2 Create Card Label From Variables
1) Download Start Up file.
Download CardGameTemplates.capx and rename the project as CardLabelVariables.
2) Destroy objects on start of layout.
3) Create CardFrame and CardPiece Instances.
Add the two new groups to the bottom of Destroy Objects group.
Add local variables, varCardLabels=A|B|C|D|E and varCardCount=5
Add System Repeat to create the CardFrame instances and assign label to SpriteHotSpot.SID.
Create SpriteCardPiece.
Set SpriteCardPiece.SID.
Set TextCardLabel.Text.
Both assignments use the expression tokenat(varCardLabels,loopindex,"|").
Move the group Pin CardLabel To CardPiece into Create CardPieces group.
OUTCOME.
4) Modify the Drag Drop Event for CardPiece.
5) Shuffle CardPieces.
For this step you need to copy the Statement Group “ShuffleIndexes” from the project file ShuffleIndexes.capx.
First, create an object DictionaryShuffle.
Then, copy the ShuffleIndexes Group from the ShuffeIndexes.capx. (by default, the local variable is set to 5 which is similar to varCardCount. Otherwise you have to change the value to match varCardCount)
Change the expression for SpriteCardPiece.SID.value and TextCardLabel.Text to tokenat(varCardLabels,int(DictionaryShuffle.Get(str(loopindex))),"|"). Instead of referring to the loopindex value to select the Letter from varCardLabels, we refer to DictionaryShuffle values which randomizes the Letter selection.
No comments:
Post a Comment