Hi nussmuchel
Your game idea and graphics really brightens up the forums - nice to see some pictures.
Yes you can do these with canvases and the sprite engine.
*** Colored Buttons ***For the colored buttons your canvas idea is probably the best approach.
To set the color of a canvas use the
CanvasClear command where the red,green blue values are between 0 and 255:-
syntax:- CanvasClear(canvasnumber,red,green,blue)
@ set canvas 2 to red
CanvasClear(2,255,0,0)
Next the canvas needs to respond when touched so add the code below to its event script. To edit its event script just select the canvas and then the Script button on the Properties toolbar:-
@ assumes canvas 3
Local evnum
Put CanvasEventFN(3) into evnum
If evnum=1 Then
@ do something as canvas touched example:-
GotoCard 2
EndIf
----------------
**** Door Animation ****For your door animation you could either use a canvas or the sprite engine with both methods using the image banks.
The image banks are preloaded with images before the door animation runs. Of course for canvas animation, you could just load the images from disk(sdcard) but it might not give smooth animnation although it would save memory as image banks hold their images in memory which is why they are faster.
Note, usually its best to have the image banks preloaded as the game is starting up but before the Home card loads.
(1) Canvas Door AnimationFor a canvas door animation just preload the images, then on the card holding the the animation, add a timer to cycle through the images.
To preload the images make a global procedure called
LoadImages and call it from the
Startup section of
MainCode. LoadImages has the code below.
@ ---- Load Image Banks ----
Global maxImages
Local fname
Put 5 into maxImages
ImageBankReserve(5)
Put 'Local:door1.png' into fname
ImageBankLoad(1,fname,1)
Put 'Local:door2.png' into fname
ImageBankLoad(2,fname,1)
Put 'Local:door3.png' into fname
ImageBankLoad(3,fname,1)
Put 'Local:door4.png' into fname
ImageBankLoad(4,fname,1)
Put 'Local:door5.png' into fname
ImageBankLoad(5,fname,1)
For the card with the animation, add a timer with the following code.
@ ---- Timer code ----
Global maxImages,imageCount
if (imageCount=maxImages) then
TimerOff(1)
endif
@ copy to canavas 2 and scale to fit
ImageBankToCanvas(imageCount,2,1)
Increment imageCount
@ ---- Timer set up ----
Global imageCount
Put 1 into imageCount
@ temier 1, mode = repeat, period = 100mS
TimerSet(1,2,100)
(2) Sprite engine animation There is a demo project called
FireSprite that basically just simulates a fire
It loads it images as below:-
Global xCoord,yCoord
Local result,n,x,y,w,h,mess,fname,priority
Local imagebase,fishimage,direct,res
ImageBankReserve(5)
@Put ImageBankSetSizeFN(1,300,340) into res
Put 'Local:back.png' into fname
ImageBankLoad(1,fname,0)
AnimationBackDrop(1)
@Put ImageBankSetSizeFN(2,50,50) into res
Put 'Local:fire_p1.png' into fname
ImageBankLoad(2,fname,0)
@Put ImageBankSetSizeFN(3,50,50) into res
Put 'Local:fire_p2.png' into fname
ImageBankLoad(3,fname,0)
@Put ImageBankSetSizeFN(4,50,50) into res
Put 'Local:fire_p3.png' into fname
ImageBankLoad(4,fname,1)
@Put ImageBankSetSizeFN(5,50,50) into res
Put 'Local:fire_p4.png' into fname
ImageBankLoad(5,fname,1)
Put ImageBankWidthFN(2) into w
Put ImageBankHeightFN(2) into h
Put SpriteCreateFN(1,xCoord,yCoord,w,h,1,1,1) into result
The animation is set up as:-
AnimationClear
AnimationSetCoords(10,20)
AnimationSetSize(300,340)
AnimationShow
AnimationEnable
AnimationSetPeriod(25)
The card script has this code:-
Call AnimSetup
Call LoadImages
To start the animation, this code goes in a button:-
Global imageNum
Put 2 into imageNum
AnimationRun
To stop animation, this code goes in a button:-
AnimationStop
Its probably much better to play around with the FireSprite project(its installed with HAC)
http://www.hypernextandroid.com/hnfiles/rescreator.htmlI haven't run all this code, except for that in the FireSprite proect, but hope it helps
Malkom