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.

Newcomers AppGameKit Corner / Trying to make a sprite move

Author
Message
KMCE
8
Years of Service
User Offline
Joined: 8th Apr 2016
Location:
Posted: 8th Apr 2016 07:46
I am trying to make my first program using AppGameKit, and I am having some problems. Its a simple program in which a sprite moves, but i cannot get it to move. Ive loaded in the image for it, but i feel like the image is not linked the the sprite name correctly. I was hoping if i post my code someone could help me out, thanks...


// Project: new app
// Created: 2016-02-19

// set window properties
SetWindowTitle( "Kitty game" )
SetWindowSize( 1024, 768, 0 )

// set display properties
SetVirtualResolution( 800, 600 )
SetOrientationAllowed( 1, 1, 1, 1 )

SetVirtualResolution (800,600)

//rem load in images and sounds
LoadImage = (1, "KITTY.jpg")

//rem set up variable

1 = KITTY
KITTYXpos = 400
KITTYYpos = 300

//rem create sprites
CreateSprite (KITTY,1)

// rem put sprites on the screen


//rem do loop
do
SetSpritePosition (KITTY, KITTYXpos, KITTYYpos)
gosub moveplayer
sync()

loop


//rem gosubs

moveplayer :

if GetRawKeyState(38)
KITTYYpos = KITTYYpos -5

endif

if GetRawKeyState(40)
KITTYYpos = KITTYYpos +5

endif

if GetRawKeyState(37)
KITTYXpos = KITTYXpos -5

endif

if GetRawKeyState(39)
KITTYXpos = KITTYXpos +5

endif

SetSpritePosition(KITTY, KITTYXpos, KITTYYpos)
Return
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Apr 2016 08:16
Welcome

Change this:

1 = KITTY

to:

KITTY = 1

and this:

SetSpritePosition (KITTY, KITTYXpos, KITTYYpos)
gosub moveplayer


to this:

gosub moveplayer
SetSpritePosition (KITTY, KITTYXpos, KITTYYpos)



Things should start to move!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
KMCE
8
Years of Service
User Offline
Joined: 8th Apr 2016
Location:
Posted: 8th Apr 2016 21:06
Hi, thanks for the help, still having a problem though when I changed the code to

gosub moveplayer
SetSpritePosition (KITTY, KITTYXpos, KITTYYpos)

I am getting the error "moveplayer" is not a valid label. I dont know if I would be better trying to start the project again from scratch.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Apr 2016 21:49
It looks like you have a space between the label and the ":"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
KMCE
8
Years of Service
User Offline
Joined: 8th Apr 2016
Location:
Posted: 8th Apr 2016 22:05
Finally got it to work, thanks for you help. I ended up just starting again and writing it out again, and it worked for some reason this time

Login to post a reply

Server time is: 2024-04-25 01:56:00
Your offset time is: 2024-04-25 01:56:00