1. Use the STICK instruction. It follows this syntax...
STICK OUT SX,SY
...where SX and SY are values that range between -1 and 1, which represent the stick's position relative to it's default position. (Note that the actual values will be closer to ±0.86) This values are updated as soon as you call STICK OUT again, so it is recommended to call it within a loop.
I suggest running this simple program to observe the instruction's behavior...
WHILE TRUE
STICK OUT SX,SY
?"SX:";SX:?"SY:";SY
GCIRCLE 200,120,50
GCIRCLE 200+SX*50,120-SY*50,5,#RED
WAIT 1
CLS:GCLS
WEND
Also, if you have a New 3DS or a Circle Pad Pro you can also use STICKEX in the exact same way to receive stick information from the C-Stick.
With this information you can easily offset something's position by incrementing its coordinates using STICK's values, like this...
'X AND Y = COORDINATES OF SMTH TO MOVE
STICK OUT SX,SY
INC X,SX*2 'MULTIPLY TO "CHANGE MOVE SPEED"
DEC Y,SY*2 'DEC Y SINCE SY IS NEGATIVE RELATIVE TO GRAPHIC SCREEN
2. I can't really give you much help with this one right now, sorry. Use BGOFS, maybe?
have a few if statements that check what direction the sprite is going.
'X/Y=SP X, Y
OLDX=X
OLDY=Y
'PUT THE SPRITE MOVEING CODE HERE
IF OLDX>X THEN 'finds out if the sprite has moved left. Put animation code here
You can have multiple IF statements to check what direction the sprite is going in:
OLDX>X' left
OLDX<X' right
OLDY>Y' up
OLDY<Y' down
You need the following things to make a camera:
-Variables to store the position of the camera.
-A invisible sprite(Call this the camera sprite) with management number=0
-The speed of the camera.
-SPLINK all the sprites you create with the camera sprite
Then you need to declare the functions:
DEF renderCamera
VAR I
INC cameraX%,cameraVX%
INC cameraY%,cameraVY%
SPOFS 0,-cameraX%,-cameraY%
FOR I=0 TO LEN(cameraBG)-1
BGOFS cameraBG[I],cameraX%,cameraY%
NEXT
cameraVX%=0
cameraVY%=0
END
Also:
-You need to put renderCamera in the part where your code render the changes of the game.
-To move background, you need to push the layer on cameraBG
Then just call moveCamera somewhere in your code(Try in the one that control the player) to test it.
The problem in your code is that the argument of BGOFS are on line 20. Put BGOFS cameraBG[I],cameraX%,cameraY% in the same line.
I use this code on a map editor for my tactic rpg game. It's still a work in progress but it is too complex to use it as an example.
If you have a code where you want to add the camera, then I can try to add it for you. If not, then I could share my project.
I'm trying to make a 2D sidescrolling shooter. I used BGOFS to move the camera around the map. The problem I'm having is the enemies. It's hard to make AI's with BGOFS. It's pretty hard to explain, I would probably have to show you. My question is, will your method help make AI's?
Here is your code. S223C38E. I put the camera and solved some issues with the AI.
I changed a lot of things and left some commentaries on your code.
Important things:
-Always store your sprites on variables. Right now, the amount of sprites is low, but if you have to do this if you want to handle more enemies on screen.
-Use a speed variable instead of hard coding movement.
Now the problems in your code:
-The mummy was following X=0. The player is on the center of the screen so I changed it to X+200.
-Try to not use goto. I know that in the examples they use that but it make the code confusing and hard to read. Only use it inside a function(Becuase the goto can only jump to a line inside of it).
-Declare the variables that you're going to use(Use VAR or DIM)
Few more questions,
1. What does SPLINK do in this program?
2. How does adding sprite variables make it better?
3. What does FORMAT$ do?
Anyways, Thank you so much! I'm definitely going to include you in the credits. I really don't know how to repay you. xD
1-SPLINK link a sprite(Child) with another(Parent). This mean that the sprite position is relative to the parent.
For example, you can make a Boat (Parent) and a person on it (Child). If the boat moves, then the person will move along with it. The person can move inside it too but he will still move with the boat.
2- For now your code is simple: you have one player and one enemy. But if you start to add more enemies, then you'll have problems to do the AI if you handle them without variables.
You can use arrays to store all the enemies and iterate the values of it to do things, for example validations to know where is the player and then move all the enemies.
Variables also tell you what you're using in functions.
For example, if you read "SPOFS 1,X,Y" in your code, then you won't know what is '1'. But if you read "SPOFS SPPlayer,X,Y", then you will know that the player is moving to the position (X,Y)
3- FORMAT let you insert variables in a string and define properties to it. For example '%d' is used to put an integer into the string, "%05d" let you put a integer that will use 5 characters(The unused characters will be '0').
In the code, "%- 5d" let you put an integer that will use 5 characters(The unused characters will be ' ') and aligned to the left.