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! / Help with 2D code please.

Author
Message
stankarp
20
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: Australia
Posted: 21st Oct 2003 11:41
I am working on a turn based strategy game. After some problems I have a very nice scrolling 2d map but sprites used on the map move with the scroll.

By using code and paste sprite I was able to get the sprites to maintain their relative position on the map by moving them the oposite way to compensate for the scroll.
code-
if keystate(17)=1 and y>0 then dec y,24:by=by+24:paste sprite 1,bx,by

to save having to write separate code for every sprite I tried the following code-

if keystate(17)=1 and y>0
dec y,24
rem to prevent scrolling off top of map
if y<0 then y=0
rem test for sprite and move to compensate for scroll
for sp=1 to 20
if sprite exist(sp)=1
spx=sprite x(sp)
spy=sprite Y(sp)
spa=sprite angle(sp)
rotate sprite sp,0
paste sprite sp,spx,spy+24
rotate sprite sp,spa
endif
next sp
endif

sp are the sprite numbers. I found with paste sprite, sprites had to be angled at 0 or paste sprite does not work. In addition, I wanted to retain the angle of sprites after the scroll as it determined the direction of their next move.

The code does not return errors but does not do anything.

I dont have enough experience to work out why it doesnt work.

Any suggestions welcomed gratefully.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Oct 2003 12:30
If the top line of code works then this should work too...

if keystate(17)=1 and y>0
dec y,24
rem to prevent scrolling off top of map
if y<0 then y=0
rem test for sprite and move to compensate for scroll
for sp=1 to 20
if sprite exist(sp)=1
`spx=sprite x(sp)
`spy=sprite Y(sp)
`spa=sprite angle(sp)
`rotate sprite sp,0
paste sprite sp,bx,by
`rotate sprite sp,spa
endif
next sp
endif

I have rem'd out some lines that you have put in. It is exactly the same as the top line of code that you say works. Just slap this over that line. Then when you get this working you can try rotating the sprites.
stankarp
20
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: Australia
Posted: 21st Oct 2003 15:14
Hi Pimcho,

Neither mine or yours works. Dont know why.

Note: "bx" and "by" were values I allocated when setting up the test sprite so I had variables to adjust during the original scrolling operation. "spx" and "spy" were to replace "bx" and "by" so I did not have to allocate variables to the start location of every sprite.

Both codes cause all sprites betwen 1 and 20 to disappear. Thats the part I cant understand. The paste function is not working it appears.

Maybe I should get back into the sherry again I debugged one code on Sat night at 1am after two glasses of sherry.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 21st Oct 2003 16:15
It sounds easy to just move the sprites with the map. When you change the map x/y just change the sprites x/y the same amount. I don't know why you are having so many problems.

I am a bit confused by all this. What sort of scroll did you use. Is it Camera move, or Copy Bitmap no,x,y,no,x,y, or a sprite background. They all have different solutions to your problem. But it sounds to me like you should put the map in the same loop as the sprite loop. That should fix everything.
stankarp
20
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: Australia
Posted: 21st Oct 2003 17:15
Hi pincho,

I am using a base code from IanM that involves a large bitmap, sprite as backdrop. The main elements are as follows.

sync : center text screen width()/2,screen height()/2,"LOADING" : sync
sync on
sync rate 10
backdrop off
hide mouse

load image "CoralSea2.bmp",3
sprite 1001,0,0,3

` Disable backsave
set sprite 1001, 0, 0
I then create the unit sprites and place on map.

Using 4 key entry functions I offset the background sprite. This line of code works-

if keystate(17)=1 and y>0 then dec y,24:by=by+24:paste sprite 1,bx,by

after all the keystates I use

offset sprite 1001, x, y

I was trying to set up an auto function that reads if a sprite exists, records its x,y and angle, pastes it to offset the scroll and resets the angle so it can move in the same direction when required.

If I do it manually, I would have to set a variable for x,y and angle for every sprite and then every turn, adjust that for the scroll.eg
sprite 2,bx,by,26
set sprite priority 2,0
scale sprite 2,50
set sprite 2,1,1
rotate sprite 2,ba

Then one line per keystate per sprite to adjust for the scroll of the map.

This is like a Civilisation 3 map, or many turn based startegy games. You have a large map, too big to be on one screen because the details is too small and you in effect, zoom in on part of the map at the start and then move around it but the units and artifacts remain in their respective positions relative to the main map.

The problem is sprites are set to co-ordinates on the visible screen and move with the scroll as you know. Gamecreators advised that camera functions do not work in 2d. So I have to re-locate the sprites.

I now have a cross betwen your first code and mine partly working in that the sprites do not disappear now. However, they are moving with the scroll in a manner that suggests they are being pasted back onto the screen but not at the sprite x and sprite y position but onto the screen proper.

In other words, I am sure that the code is not reading the integers for the sprite x(spx), sprite y(spy) and sprite angle(spa) or it is not retaining them or ,possibly, overwriting them. Donk know.

I am sure the problem is now that and I cant figure out why unless there is a bug in the sprite x,sprite y and sprite angle function.
I inserted 6 sprites into the map and rotated one. When I pressed the right key(w) they jumped as if they were pasted but moved with the scroll and the rotated one rotated back to 0, but did not rotate back to "spa".
stankarp
20
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: Australia
Posted: 23rd Oct 2003 08:05
I have found the problem with the sprite location function in the above example.

I changed the paste sprite function in the above code to rotate sprite to 0 then move the sprite + or - the amount of the screen scroll depending on what direction it was scrolling and it now works (phew). However, I experimented further by rotating the sprites without the sprite angle command to get the value and that worked.

The only conclusion that I can draw is that either my syntax above is wrong, ie
spx=sprite x(sp)
spy=sprite Y(sp)
spa=sprite angle(sp)

or there is a bug in these functions as the routine was ignoring the location values that the above sequence was supposed to get. Therefore they were being just pasted back at the same position and angle relative to the screen, not the backdrop.

Thanks for your help Pincho.
stankarp
20
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: Australia
Posted: 26th Oct 2003 02:30
Mystery partly solved. Reply from Gamecreators, although I did try move sprite and that also did not work. Help manual needs abit more detail.

"> Does that mean sprite x,xprite y and sprite angle commands don't work?

Not at all - sprite positions are *not* updated by the PASTE SPRITE command,
and never have been, even in DBC. They are updated by the SPRITE and MOVE
SPRITE commands, and MOVE SPRITE has the bonus of moving the sprite at the
rotated angle - which you might find quite useful "

Login to post a reply

Server time is: 2024-04-28 01:53:54
Your offset time is: 2024-04-28 01:53:54