Topic:   Key sprites   (Read 20111 times)


0 Members and 1 Guest are viewing this topic.

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Key sprites
« on: March 13, 2011, 05:14:24 PM »
I'm having trouble getting sprites to move up and down on keydown.
-zoo
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: Key sprites
« Reply #1 on: March 14, 2011, 12:13:32 PM »
Well you should post the code you're using so they can help you better. :3
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: Key sprites
« Reply #2 on: March 14, 2011, 03:11:12 PM »
got it.
I knew this wouldn't work but it's as close as I got

py = 0
ON KEYDOWN
  IF keydown$ = "W" THEN py = py - 3
  IF keydown$ = "S" THEN py = py + 3
END KEYDOWN
SPRITE 1 py 0 dragon3.gif
ON MOUSEDOWN
  SPRITE 2 py 0 laser.gif
    SPRITEPATH 2 800 0 100
END MOUSEDOWN

thanks.
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: Key sprites
« Reply #3 on: March 14, 2011, 03:24:04 PM »
Quote
got it.
I knew this wouldn't work but it's as close as I got

py = 0
ON KEYDOWN
 Â IF keydown$ = "W" THEN py = py - 3
 Â IF keydown$ = "S" THEN py = py + 3
END KEYDOWN
SPRITE 1 py 0 dragon3.gif
ON MOUSEDOWN
 Â SPRITE 2 py 0 laser.gif
 Â   SPRITEPATH 2 800 0 100
END MOUSEDOWN

thanks.
[glb][/glb]

deja vu. I did something like this while making my TRON game. according to your code the SPRITE will only be drawn once (at the beginning.) It should either have a timer, or the KEYDOWN should look like


ON KEYDOWN
 Â IF keydown$ = "W" THEN
 Â   py = py - 3
 Â   SPRITE 1 py 0 dragon3.gif
 Â IF keydown$ = "S" THEN
 Â   py = py + 3
 Â   SPRITE 1 py 0 dragon3.gif
END KEYDOWN

The keydown method is better, and will usually always be. I can only think of one instance when a TIMER would be better.
« Last Edit: March 14, 2011, 03:26:02 PM by KurtManion »
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: Key sprites
« Reply #4 on: March 14, 2011, 04:06:50 PM »
Ok this seems to work.

py = 0
ON KEYDOWN  
  IF keydown$ = "W" THEN
    py = py - 6
    SPRITE 1 0 py dragon3.gif
      ON MOUSEDOWN
  SPRITE 2 py 0 laser.gif
    SPRITEPATH 2 800 0 100
END MOUSEDOWN

END IF
  IF keydown$ = "S" THEN
    py = py + 6
    SPRITE 1 0 py dragon3.gif
       ON MOUSEDOWN
  SPRITE 2 py 0 laser.gif
    SPRITEPATH 2 800 0 100
END MOUSEDOWN

END IF
END KEYDOWN
ON MOUSEDOWN
  SPRITE 2 py 0 laser.gif
    SPRITEPATH 2 800 0 100
END MOUSEDOWN

but the laser doesn't fire from "py".
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: Key sprites
« Reply #5 on: March 14, 2011, 09:34:17 PM »
OKAY so I copied & pasted your script into a blank doc (I substituted in the sprite files for my own of course.)

So at first I was over whelmed by the shear bulk of the code. So I cleaned up your script to see what I could find. First I changed it so that your mousedown would only be one block, since all of your blocks were the same. Then I decided to run it... It worked. I think that you may have typed in the file wrong, here's what I used to make it work

SPRITE 1 py 0 flyer_red
ON MOUSEDOWN
  SPRITE 2 py 0 flyer_blue
  SPRITEPATH 2 800 0 100
END MOUSEDOWN

The first impression I got from your code is that you wanted to change the outcome of the mousedown depending on the keydown$ variable. If that is what you want to do (and correct me If I'm wrong) then type this in right before the end ifs in the keydown block

Pkeydown$ = keydown

I used this for animating, and tracking my sprites in TRON, it might be useful to tell which way your dragon is facing to se where the lasers must originate.

good luck, I'm eager to see one of your games.
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: Key sprites
« Reply #6 on: March 15, 2011, 03:22:50 PM »
It's for a side scrolling shooter. The player controls a ship using W and S and when the mouse is clicked, a bullet shoots.
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: Key sprites
« Reply #7 on: March 15, 2011, 04:29:38 PM »
Cool!! So yeah in this case you should save yourself some grief, and put the mouse down as only one block.
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: Key sprites
« Reply #8 on: March 15, 2011, 04:48:17 PM »
Ah. Like this?


py = 0

ON KEYDOWN  
 Â IF keydown$ = "W" THEN
 Â   py = py - 6
 Â   SPRITE 1 0 py dragon3.gif
END IF
 Â IF keydown$ = "S" THEN
 Â   py = py + 6
 Â   SPRITE 1 0 py dragon3.gif
END IF
END KEYDOWN  

ON MOUSEDOWN
 Â SPRITE 2 py 0 laser.gif
 Â   SPRITEPATH 2 800 0 100
END MOUSEDOWN

Yet again everything works fine, but the shooting. The bullet always fires from the same place, not where the player is. I cannot understand why.

« Last Edit: March 15, 2011, 04:48:33 PM by zoo804 »
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: Key sprites
« Reply #9 on: March 15, 2011, 05:05:30 PM »
Quote
Ah. Like this?
ON MOUSEDOWN
 Â SPRITE 2 py 0 laser.gif
 Â   SPRITEPATH 2 800 0 100
END MOUSEDOWN

Yet again everything works fine, but the shooting. The bullet always fires from the same place, not where the player is. I cannot understand why.

Oh I see why... I think. all I can see wrong with it is that py is in the x-spot, but that shouldn't affect this.
Then I looked at the top. A line I knew was pointless, but causing no harm, is probably the root of all your problems. I took it out when I demoed it, so I could understand your script better.
The very first line sets py as zero (you do know that all variables start out as 0 anyways... Right?) and that would run overtime before the mouse button hit, but this is assuming that you have loopscript running, though. If loopscript isn't running, then I have no idea.
Although even if you don't have loopscript on, it's useful to get rid of useless code lines, before you get into a bad habit.
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: Key sprites
« Reply #10 on: March 15, 2011, 05:11:46 PM »
Yeah, I made two stupid mistakes. Is there a way to make sprites move smoothly with keydown?
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: Key sprites
« Reply #11 on: March 15, 2011, 05:14:32 PM »
Quote
Yeah, I made two stupid mistakes. Is there a way to make sprites move smoothly with keydown?
of course, heres a simple example:

SPRITE 1 x y data
ON KEYDOWN
  IF keydown$ = "UPARROW" THEN
    y = y - 21
    SPRITEPATH 1 x y
  END IF
END KEYDOWN

now of course this is only one direction, without location variables, but you get the gist.
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to