I want to be able to load a map on to the screen.
image size is around 5000 by 5000.
i know the max size image is only 512 by 512.
how do i go about loading my map and be able to scroll around the map?
Loading a large image?
Moderators: Shine, Insert_witty_name
-
- Posts: 21
- Joined: Mon Apr 10, 2006 5:26 am
- Contact:
This is nice solution you can use:
You cut the image into pisses (512X512 or what ever) and use this object
To do what ever you like. (Like image but a little bit different).
You cut the image into pisses (512X512 or what ever) and use this object
To do what ever you like. (Like image but a little bit different).
Code: Select all
NewImage =
{
Images = {},
}
-- Creates new image.
function NewImage:New()
local c = {}
setmetatable(c,self)
self.__index = self
c.Images = {}
return (c)
end
-- Loads image as part of the image in the x,y pos in the global image
function NewImage:LoadImage(x,y,str)
local img = Image.load(str)
local tempImg = {}
tempImg.Image = img
tempImg.X = x
tempImg.Y = y
self.Images[table.getn(self.Images) + 1] = tempImg
end
-- Draws the image on the img. x1,y1,x2,y2 is part of the image to draw..
function NewImage:Draw(x,y,img,x1,y1,x2,y2)
local indx
local maximg = table.getn(self.Images)
if (x1 == nil) then
x1 = 0
end
if (y1 == nil) then
y1 = 0
end
if (x2 == nil) then
x2 = img:width()
end
if (y2 == nil) then
y2 = img:height()
end
for indx = 1,maximg do
local temp = self.Images[indx]
local xx1
local xx2
local yy1
local yy2
if (temp.X >= x1) then
xx1 = 0
else
xx1 = x1 - temp.X
end
if (temp.Y >= y1) then
yy1 = 0
else
yy1 = y1 - temp.Y
end
if (temp.X + temp.Image:width() <= x2) then
xx2 = temp.Image:width()
else
xx2 = x2 - temp.X
end
if (temp.Y + temp.Image:height() <= y2) then
yy2 = temp.Image:height()
else
yy2 = y2 - temp.Y
end
img:blit(x + temp.X ,y + temp.Y,temp.Image,xx1,yy1,xx2,yy2)
end
end
-- blits image img to this new image.
function NewImage:blit(x,y,img)
local indx
local maximg = table.getn(self.Images)
for indx = 1,maximg do
local temp = self.Images[indx]
local ToDraw = true
local xx1
local xx2
local yy1
local yy2
local xxx1
local yyy1
if (x >= temp.X) then
xx1 = x - temp.X
xxx1 = 0
else
xx1 = 0
xxx1 = temp.X - x
end
if (y >= temp.Y) then
yy1 = y - temp.Y
yyy1 = 0
else
yy1 = 0
yyy1 = temp.Y - y
end
if (x + img:width() <= temp.X + temp.Image:width()) then
xx2 = img:width() - xxx1
else
xx2 = temp.Image:width() - xxx1
end
if (y + img:height() <= temp.Y + temp.Image:height()) then
yy2 = img:height() - yyy1
else
yy2 = temp.Image:height() - yyy1
end
temp.Image:blit(xx1,yy1,img,xxx1,yyy1,xx2,yy2)
end
end
img = NewImage:New()
img:LoadImage(0,0,"1.png")
img:LoadImage(200,0,"2.png")
img:LoadImage(0,200,"2.png")
img:LoadImage(100,200,"1.png")
img:LoadImage(400,0,"1.png")
img:blit(160,190,Image.load("3.png"))
while true do
img:Draw(0,0,screen,0,0,400,240)
screen:flip()
end
-
- Posts: 64
- Joined: Fri Jul 15, 2005 11:44 pm
-
- Posts: 21
- Joined: Mon Apr 10, 2006 5:26 am
- Contact: