You should make it so that it sets the destination to the edge of the screen as opposed to + 20 or whatever. That way it will keep moving smoothly. Then to stop character you add stop character action part to the release key.
Did you know that in 4.x that you can query the width & height of a sprite? This means that you can return the exact size of each scene, which would give you the right & bottom coordinate values. Left & top would both be 0.
Here's a quick function for defining the size of the scene into a global variable...
1. add this as a definition script to the script tab.
local pos, swh -- empty variables
-- * function which stores scene width & height into the swh variable * --
function getSceneSize()
swh = getObject("Game.GameCurrentScene.SceneSprite"):getSprite(VSpriteSprite):getSize()
end
-- * function which sets character destination (1 = left, 2 = right, 3 = up, 4 = down) * --
function moveChar(i)
pos = game.CurrentCharacter.Position
-- + --
if i == 1 then game.CurrentCharacter.Destination = { x = 0, y = pos.y }
elseif i == 2 then game.CurrentCharacter.Destination = { x = swh.x, y = pos.y }
elseif i == 3 then game.CurrentCharacter.Destination = { x = pos.x, y = 0 }
elseif i == 4 then game.CurrentCharacter.Destination = { x = pos.x, y = swh.y }
end
end
2. to update the current scene size variable, create an execute a script action part containing... (
this should only be called once at the beginning of each playable scene)
3. to move character, create an execute a script action part containing...
moveChar(1) -- replace 1 with direction you want to move in. (1 = left, 2 = right, 3 = up, 4 = down).
I have no idea if it will work or not.
P.S: I recommend adding a short pause to the key pressed actions - something like 50 to 100ms because key pressed acts like the turbo function on a gamepad, as in it constantly loops through the actions really fast while the key is pressed which is not necessarily a good thing.