android
  #41  
Old 01-31-2011, 06:26 AM
Redwolfhome's Avatar
Redwolfhome Redwolfhome is offline
Junior Member
 
Join Date: Mar 2010
Location: Germany
Posts: 91
Default

I haven´t test it yet, but I have test it with a small 100x100 black image. I have save this image with Photoshop as an compremize image.
Reply With Quote

Advertisement [Remove Advertisement]

  #42  
Old 02-01-2011, 01:59 PM
Nohajc's Avatar
Nohajc Nohajc is offline
Junior Member
 
Join Date: Mar 2010
Location: Czech Republic
Posts: 68
Default

Because there is still the "draw at negative coordinates" bug which presumably causes the player to shut down, I had an idea to write a function safeDraw which would handle the negative coordinates for you and actually crop the image automatically.

I think it's a good solution when you have lots of moving objects that often slide off the screen and you don't want to make checks every time.

Code:
function image:safeDraw(x,y) 
    local l,t=x,y 
    local ox,oy=0,0 
    local crop=false
     
    if x<0 then 
        ox=-x 
        l=0
        crop=true 
    elseif x+self:width()>screen.width() then
        ox=x+self:width()-screen.width()
        crop=true
    end
     
    if y<0 then 
        oy=-y 
        t=0
        crop=true 
    elseif y+self:height()>screen.height() then
        oy=y+self:height()-screen.height()
        crop=true
    end 
    if crop then 
        return self:draw(x,y,l,t,self:width()-ox,self:height()-oy)
    else
        return self:draw(x,y)
    end 
end
So, instead of :draw you can use :safeDraw on every image object, as you please.
__________________
There was a little man...

Last edited by Nohajc; 02-03-2011 at 04:43 AM.
Reply With Quote

  #43  
Old 02-03-2011, 04:45 AM
Nohajc's Avatar
Nohajc Nohajc is offline
Junior Member
 
Join Date: Mar 2010
Location: Czech Republic
Posts: 68
Default

I had to edit the function a bit, since it was slowing things down and also I did not take to account pictures that are off screen at right or bottom.

So, an updated version above.
__________________
There was a little man...
Reply With Quote

  #44  
Old 02-03-2011, 08:26 AM
Redwolfhome's Avatar
Redwolfhome Redwolfhome is offline
Junior Member
 
Join Date: Mar 2010
Location: Germany
Posts: 91
Default

Yes now it works right
Reply With Quote

  #45  
Old 02-12-2011, 01:07 PM
jbob182's Avatar
jbob182 jbob182 is offline
X-Fi2 Development Moderator
 
Join Date: Feb 2010
Location: The U.S.A.
Posts: 554
Default

This code is helpfull for realtime saves weather in rpg's,puzzles,fast paced action games
Here is a table to file code:
Right now it will only work with tables in this format: ( i plan on updating my function to handle all types of tables)

example[1].x = 315
example[1].y = 95
example[1].maxx = 21
example[1].maxy = 28

example[2].x = 315
example[2].y = 95
example[2].maxx = 21
example[2].maxy = 28
e.c.t.

tbl= the table you want to save
savename=the name you want your table to be saved as
filename=the file you want to save to
subtables= the number of smaller tables in on section of a table ie: in the example above there is 4

Code:
function table_save(tbl,savename,filename,subtables)
	local passes=0
	local charS,charE = "   ","\n"
	file,err = io.open( filename, "w" )
	local tables,lookup = { tbl },{ tbl }
	file:write( savename .. " = {{}")
	for i=2, #tbl do
		file:write(",{}")
	end
	file:write("}")  
	for idx,t in ipairs( tables ) do
		local thandled = {}
		for i,v in ipairs( t ) do
			thandled[i] = true
			if type( v ) == "table" then
				if not lookup[v] then
					table.insert( tables, v )
					lookup[v] = #tables
				end
			else
				local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
			end
		end
		for i,v in pairs( t ) do
			if (not thandled[i]) then
				if type( i ) == "table" then
					if not lookup[i] then
						table.insert(tables,i)
						lookup[i] = #tables
					end
				else
					passes=passes+1
					currentsubtable=math.ceil(passes/subtables)
							local index = ( type( i ) == "string" and savename.."["..currentsubtable.."]"..".".. i ) or string.format( "[%d]",i )
							-- penguins style table	   

					file:write(index.."=" )
				end
				if type( v ) == "table" then
					if not lookup[v] then
						table.insert( tables,v )
						lookup[v] = #tables
					end
				else
					local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
					file:write( value..charE )
				end
			end
		end
		file:write(charE )
	end
	file:close()
end

Usage

Code:
function table_save(example,"example","save.lua",4)

Last edited by jbob182; 02-12-2011 at 01:13 PM.
Reply With Quote

  #46  
Old 02-24-2011, 09:17 PM
jbob182's Avatar
jbob182 jbob182 is offline
X-Fi2 Development Moderator
 
Join Date: Feb 2010
Location: The U.S.A.
Posts: 554
Default

Here is a function for on player debugging

Quote:
function debug_player(functionname)
f,vrf=pcall(functionname)
if not f then
savevariable("ErrorLog.txt",variabletype(vrf))
end
end


function variabletype (o)
if type(o) == "number" then
return tostring(o)
elseif type(o) == "string" then
return string.format("%q", o)
else
return tostring(o)
end
end

function savevariable(file,variable)
Saver= io.open(file,"wb");
Saver:write("\n" .. variable .. "\n");
io.close(Saver);
end
This will output any errors to the ErrorLog.txt file

Usuage:

Code:
debug_player(animations)
Reply With Quote

  #47  
Old 07-01-2011, 01:18 PM
jameswalker101 jameswalker101 is offline
Junior Member
 
Join Date: Jul 2010
Location: United Kingdom
Posts: 91
Default

This is a PSP lua common code snippets page:
http://forums.qj.net/psp-development...-snippets.html
maybe something on here will help coding:-)
__________________
Apps: Guitar Tuner- http://anythingbutipod.com/forum/showthread.php?t=61049
Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 11:18 AM.