AppGameKit Classic

AppGameKit Classic

Otillräckligt med betyg
Adding Animation frames to a Sprite.
Av thescenecommander
A guide demonstrating how quickly animation frames can be added to an existing Sprite. This tutorial expands on the previous samples.
   
Utmärkelse
Favorit
Favoritmarkerad
Avfavoritmarkerad
How to add animation frames to a sprite.
Hi,

This next guide adds a little extra gloss to our moving sprite demonstration by showing users how simple it is to add any number of animation frames to a sprite, creating a greater impression of movement.

As before you can find the resulting code posted below and I encourage you to cut and paste it into the AppGameKit IDE and play around with it yourself.


// Project: making a sprite move.
// Created: 2014-11-21

// set window properties
SetWindowTitle( "making a sprite move." )

// set variables
screenwidth=1024
screenheight=768
fullscreen=0

// set display properties for platforms that support windows, e.g., Windows or Mac.

SetWindowSize(screenwidth,screenheight,fullscreen )

// set display properties for mobile devices.

SetVirtualResolution(screenwidth,screenheight)


// Set up a sprite data

balloonsprite=1
balloonx=512
balloony=384
balloondirection=1


// create a sprite with ID that uses the balloon image
CreateSprite (balloonsprite,0)

AddSpriteAnimationFrame(balloonsprite,LoadImage("item0.png"))
AddSpriteAnimationFrame(balloonsprite,LoadImage("item1.png"))
AddSpriteAnimationFrame(balloonsprite,LoadImage("item2.png"))
AddSpriteAnimationFrame(balloonsprite,LoadImage("item3.png"))
AddSpriteAnimationFrame(balloonsprite,LoadImage("item4.png"))

PlaySprite (balloonsprite)

// Main loop

do

// set the sprite position.
SetSpritePosition (balloonsprite,balloonx,balloony)

//move the balloon along the X axis by the amount specified by balloondirection
balloonx=balloonx+balloondirection

// check to see if the balloon is near the far right edge of the screen and if so, reverse direction
if balloonx+GetSpriteWidth(balloonsprite)>screenwidth
balloondirection=-1
endif

// check to see if the balloon is near the far left edge of the screen and if so, reverse direction
if balloonx<1
balloondirection=1
endif


Sync()
loop
9 kommentarer
Colonel Slanders 28 dec, 2019 @ 13:49 
AWESOME, you are a huge help thank you, enjoy the new year! 2020
thescenecommander  [skapare] 28 dec, 2019 @ 12:34 
You need LoadSubImage. You'll need to set up a text file. You might find it faster to create smaller sprite sheets manually rather than try to calculate the atlas cords.
Colonel Slanders 28 dec, 2019 @ 9:37 
wait, i knew this, but for example. I'm trying to recreate Pacman for practice. My Sprite sheet has multiple animations of different sprites on it. https://tcrf.net/File:Pac-Man_Comparable_Sprite_Sheet.png do I need to break these down into seperate animations?
Colonel Slanders 28 dec, 2019 @ 9:32 
thank you!
thescenecommander  [skapare] 28 dec, 2019 @ 9:25 
SetSpriteAnimation(sprite,framewidth,frameheight,numbeofframes)
Play(Sprite)
Colonel Slanders 28 dec, 2019 @ 9:10 
Hey thanks for the help, but how do I use Sprite Sheets for this instance? i've been stuck looking for that information & i wish to use sprite sheets rather than using a bunch of small image files. Thanks!
thescenecommander  [skapare] 4 dec, 2014 @ 3:55 
Hi, Yes that's correct. However, multiple sprites may share the same image.
anthony_4n7 4 dec, 2014 @ 2:07 
@anthony_4n7 I'll answer to myself :) No, you cant. If sprite is still used, then Image must exist.
anthony_4n7 4 dec, 2014 @ 0:39 
When I use already created sprite using LoadImage and CreateSprite commands, can I deleteImage to save some resources?