Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Animation Problem -- HELP please!

Author
Message
SnowBoardin360
13
Years of Service
User Offline
Joined: 29th Nov 2009
Location:
Posted: 2nd Feb 2010 22:59
this is my code:
sync on
sync rate 60
hide mouse

load image \"man.bmp\", 1

x=1
y=380

walk:
DO


sprite 1,x,y,1

if rightkey()=1 then inc x
if leftkey()=1 then dec x
if spacekey()=1 then delete image 1
if spacekey()=1 then goto attack

sync
loop


attack:
cls
load image \"manwithaxe.bmp\",2
sprite 2,x,y,2
sleep 100
load image \"hitaxe.bmp\",3
sprite 3,x,y,3
sleep 35
cls
load image \"man.bmp\", 1
GOTO walk

end


I just wanted to test out the 2d stuff. well after I hit the spacekey it plays the images but then leaves them there then when I push right my normal man will move to the right but that hitaxe image will stay wherever you pressed spacekey at



as you can see my hit animation played but it didn\'t go away after and go back to my basic man.

You don't fight war for your contry, you don't fight war for your Queen, you fight war for the person beside you.
Tobo
17
Years of Service
User Offline
Joined: 12th May 2005
Location:
Posted: 3rd Feb 2010 21:43
I'm no expert, but I think it's because you're only clearing the screen with CLS in the ATTACK: subroutine. As soon as you go back to the WALK: subroutine and it gets to the Sync, it'll redraw sprite 2 and 3 as they didn't actually go anywhere, you just CLS'ed!

They stay where they are because they haven't been destroyed. Sprites 2 and 3 still exist, it's just their positions aren't updated any more.

If you stick a CLS after your 'DO' command of the WALK: routine, you should get the effect you're after (albeit messily).

Hope this helps.

Toby
LBFN
15
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 4th Feb 2010 18:27
First of all, when posting code on the forum, click the CODE box, paste your code and then click the CODE box again. This will put it all nicely inside a code snippet box.

It is probably easier for me to post this code and have you look over it to see what was done. I would strongly suggest that you not use the goto command and use subroutines (included here) instead. If you end up making a large program, you will pull your hair out chasing after your code if you use goto's.

Anyway, here is something that should help you.



The code assumes you have an image for a man standing (image 1), and have images showing using the axe (images 2 and 3). It is better to store values in variables instead of hard-coding them. You can rename images 2 and 3 as you see fit.

You would do well to create a 'sprite sheet' which has same sized images for the man. You can use the 'create animated sprite' command to neatly make it into images for you.

The code uses the backdrop, but you don't have to when you are only using 2D sprites. If you want to turn the backdrop off, you will have to either create everything as a sprite (including the background) or paste the non-sprite items on the screen every loop iteration.

I hope this is a help to you. Let me know if you have any questions and I will see what I can do to help.

Login to post a reply

Server time is: 2023-01-29 06:59:11
Your offset time is: 2023-01-29 06:59:11