App Programming‎ > ‎

ActionGame_Android

Now that you have an action game, if you want to put it on your Android, some changes have to be made.

Sizing it to your Cellphone Screen
First is the screen size. Since there are so many screen sizes, LiveCode has a function to adjust the stack/card size to the device it is running on.

Add the following code to your "Stack Script"
(On the LiveCode Editbar, click on ""Object", then click on "Stack Script" and paste the following handler:

on preOpenStack 
   if the environment is "mobile" then 
      set the fullscreenmode of me to "exactFit" 
      set the acceleratedrendering of me to true 
   end if 
end preOpenStack


Adding new Controls (Arrow Keys)
Cell phones do not usually have separate arrow keys, much less keyboards. So we have to add arrow keys on the screen.

e.g.
                              

We can use some of the code from the card script:

On the card, we had for the "UP" arrow key:
on arrowkey x
   if x is "up" then
      set the top of btn "box" to the top of btn "box" - 10
      if top of btn "box" < the top of the card "mycard" then
         set the top of btn "box" to the top of the card "mycard"
      end if
   end if

leave that there but copy and paste the code into the button script:

on mouseDown
   set the top of btn "box" to the top of btn "box" - 20
   if top of btn "box" < the top of the card "mycard" then
      set the top of btn "box" to the top of the card "mycard"
   end if
   ckfin
end mouseDown

Then below that add the "on mouseStillDown" message and paste it in there too
 ( so that you can hold down the "up" key and the player will keep moving:

on mouseStillDown

   set the top of btn "box" to the top of btn "box" - 20
   if top of btn "box" < the top of the card "mycard" then
      set the top of btn "box" to the top of the card "mycard"
   end if
   ckfin

end mouseStillDown

So now it looks like this:

          

Now do the same for the other keys....

note: I got tired typing, so I created another message "ckfin" (to check if I crossed the finish line after I moved) So I put the code in a message "ckfin", put it on the card script and call it from every key that moves the player.

Add that code to the card script (see below)

Add the following message handler to the Card Script for the finish Line

on ckfin
   if intersect (btn "box" , btn "Finish Line") then
      global gameOn
      put false into gameOn
      move button "box" to 149,273
      go to card "mycard2"
   end if
end ckfin

Going to Another Level
When you go to another level, you need to stop the current level ("put false into gameOn" or whatever you called your variable/flag).
Add the following message handler to the Card Script for the finish Line

on ckfin
   if intersect (btn "box" , btn "Finish Line") then
      global gameOn
      put false into gameOn
      move button "box" to 149,273
      go to card "mycard2"
   end if
end ckfin

Comments