This image was uploaded into touchdevelop and using the code below a separate action was created to declare the different animation to be used in the game.
private action Animations ()
Defining the sprite parameters
◳ sprite := ◳ SpriteSheet → create sprite("4")
◳ sprite → set height(75)
◳ sprite → set y(◳ board → height - ◳ sprite → height / 1.5)
Here is where all the animations have been defined for use in the program. This has been done utilizing the sprite sheet.
This is where the sprite stands still
◳ SpriteSheet → add grid animation("Idle", 1, 1, 0, 100000, false)
Sprite runs right
◳ SpriteSheet → add grid animation("RRun", 9, 3, 0.5, 100, false)
Sprite runs left
◳ SpriteSheet → add grid animation("LRun", 5, 3, 0.5, 100, false)
sprite is hit
◳ SpriteSheet → add grid animation("Hit", 2, 3, 0.5, 100, false)
This sets the first animation to play "Idle"
◳ sprite → hide
◳ sprite → create animation → play frames("Idle")
◳ sprite → show
end action
after testing each animation it was found that they run quite well however there were a few stray pixels and unaligned sprites, these where all fixed and now the sprite sheet runs smoothly.
now that the animations have been declared the sprite needs to be able to move. Another action was created for this purpose and called Run. This determines that if the screen is tapped left the character will move left and if the screen was tapped right the character would run right as long as stop = 1. This variable is key and will be used again later.
private action Run ()
◳ board → on tap(tapped)
where tapped(x : Number , y : Number) is
if ◳ Stop = 1 then
if x < ◳ board → width / 2 then
◳ sprite → create animation → stop
◳ sprite → show
◳ sprite → create animation → play frames("LRun")
◳ sprite → set speed x( - 100)
◳ Direction := 2
else
◳ sprite → create animation → stop
◳ sprite → show
◳ sprite → create animation → play frames("RRun")
◳ sprite → set speed x(100)
◳ Direction := 1
end if
else do nothing end if
do nothing
end
end action
This code was placed in the gameloop and ran perfectly. The next section of code is to ensure that the character stays within the screen otherwise players can hide off screen and earn points. this code is as below here the game ends if the player leaves the screen.
private action SpriteLimits ()
This limits the sprite the the confines of the screen. If the sprite leaves the screen the game finishes.
if ◳ sprite → x > ◳ board → width or ◳ sprite → x < 0 then
✿ Awww2 → play
◳ sprite → hide
◳ sprite → set x(◳ board → width / 2)
◳ sprite → set speed x(0)
▷ gameOver
else do nothing end if
end action
An effective solution to the movement of your character, Widget.
ReplyDelete