Description.
Let's start by creating a function that we will use to get our sprites setup.
Remember to call your new function in on start
!
function setupSprites () {
}
setupSprites()
Create three sprites that represent the three cards in play.
function setupSprites () {
let leftSprite: Sprite = sprites.create(playing_card_skillmap_assets.cardBack32x32, SpriteKind.Player)
leftSprite.setPosition(40, 30)
let playerSprite: Sprite = sprites.create(playing_card_skillmap_assets.cardBack32x32, SpriteKind.Player)
playerSprite.setPosition(80, 60)
let rightSprite: Sprite = sprites.create(playing_card_skillmap_assets.cardBack32x32, SpriteKind.Player)
rightSprite.setPosition(120, 90)
}
Hide the middle card.
// @hide
let playerSprite: Sprite = null
playerSprite.setFlag(SpriteFlag.Invisible, true)
Create a function that reveals the card. (We will do more in this function later!) Call the function when the player presses the A button or the B button.
controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
reveal()
})
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
reveal()
})
function reveal () {
// @hide
let playerSprite: Sprite = sprites.create(img`.`, 0)
playerSprite.setFlag(SpriteFlag.Invisible, false)
}
Now, let's add a deck of cards to the game!
controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
reveal()
})
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
reveal()
})
function reveal () {
playerSprite.setFlag(SpriteFlag.Invisible, false)
}
function setupSprites () {
leftSprite = sprites.create(playing_card_skillmap_assets.cardBack32x32, SpriteKind.Player)
leftSprite.setPosition(40, 30)
playerSprite = sprites.create(playing_card_skillmap_assets.cardBack32x32, SpriteKind.Player)
playerSprite.setPosition(80, 60)
rightSprite = sprites.create(playing_card_skillmap_assets.cardBack32x32, SpriteKind.Player)
rightSprite.setPosition(120, 90)
playerSprite.setFlag(SpriteFlag.Invisible, true)
}
let rightSprite: Sprite = null
let leftSprite: Sprite = null
let playerSprite: Sprite = null
setupSprites()
playing_card_skillmap_assets=github:robo-technical-group/playing_card_skillmap_assets.git
PlayingCards=github:robo-technical-group/pxt-arcade-playing-cards.git
textsprite=github:microsoft/arcade-text.git