Graphical anomolies

Previous topic - Next topic

MrTAToad

Now, I am sure with this little problem.

As you can see from the included Palm Pre screenshot, there are a couple of graphical oddities - the small shapes are strange grey cubes and for some reason the top right corner of the grid is missing.  For comparison, I've included what it should look like.

They have been scaled down, which could be the cause.

[attachment deleted by admin]

Ian Price

How are you rendering the scene? I've not had any problems with sprites or POLYVECTORs in several different apps.

Very odd.
I came. I saw. I played.

MrTAToad

#2
Everything is pretty much scaled really - the small shapes are originally 26x26 png animated sprites.  They are probably not scale down much, but it seems to be affecting it.

The alphamode would be 0.0 and smooth shading is off.

This is the main rendering routine :

Code (glbasic) Select
FUNCTION displayLevel%:setup AS TSetup,message AS TMessage,players[] AS TPlayer,currentPlayerIndex%,speed,alpha,gameMode%,playerType%
LOCAL x%,y%,item%,tile%,animate%,alpha2
LOCAL loop AS tSpot
LOCAL loop2 AS tValidPositions
LOCAL loop3 AS TPlayer
LOCAL finX%,finY%,animState% //,spotsTaken%

animState%=FALSE // Set for no animations being processed

// Display all players statuses
FOREACH loop3 IN players[]
loop3.DisplayStatus(setup,speed,currentPlayerIndex%)
NEXT

// Draw the grid border
ALPHAMODE alpha
DRAWSPRITE self.borderSprite%,self.borderX%,self.borderY%

// Display the title
IF self.levelTitle.isImage%=FALSE
setup.TextColourAndAlpha(self.levelTitle.font%,255,255,255,7,alpha)
setup.PrintText(self.levelTitle.font%,self.levelTitle.text$,self.levelTitle.x%,self.levelTitle.y%)
ELSE
setup.DrawSpr_Scale(INTEGER(self.levelTitle.text$),-1,self.levelTitle.x%,self.levelTitle.y%,0.0,1.0,FALSE)
ENDIF

// Display the round number
setup.TextColourAndAlpha(self.levelTitle.font%,255,255,0,7,alpha)
setup.PrintText(self.roundInfo.fontID%,self.roundInfo.text$,self.roundInfo.x%,self.roundInfo.y%)

animate%=TRUE
FOR y%=0 TO self.GRID_SIZEY%-1
FOR x%=0 TO self.GRID_SIZEX%-1
IF self.gridData[x%][y%][self.LAYER_MAP%]<>self.EMPTY_GRID%
IF animate%=TRUE
tile%=SPRITE_LEVELS1%
ELSE
tile%=SPRITE_LEVELS2%
ENDIF

IF alpha=0.0 AND playerType%=PLAYING_HUMAN%
IF self.gridData[x%][y%][self.LAYER_VALIDMOVES%]=self.EMPTY_GRID% AND BOUNDS(self.validPos[],0)>0
alpha2=-0.25
ELSE
alpha2=alpha
ENDIF

ALPHAMODE alpha2
ENDIF

setup.DrawSpr_Scale(tile%,self.gridData[x%][y%][self.LAYER_MAP%],self.mapX%+(x%*self.gridWidth%),self.mapY%+(y%*self.gridHeight%),0.0,1.0)
ENDIF

animate%=NOT animate%
NEXT
NEXT

// Display the selection rectangles
FOREACH loop2 IN self.validPos[]
IF loop2.moveType%=MOVE_ORIGINALPOS%
item%=SPRITE_SELECTIONRECT%
setup.DrawSpr_Scale(item%,-1,self.mapX%+(loop2.x%*self.gridWidth%),self.mapY%+(loop2.y%*self.gridHeight%),0.0,1.0)
// ELSE
// item%=SPRITE_SELECTGRID%
ENDIF

// setup.DrawSpr_Scale(item%,-1,self.mapX%+(loop2.x%*self.gridWidth%),self.mapY%+(loop2.y%*self.gridHeight%),0.0,1.0)
NEXT

// Check to see if any life graphics need moving
IF gameMode%=GAME_ARCADE% THEN animState%=players[self.humanPlayerIndex%].UpdateLifeAnimation(speed)

// Display all the spots
FOREACH loop IN self.spots[]
IF alpha<>0.0
ALPHAMODE alpha
ELSE
ALPHAMODE loop.alpha
ENDIF

setup.DrawSpr_Scale(SPRITE_PLAYERSLARGE%,loop.playerIndex%-PLAYER_1%,self.mapX%+(self.gridWidth%/2)+(self.gridWidth%*loop.x),self.mapY%+(self.gridHeight%/2)+(self.gridHeight%*loop.y),loop.angle,loop.scale,TRUE)

IF loop.moveType%<>SPOT_NOMOVE% THEN animState%=TRUE

// Deal with any animations
SELECT loop.moveType%
CASE SPOT_COPY% // Moving a copy to a new square
INC loop.x,loop.dirX%*speed*loop.speed
INC loop.y,loop.dirY%*speed*loop.speed

finX%=TRUE
finY%=TRUE

IF (loop.dirX%<0 AND loop.x>loop.destX) OR (loop.dirX%>0 AND loop.x<loop.destX) THEN finX%=FALSE
IF (loop.dirY%<0 AND loop.y>loop.destY) OR (loop.dirY%>0 AND loop.y<loop.destY) THEN finY%=FALSE

//DEBUG "Move : "+loop.x+" "+loop.destX+" "+loop.dirX%+" "+finX%+" "+finY%+"\n"

IF finX% AND finY%
self.finishPlayerMovement(setup,message,loop,players[])
ENDIF

CASE SPOT_FADEDOWN% // Fade a spot down
INC loop.alpha,loop.speed*speed
IF loop.alpha>-0.01 THEN loop.moveType%=SPOT_CHANGE1%

CASE SPOT_CHANGE1% // Move to destination position
LOCAL pIndex%

pIndex%=self.findPlayerIndex(loop.playerIndex%,players[])
self.removeSpotFromArray(INTEGER(loop.x),INTEGER(loop.y))
loop.x=loop.destX
loop.y=loop.destY
loop.moveType%=SPOT_FADEUP%
self.addSpotToArray(INTEGER(loop.x),INTEGER(loop.y),loop.playerIndex%)

// Reduce jump count if need be
players[pIndex%].updateJumpCount()


CASE SPOT_FADEUP% // Fade spot down
DEC loop.alpha,loop.speed*speed
IF loop.alpha<=-1.0
LOCAL pIndex%

pIndex%=self.findPlayerIndex(loop.playerIndex%,players[])
players[pIndex%].UpdateScore(2)
loop.moveType%=SPOT_CHECKFORTAKE%
ENDIF

CASE SPOT_SCALEDOWN% // Scale spot down
DEC loop.scale,loop.speed*speed
//DEBUG "Scale : "+loop.scale+" "+loop.speed+"\n"
IF loop.scale<=0.01
loop.moveType%=SPOT_CHANGE2%
loop.scale=0.01
ENDIF

CASE SPOT_CHANGE2% // Replace old spot and array index with new details
// Reduce losing player spot count later
LOCAL pIndex%

pIndex%=self.findPlayerIndex(loop.playerIndex%,players[])
players[pIndex%].changeSpotCount(setup,message,-1)
loop.playerIndex%=loop.winningPlayerIndex%
self.addSpotToArray(INTEGER(loop.x),INTEGER(loop.y),loop.playerIndex%)

pIndex%=self.findPlayerIndex(loop.playerIndex%,players[])
players[pIndex%].changeSpotCount(setup,message,1)
players[pIndex%].UpdateScore(5)
loop.moveType%=SPOT_SCALEUP%

CASE SPOT_SCALEUP% // Fade spot up
INC loop.scale,loop.speed*speed
IF loop.scale>=1.0
loop.scale=1.0
loop.moveType%=SPOT_NOMOVE%
ENDIF


ENDSELECT
NEXT

// Check for takes need to be a seperate pass
FOREACH loop IN self.spots[]
// DEBUG "Check : "+loop.moveType%+"\n"
IF loop.moveType%=SPOT_CHECKFORTAKE%
loop.moveType%=SPOT_NOMOVE%
item%=self.doWeNeedToChangeSpots(loop.playerIndex%,INTEGER(loop.x),INTEGER(loop.y),players[])
SELECT item%
CASE 0 // Nothing taken
DEBUG "No spots taken\n"
CASE 1 TO 4
setup.playSND(SOUND_PIECESTAKEN1%,FALSE)
DEFAULT
setup.playSND(SOUND_PIECESTAKEN2%,FALSE)
ENDSELECT
ENDIF
NEXT

RETURN animState%
ENDFUNCTION


The scaling routine is :

Code (glbasic) Select
FUNCTION DrawSpr_Scale%:spriteID%,spriteIndex%,x,y,angle,scale,useScale%=TRUE
LOCAL cosp,sinp,sx,sy,px,py,rx,ry

IF useScale%=TRUE
scale=scale*self.maxScale
ENDIF

cosp=COS(angle)
    sinp=SIN(angle)

    sx = self.spriteLoadData[spriteID%].xSize%/2.0
    sy = self.spriteLoadData[spriteID%].ySize%/2.0

// Always revolve around the centre
    px = self.spriteLoadData[spriteID%].handleXOffset%-sx
    py = self.spriteLoadData[spriteID%].handleYOffset%-sy

    // reverse rotate pivot point around center
    // of sprite
    rx = (px*cosp + py*sinp) * scale
    ry = (py*cosp - px*sinp) * scale

    // adjust center
    INC rx,sx
    INC ry,sy

IF spriteIndex%<0
    ROTOZOOMSPRITE self.spriteLoadData[spriteID%].idNumber%,x-rx,y-ry,angle,scale
    ELSE
    ROTOZOOMANIM self.spriteLoadData[spriteID%].idNumber%,spriteIndex%,x-rx,y-ry,angle,scale
    ENDIF
ENDFUNCTION

Ian Price

Have you tried breaking it up into smaller chunks and remove everything that does work? For instance just the blue background - why is that black on the Pre? How are you drawing that? Is that a sprite too? Is the gamegrid part of that background?

As for scaling, have you considered using POLYVECTOR?
I came. I saw. I played.

MrTAToad

Dont worry - I'll be checking each part :)

MrTAToad

#5
A fair few graphical problems have been sorted, although I do get the following.

In addition, I find that the title sprite is being reset to a blue block for some reason too...

I need to check each section individually, but it should be noted that I dont get so much strangeness when using a rotated display :)

[attachment deleted by admin]

Ian Price

So what caused (some of) the problems? Maybe something we all need to be aware of. :)

At least you're getting there.
I came. I saw. I played.

MrTAToad

#7
I dont know really - aside from updating the title menu graphics, all I did was clear the GLBasic temporary directory :blink:  The background plasma routine wasn't active when I posted the first picture anyway, so that one was easy to solve :)

The 320 x 480 graphical problems seem to be rather random...

Update : The border is created with CREATESCREEN, and it appears that if this is displayed during the initialisation routine, then I don't get the graphic weirdness :/  Looks like there is something slightly odd with that command (perhaps screens with the same ID number but different sizes cause problems)

Update 2 : Using a unique CREATESCREEN ID solved it.  It also seems to have solved the title logo corruption too...

Now I just need to find out why incorrect sounds are played on the Pre...


Ian Price

I came. I saw. I played.

MrTAToad