| View previous topic :: View next topic |
| Author |
Message |
Cybojanek
Joined: 16 May 2006 Posts: 1
|
Posted: Tue May 16, 2006 12:48 pm Post subject: Help with screen:blit... |
|
|
Hi,
I recenley started coding and I recieve an error when I run my code. ( on my PC). It states "Bad argument #2 to 'blit' <image expected, got table>
Here is my code. If you could pleases help me fix it I would be very grateful....
THNX :)
arrow = Image.load("arrow.png")
grass = Image.load("grass.png")
screenwidth = 480 - arrow:width()
screenheight = 272 - arrow:width()
arrow = {}
arrow[1] = { x = 200, y = 50}
--***** Main Loop *****
while true do
pad = Controls.read()
screen:clear()
for a = 0, 14 do
for b = 0,8 do
screen:blit(32 * a, 32 * b, grass)
end
end
screen:blit(300,220,arrow)
if pad:left() and arrow[1].x > 0 then
arrow[1].x = arrow[1].x - 2
end
if pad:right() and arrow[1].x < screenwidth then
arrow[1].x = arrow[1].x + 2
end
if pad:up() and arrow[1].y > 0 then
arrow[1].y = arrow[1].y - 2
end
if pad:down() and arrow[1].y < screenheight then
arrow[1].y = arrow[1].y + 2
end
screen.waitVblankStart()
screen.flip()
end |
|
| Back to top |
|
 |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Tue May 16, 2006 1:27 pm Post subject: |
|
|
| Code: | arrow = Image.load("arrow.png")
grass = Image.load("grass.png")
screenwidth = 480 - arrow:width()
screenheight = 272 - arrow:width()
arrow = {}
arrow[1] = { x = 200, y = 50}
...
|
You had defined 'arrow' variable twice. The first definition was an image and the second was a table. That's why you got an error. _________________ Geo Massar
Retired Engineer |
|
| Back to top |
|
 |
Gary13579
Joined: 15 Aug 2005 Posts: 93
|
Posted: Tue May 16, 2006 1:31 pm Post subject: |
|
|
| Ack, you beat me too it. I had my post done with color coding and everything :( |
|
| Back to top |
|
 |
daurnimator

Joined: 11 Dec 2005 Posts: 38 Location: melbourne, australia
|
Posted: Tue May 16, 2006 9:27 pm Post subject: |
|
|
| your all too quick for me :S |
|
| Back to top |
|
 |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Tue May 16, 2006 11:29 pm Post subject: |
|
|
| daurnimator wrote: | | Ack, you beat me too it. I had my post done with color coding and everything :( |
Why don't you just post your colorful reply, anyway? We all are curious to see yours. _________________ Geo Massar
Retired Engineer |
|
| Back to top |
|
 |
Gary13579
Joined: 15 Aug 2005 Posts: 93
|
Posted: Wed May 17, 2006 5:56 am Post subject: Re: Help with screen:blit... |
|
|
| Quote: |
arrow = Image.load("arrow.png")
grass = Image.load("grass.png")
screenwidth = 480 - arrow:width()
screenheight = 272 - arrow:width()
arrow = {}
arrow[1] = { x = 200, y = 50}
--***** Main Loop *****
while true do
pad = Controls.read()
screen:clear()
for a = 0, 14 do
for b = 0,8 do
screen:blit(32 * a, 32 * b, grass)
end
end
screen:blit(300,220,arrow)
if pad:left() and arrow[1].x > 0 then
arrow[1].x = arrow[1].x - 2
end
if pad:right() and arrow[1].x < screenwidth then
[color=red]arrow[1].x = arrow[1].x + 2
end
if pad:up() and arrow[1].y > 0 then
arrow[1].y = arrow[1].y - 2
end
if pad:down() and arrow[1].y < screenheight then
arrow[1].y = arrow[1].y + 2
end
screen.waitVblankStart()
screen.flip()
end |
Pretty much just replace the blue words with "arrowImg".
BTW, you screwed your quote tag up. It says daurnimator wrote that, when it was me.. |
|
| Back to top |
|
 |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Wed May 17, 2006 6:28 am Post subject: |
|
|
Sorry, dude!
BTW, nice looking, indeed. :) _________________ Geo Massar
Retired Engineer |
|
| Back to top |
|
 |
|