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 DBPro Corner / "sprite frame" function behavior

Author
Message
TCat87
17
Years of Service
User Offline
Joined: 27th Dec 2006
Location:
Posted: 19th Jan 2007 01:29
I'm using DBPro. I don't understand what I'm getting from the "sprite frame" function. I'm displaying a hexagonal tile made up of a set of animated sprites. Six sprites make up the "spokes" of the tile. I change colors by changing the frame each sprite displays (1,2, or 3). Initially, there are two spokes each of the colors. To give the appearance of the tile rotating I wanted to change the sprite's frames to change the color displayed on each spoke. I set up a loop using "sprite frame" to get the frame of each spoke and shift them around the circle. All the spokes came out the same color! (As if they were all number 1.) Running the loop twice in a row displayed the tile rotated 1 time. The numbers I get when printing the results of "sprite frame" are stranger than that. I initialize the frames to 1,1,2,2,3,and 3. Before my "rotation" routine, "sprite frame" shows all 1's. After the 1st move loop, the data shows up that should have been there at first (before the loop), but the sprites display as if they were all 1s. After the 2nd loop, the sprites display like the should have after the 1st loop and "sprite frame" shows all 1's again. Can anyone explain what's going on?

Here's the code, I don't know how to do a "snippet":

type tile
serial
spriteBase
endtype
dim Tiles(1) as tile
global turn = 2
global serial
global spriteBase = 1000
randomize timer()
set image colorkey 128,64,0
create animated sprite 1,"SmallBkg.bmp",4,1,1
create animated sprite 2,"SmallCenter.bmp",3,1,2
create animated sprite 3,"SmallRays.bmp",3,1,3
offset sprite 1,sprite width(1)/2,sprite height(1)/2
offset sprite 2,sprite width(2)/2,sprite height(2)/2
offset sprite 3,-7,13

for i = 4 to 8
clone sprite 3,i
next i

rotate sprite 4,60
rotate sprite 5,120
rotate sprite 6,180
rotate sprite 7,240
rotate sprite 8,300

sync on
sync
NewTile(1,300,50,4)

do
RotateTileCCW(1)
set cursor 1,1
sync
loop
end

function NewTile(serial,x,y,ring)
Tiles(serial).spriteBase = spriteBase
for i = 1 to 8
clone sprite i,Tiles(serial).spriteBase + i
next i
set sprite frame Tiles(serial).spriteBase + 1,2
set sprite frame Tiles(serial).spriteBase + 2,3
` These six sprites (+3 thru +8) form the spokes of the hexagon
set sprite frame Tiles(serial).spriteBase + 3,1
set sprite frame Tiles(serial).spriteBase + 4,1
set sprite frame Tiles(serial).spriteBase + 5,2
set sprite frame Tiles(serial).spriteBase + 6,2
set sprite frame Tiles(serial).spriteBase + 7,3
set sprite frame Tiles(serial).spriteBase + 8,3
endfunction

function PasteTile(serial,x,y)
for i = 1 to 8
paste sprite Tiles(serial).spriteBase + i,x,y
next i
endfunction

function RotateTileCCW(tile)
`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`Tile displays OK - sprite frame data odd

` Shows tile before any change
PasteTile(1,200,50)

` Expected to print 1,1,2,2,3,3 (from NewTile function) - Prints 1,1,1,1,1,1
print "before rotate"
for i = 3 to 8
print i,"=",sprite frame(Tiles(1).spriteBase+i)
next i
print

` First time through the loop - Should do the job
hold = sprite frame(Tiles(tile).spriteBase+3)
for i = 3 to 7
set sprite frame Tiles(tile).spriteBase+i,sprite frame(Tiles(tile).spriteBase+i+1)
next i
set sprite frame Tiles(tile).spriteBase + 8,hold

`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`Tile display odd - sprite frame data one step out of phase

` Expected to show tile after rotation - Shows tile with data 1,1,1,1,1,1
PasteTile(1,200,175)

` Expected to print 1,2,2,3,3,1 - Prints 1,1,2,2,3,3 (data before change)
print "mid rotate"
for i = 3 to 8
print i,"=",sprite frame(Tiles(1).spriteBase+i)
next i
print

` Second time through the loop - Should not be necessary
hold = sprite frame(Tiles(tile).spriteBase+3)
for i = 3 to 7
set sprite frame Tiles(tile).spriteBase+i,sprite frame(Tiles(tile).spriteBase+i+1)
next i
set sprite frame Tiles(tile).spriteBase + 8,hold

`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`Tile displays OK (one step out of phase) - sprite frame data odd

` Shows tile after 1 rotation
PasteTile(1,200,300)

` Expected to print 2,2,3,3,1,1 - Prints 1,1,1,1,1,1
print "after rotate"
for i = 3 to 8
print i,"=",sprite frame(Tiles(1).spriteBase+i)
next i
print
sync
wait key
endfunction
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jan 2007 04:18
Code snips are like this:
[ code ]
Your code here.
[ /code ]

Remove the spaces between the brackets and we see the code snip.

Everything in your code looks good so I think you've discovered a new bug in Pro. You should post this in bug reports too.
TCat87
17
Years of Service
User Offline
Joined: 27th Dec 2006
Location:
Posted: 19th Jan 2007 04:31
Thanks Grog! I'm good at finding bugs.

Login to post a reply

Server time is: 2024-11-26 23:24:24
Your offset time is: 2024-11-26 23:24:24