开发者

how to store a 2D game world in mysql

I am making a 2D game in javascript/ajax, that will be using data stored in mysql database. Every user have got his own "area" made of small squares that can have some 开发者_如何学Cvalues. But I have no idea, how to store values of each square in mysql, when each user can have area with different width or height. Do you have some idea?


How about storing the rectangle's four corners (x0, y0, x1, y1)? If you have an index on them, querying should be fairly efficient too, but your mileage may vary...


You should store data like this

SQUARES(squareId, XYdataOfSqare)
USERSQUARES(userId, squareId)


I would just save the coordinates, one entry for each square per user.

Table structure:

id 
square_x 
square_y
user_id

id is auto incrementing, square_x and square_y is for the square's position.

You can then insert every user's squares with single records.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜