Author Topic: The picture refuses to move  (Read 6877 times)

0 Members and 3 Guests are viewing this topic.

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
The picture refuses to move
« on: September 04, 2012, 11:04:26 am »
The code is:

platform.apilevel = '1.0'
Person = image.new("\012\000\000\000\024\000\000\000\000\000\000\000\024\000\000\000\016\000\001\000\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128 \225\160\253 \225\160\253 \225\160\253 \225\160\253 \225\160\253\000\128\000\128\160\253 \225\160\253 \225\160\253 \225\160\253 \225\160\253 \225\000\128\000\128 \225\160\253 \225\160\253 \225\160\253 \225\160\253 \225\160\253\000\128\000\128\160\253\000\128\160\253\000\128\000\128\000\128\000\128 \225\000\128 \225\000\128\000\128\000\128\208\254\000\128\208\254\208\254\208\254\208\254\000\128\208\254\000\128\000\128\000\128\208\254\208\254\208\254\000\128\208\254\208\254\000\128\208\254\208\254\208\254\000\128\000\128\208\254\208\254\208\254\000\128\208\254\208\254\000\128\208\254\208\254\208\254\000\128\000\128\208\254\208\254\208\254\208\254\208\254\208\254\208\254\208\254\208\254\208\254\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\224\145\224\145\224\145\224\145\224\145\224\145\224\145\224\145\224\145\224\145\000\128\000\128\224\145\224\145\000\128\224\145\224\145\224\145\224\145\000\128\224\145\224\145\000\128\000\128\224\145\224\145\000\128\224\145\224\145\224\145\224\145\000\128\224\145\224\145\000\128\000\128\224\145\224\145\000\128\224\145\224\145\224\145\224\145\000\128\224\145\224\145\000\128\000\128\000\128\000\128\000\128\224\145\224\145\224\145\224\145\000\128\000\128\000\128\000\128\000\128\208\254\208\254\000\128\224\145\224\145\224\145\224\145\000\128\208\254\208\254\000\128\000\128\208\254\208\254\000\128\224\145\224\145\224\145\224\145\000\128\208\254\208\254\000\128\000\128\000\128\000\128\000\128\224\145\000\128\000\128\224\145\000\128\000\128\000\128\000\128\255\255\255\255\000\128O\128O\128\000\128\000\128O\128O\128\000\128\255\127\255\127\255\255\255\255\000\128O\128O\128\000\128\000\128O\128O\128\000\128\255\127\255\127\000\128\000\128\000\128\000\128O\128\000\128\000\128O\128\000\128\000\128\000\128\000\128\000\128\000\188\000\188\000\188\000\188\000\128\000\128\000\188\000\188\000\188\000\188\000\128\000\128\000\188\000\188\000\188\000\188\000\128\000\128\000\188\000\188\000\188\000\188\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128")

x = 1
y = 1

function on.arrowUp()
y = y-1
end

function on.arrowDown()
y = y+1
end

function on.arrowRight()
x = x+1
end

function on.arrowLeft()
x = x+1
end

function on.timer()
platform.window:invalidate()
end

function on.paint(gc)
   gc:drawImage(Person, x, y)
   platform.window:invalidate()
end

The person won't move until I click the middle of the screen. The program works fine on the PC. I am running on 3.1 and using 3.2 pc software. Any ideas on why it won't work?
« Last Edit: September 04, 2012, 11:10:40 am by Augs »

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: The picture refuses to move
« Reply #1 on: September 04, 2012, 11:51:38 am »
The reason is simple :
- On the computer, everytime you *do* something ( move the mouse, etc. ), the screen gets refreshed.
- On the handheld, platform.window:invalidate() has to be called. You wanted that by calling it in [lua]on.timer[/lua], but you forgot to do  [lua]timer.start[/lua](0.01)  to actually start the timer.

Instead of doing that, you could simply put the invalidate at the end of the arrow functions. (Btw, you can also use [lua]on.arrowKey[/lua](arrow) (arrow=="left" etc.)

Also, don't put platform.window:invalidate() inside of on.paint, it's useless.
« Last Edit: September 04, 2012, 11:55:50 am by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
Re: The picture refuses to move
« Reply #2 on: September 04, 2012, 11:59:56 am »
The reason is simple :
- On the computer, everytime you *do* something ( move the mouse, etc. ), the screen gets refreshed.
- On the handheld, platform.window:invalidate() has to be called. You wanted that by calling it in [lua]on.timer[/lua], but you forgot to do  [lua]timer.start[/lua](0.01)  to actually start the timer.

Instead of doing that, you could simply put the invalidate at the end of the arrow functions. (Btw, you can also use [lua]on.arrowKey[/lua](arrow) (arrow=="left" etc.)

Also, don't put platform.window:invalidate() inside of on.paint, it's useless.

Why thanks, as you know I am new to this. Since you introduced me last night.
Thanks, it worked.
« Last Edit: September 04, 2012, 12:01:58 pm by Augs »

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: The picture refuses to move
« Reply #3 on: September 04, 2012, 12:00:54 pm »
np.
So did you make it work ? :)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Augs

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 306
  • Rating: +30/-29
    • View Profile
Re: The picture refuses to move
« Reply #4 on: September 04, 2012, 12:30:31 pm »
np.
So did you make it work ? :)

Yes, This is one of many problems I will have during the making of my rpg