Game Maker's Garage Forum

Game Creation => SilverCreator => Topic started by: bellybot1 on February 18, 2009, 09:56:58 PM

Title: Sprites
Post by: bellybot1 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.
Title: Re: Sprites
Post by: WarHampster 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.







Title: Re: Sprites
Post by: bellybot1 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.
Title: Re: Sprites
Post by: WarHampster on February 20, 2009, 07:13:12 AM
Take a look at the examples and ask any questions about the code here...
Title: Re: Sprites
Post by: Connors 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.
Title: Re: Sprites
Post by: HarryCaray on July 03, 2009, 03:00:16 PM
If you want the simplest grid example, download this. (http://www.silvercreator.net/cgi-bin/yabb2/YaBB.pl?num=1216079353)