On Sunday, July 27, 2003, at 10:25 AM, Eric wrote:
So would I use xpos and ypos for look at data in a map?
Ok I'm lost.... so draw at 0,0?
Yes. I didn't think about this, but g isn't the graphics property for
the entire surface, just the tile, so draw 64 x 64 tiles at 0, 0 and
look them up in the map with xpos and ypos.
Since I don't know much about SpriteSurface in's and out's would it not
be better for Spritesurface to draw at what ever the tiles size's are
rather
than a set 64x64?
It can go either way.
So if I use 32x32 I would need to draw 4 for ever I tile of Sprite
Surface...ewe
That sounds very hard....
It's not that difficult.
Going from Canvas to Sprite Surface is bit of a pain. Drawing
the tiles in Canvas is easy.
It's easy but it's also very easy in a Sprite Surface.
Do this:
1) Create a SpriteSurface subclass if you haven't already. You really
should that way you can reuse the code from project to project very
easily.
2) Put this in the PaintTile event of the subclass after defining
TileHeight and TileWidths as constants or properties.
/////////////////////////////////////////
// Contributed by Joe Strout //
/////////////////////////////////////////
Dim startcol, endcol, startrow, endrow As Integer
Dim row, col As Integer
Dim worldX, worldY As Integer
Dim dx, dy As Integer
if TileWidth > 0 and TileHeight > 0 then
worldX = xpos * 64
worldY = ypos * 64
startcol = worldX / TileWidth
startrow = worldY / TileHeight
endcol = (worldX + 63) / TileWidth
endrow = (worldY + 63) / TileHeight
dy = startrow * TileHeight - worldY
for row = startrow to endrow
dx = startcol * TileWidth - worldX
for col = startcol to endcol
PaintTile g, dx, dy, row, col
dx = dx + TileWidth
next
dy = dy + TileHeight
next
else
PaintTile g, xpos, ypos, row, col
end if
3) Then put this in the instance:
dim p as picture
p = SWWorld1.map.GetTile(row, column)
if p <> nil then
if xpos > 0 and ypos > 0 and xpos < me.SurfaceWidth and ypos <
me.SurfaceHeight then
g.drawpicture p, xpos, ypos
end if
end if
(I've rewritten that last bit of code several times so I'm not sure if
it's absolutely correct.)
You should obviously modify the instance code to suit your needs but
you should only need to modify the second line.
Seth Willits
------------------------------------------------------------------------
---
President and Head Developer of Freak Software - http://www.freaksw.com
Q&A Columnist for REALbasic Developer Magazine -
http://www.rbdeveloper.com
Webmaster for REALbasic Game Central - http://www.freaksw.com/rbgames
"We are rarely proud when we are alone."
-- Voltaire
------------------------------------------------------------------------
---
---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>
.
|