Hi, I'm having an issue where when bullets are created on my player sprite, instead of going up the y-axis they just spawn and sit still. My code was taken from this guide (https://smilebasicsource.com/page?pid=982) but modified, as my bullets only need to be sent upwards.
Here's my code.
I think there's something funky going on with my BulletFunc function but I'm not sure. Everything seems to work up until the point where it needs to update the y-axis position for the bullet. Or maybe it has to do with the syntax at the end of the BulletFunc.
Any suggestions? I just started coding today so it's pretty messy looking I'm sure
Bullet won't move along y-axis
Root / Programming Questions / [.]
iwanthamCreated:
It looks like you use global variables X and Y for player movement and as local variables in the BULLETFUNC function. The bullet sprite may be getting confused and sticking with the global Y variable for your player. Try changing the variable names in your BULLETFUNC to something more unique and see how that goes.
It looks like you use global variables X and Y for player movement and as local variables in the BULLETFUNC function. The bullet sprite may be getting confused and sticking with the global Y variable for your player. Try changing the variable names in your BULLETFUNC to something more unique and see how that goes.Tried renaming the local variables and it does the same thing. Very odd, I'm tempted to just rewrite the entire thing but I am very curious what I missed...
I think you are missing a call to CALL SPRITE in your game loop
I think you are missing a call to CALL SPRITE in your game loop
if button(1,B#_RDOWN)==1 then makebullet x,yI think this calls the sprite, and besides the bullet spawns, it just doesn't move. EDIT you are correct, in the guide I read there was a
call spritebut I can't find where he named that variable so I'm unsure what to do in mine...
call sprite is a command that tells smilebasic to call the functions you set up with spfunc (which you set up in MAKEBULLET).
It calls your callback function for a sprite passing in the id number through the global CALLIDX.
That is why your bullet doesn't move because you need to tell smilebasic to call the sprite functions once a frame.
call and sprite are both keywords here and not variables but I can see how it would be confusing.
all you have to do is add call sprite to your main game loop.