Main Menu

Animate - example

Started by ATLUS, December 11, 2012, 10:58:34 AM

Previous topic - Next topic

ATLUS

My Animate - example
PlayBASIC Code: [Select]
; PROJECT : Project1
; AUTHOR : ATLUS
; CREATED : 11.12.2012
; EDITED : 11.12.2012
; ---------------------------------------------------------------------
setfps 60
loadFXimage "img\1.png",1
ImageMaskColour 1, rgb(255,174,201)
loadFXimage "img\2.png",2
ImageMaskColour 2, rgb(255,174,201)
loadFXimage "img\1.png",3
ImageMaskColour 3, rgb(255,174,201)
loadFXimage "img\3.png",4
ImageMaskColour 4, rgb(255,174,201)
dim img(2)
img(0)=1
img(1)=2
img(2)=3
createsprite 1
spritedrawmode 1,2
AutoCenterSpriteHandle 1,true
ScaleSprite 1,3
global CurrentImage =1
global sp_anim=0
status = 0 ;stay
moving=0

x#=400
y#=300
do
cls rgb(100,50,0)

if status=0 then CurrentImage = 1

if rightkey()=true
status=1
scalespriteX 1,3
elseif leftkey()=true
status=2
scalespriteX 1,-3
elseif upkey()=true
status=3
elseif downkey()=true
status=4
else
status=0
endif




if status=2 and leftkey()=true
x#-=1
play()
endif

if status=1 and rightkey()=true
x#+=1
play()
endif


if upkey()=true
y#-=1
play()
endif

if downkey()=true

y#+=1
play()
endif

sp_anim--
if sp_anim<0 then sp_anim=0



print status
spriteimage 1,CurrentImage

positionsprite 1,x#,y#

drawsprite 1

sync
loop

function play()
if sp_anim = 0
sp_anim = 14
CurrentImage++
if CurrentImage>4 then CurrentImage = 1
endif
endfunction


ATLUS

A little update
PlayBASIC Code: [Select]
; PROJECT : Project1
; AUTHOR : ATLUS
; CREATED : 11.12.2012
; EDITED : 11.12.2012
; ---------------------------------------------------------------------
setfps 60
loadFXimage "img\1.png",1
ImageMaskColour 1, rgb(255,174,201)
loadFXimage "img\2.png",2
ImageMaskColour 2, rgb(255,174,201)
loadFXimage "img\3.png",3
ImageMaskColour 3, rgb(255,174,201)


dim img(3)
img(0)=1
img(1)=2
img(2)=1
img(3)=3
global z=0

createsprite 1
spritedrawmode 1,2
AutoCenterSpriteHandle 1,true
ScaleSprite 1,3
global CurrentImage =1
global sp_anim=0
status = 0 ;stay

x#=400
y#=300
do
cls rgb(100,50,0)

if status=0 then z=0

if rightkey()=true
status=1
scalespriteX 1,3
elseif leftkey()=true
status=2
scalespriteX 1,-3
elseif upkey()=true
status=3
elseif downkey()=true
status=4
else
status=0
endif




if status=2 and leftkey()=true
x#-=1
walk_anim()
endif

if status=1 and rightkey()=true
x#+=1
walk_anim()
endif


if upkey()=true
y#-=1
walk_anim()
endif

if downkey()=true

y#+=1
walk_anim()
endif

sp_anim--
if sp_anim<0 then sp_anim=0



print status

spriteimage 1,CurrentImage

positionsprite 1,x#,y#

drawsprite 1

sync
loop

function walk_anim()
if sp_anim = 0
sp_anim = 14
z++
if z>3 then z = 0
CurrentImage = img(z)
endif
endfunction


kevin


Works fine..  Looks much like the Beat'em up example from years ago.   

For loading the media, a for/next loop is easier.

PlayBASIC Code: [Select]
loadFXimage "img\1.png",1
ImageMaskColour 1, rgb(255,174,201)
loadFXimage "img\2.png",2
ImageMaskColour 2, rgb(255,174,201)
loadFXimage "img\3.png",3
ImageMaskColour 3, rgb(255,174,201)




  So this stuff, can become something more like this.

PlayBASIC Code: [Select]
  For IMage=1 to 3
loadFXimage "img\"+str$(image)+".png",IMage
ImageMaskColour IMage, rgb(255,174,201)
next




ATLUS

Thanks Kevin. Kevin how do you think how is better connect collision boxes and animate frames? Like in beat'em ups games.

kevin

#4
 you could use anything,  lines, circles, polygons/shapes...  


Note: The Attaching Shapes To Characters for Multiple Collision Zones example does what you're asking

ATLUS