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! / How to make sprite shoot in facing direction

Author
Message
sskethan
14
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 5th Nov 2011 17:44 Edited at: 6th Nov 2011 15:58
Hello all,
I've been trying a number of different ways to get the character to shoot in the direction it's facing while walking. I don't know how to go about it, im stuck. Here is the code that i have so far along with the image. Any help would be great.



Ok.. I figured out the shooting but now the sprite takes one shot across the screen on startup. how do i stop this? here is what i have now. i'm working on making a gauntlet style game.

Attachments

Login to view attachments
Grog Grueslayer
Valued Member
17
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 6th Nov 2011 17:06 Edited at: 6th Nov 2011 17:12
It's because the last IF/THEN check. The sprite exists already so the first thing it does is move. To solve it you make it move based on a switch (like a light switch 0=Off 1=On). When the switch is off it doesn't move (player didn't shoot) and when it's on it does move (player shot). I made the Shoot switch as a GLOBAL to retain it's value inside/outside of functions.

With CREATE ANIMATED SPRITE there's no need to load the image first because it automatically loads it before it figures out the frames. Also I moved the PLAY SPRITE command from the first IF/THEN check to the second to last one. It's best to keep the same key checks in one check rather than many. And don't be afraid to add as many remarks as you can so if you stop this project and go back to it a month or even years later you can glance at it and instantly know what's going on.

Your code is looking good.



sskethan
14
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 7th Nov 2011 00:32
Thank you for the great advice and your help. I'll post up my progress as i go.

Login to post a reply

Server time is: 2022-11-27 05:00:59
Your offset time is: 2022-11-27 05:00:59