Topic:   Sprites   (Read 8903 times)


0 Members and 1 Guest are viewing this topic.

bellybot1


  • GMG Newbie

  • *


  • Posts: 22

  • I love YaBB 1G - SP1!
Sprites
« on: February 18, 2009, 09:56:58 PM »
Hi

As i have just started using SilverCreator i decided that making sprites would be a good place to start. I know how to insert a sprite but what i would like to know is how to make the sprite move and also how to make it move on a grid.

thanks.

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: Sprites
« Reply #1 on: February 19, 2009, 03:42:21 PM »
Simple sprite movement code (put this in the keydown [make sure you already initialized and created the sprite in card opening])

Code: [Select]
select case key$

CASE uparrow$
PUSHSPRITE 1,0,-10

CASE downarrow$
PUSHSPRITE 1,0,10

CASE leftarrow$
PUSHSPRITE 1,-10,0

CASE rightarrow$
PUSHSPRITE 1,10,0

END SELECT

Documentation for PUSHSPRITE:

Code: [Select]
PUSHSPRITE [sprite number], [x value], [y value], [optional boolean]

There is another way to do this, as you could use conditionals to test what key the user is pressing.

Code: [Select]
IF key$ = uparrow$ THEN
PUSHSPRITE 1,0,-10
END IF

IF key$ = downarrow$ THEN
PUSHSPRITE 1,0,10
END IF

IF key$ = leftarrow$ THEN
PUSHSPRITE 1,-10,0
END IF

IF key$ = rightarrow$ THEN
PUSHSPRITE 1,10,0
END IF

It's much more elegant to use a case select, but you don't need to worry about that... both methods accomplish the same thing ;).

As for grid movement, take a look Equanox's examples.







« Last Edit: February 19, 2009, 03:49:45 PM by WarHampster »

bellybot1


  • GMG Newbie

  • *


  • Posts: 22

  • I love YaBB 1G - SP1!
Re: Sprites
« Reply #2 on: February 19, 2009, 08:57:19 PM »
Thanks for that

now that Ive sussed out moving sprites i'm looking into grids and moving my sprite around the grid. Im going to start looking at Equanox's examples but any help would be appreciated.

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: Sprites
« Reply #3 on: February 20, 2009, 07:13:12 AM »
Take a look at the examples and ask any questions about the code here...

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: Sprites
« Reply #4 on: July 03, 2009, 01:21:47 PM »
If you want to move on a grid set the x or y values in that code to the width of the grid! and make sure you create the sprite  to be aligned with it.
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/

HarryCaray


  • GMG-er

  • **


  • Posts: 119

  • I love YaBB 1G - SP1!
Re: Sprites
« Reply #5 on: July 03, 2009, 03:00:16 PM »
If you want the simplest grid example, download this.