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.

2D All the way! / Moving a 2D Sprite

Author
Message
tomshep98
User Offline
Joined: 24th Dec 2017
Location:
Posted: 8th Jan 2018 23:51
Hi I need some help with ways I can move a 2D sprite left and right. if you could leave some suggestions bellow I would be grateful
thanks

below is all my code
SetWindowSize(1024,768,0)
SetWindowTitle("Tom & Liv's adventure")
SetVirtualResolution(1024,768)


Playerx as float
Playery as float
#include "Loader.agc"
#Include "PlayerMove.agc"


GoSub Loader
do

GoSub PlayerMove

sync()
loop

loader:
LoadImage(1,"MainMenu.png")
CreateSprite(1,1)
UseNewDefaultFonts(2)
CreateText(1,"Click to Play")
SetTextColor(1,0,0,0,500)
SetTextSize(1,60)
SetTextPosition(1,394,364)


LoadImage(2,"Char1.png")

LoadImage (3,"Char2.jpg")

LoadImage(4,"Enemy1.jpg")

LoadImage(5,"Enemy2.jpg")

LoadImage(6,"Enemy3.png")


do
If GetPointerPressed() = 1
GoSub HideMenuSprite
GoSub HideMenuText
GoSub Instruction_Screen
sleep (10000)
GoSub HideInstructuon_Screen
GoSub ShowGameSprite

Endif
sync()
loop
Return

Instruction_Screen:
If GetPointerPressed() =1
CreateText(2,"Instructions")
SetTextPosition(2,394,400)
SetTextSize(2,60)
SetTextColor(2,255,255,255,500)
CreateText(3,"Press A & D keys to move left anf right")
SetTextPosition(3,394,450)
SetTextSize(3,50)
SetTextColor(3,255,255,255,500)
CreateText(4,"Press Space Bar to jump")
SetTextPosition(4,394,500)
SetTextColor(4,255,255,255,500)
Endif
Return

HideMenuSprite:
If GetPointerPressed() = 1
SetSpriteVisible(1,0)
Endif
Return

HideMenuText:
If GetPointerPressed()=1
SetTextVisible(1,0)
Endif
Return

HideInstructuon_Screen:
SetTextVisible(2,0)
SetTextVisible(3,0)
SetTextVisible(4,0)
Return

ShowGameSprite:
CreateSprite(2,2)
Playerx=GetVirtualWidth()/100 - GetSpriteWidth(2)/100
Playery=GetVirtualHeight()/1-GetSpriteHeight(2)/1
SetSpritePosition(2,Playerx,Playery)

Return



PlayerMove:
Playerx=Playerx+GetDirectionX()*12

if Playerx <0
Playerx=0
endif

if Playerx>GetVirtualWidth()-GetSpriteWidth(2)
Playerx=GetVirtualWidth()-GetSpriteWidth(2)
endif

SetSpritePosition(2,Playerx,Playery)

Return

Login to post a reply

Server time is: 2018-06-20 06:36:03
Your offset time is: 2018-06-20 06:36:03