[SOLVED]Sprite Image Stretch with Movement

[UPDATE] Someone tested it on an Android phone and reported that the flickering was hardly present So it looks like it might have just been a simulator problem.

Hi everyone,
If I have a sprite image and I move it to the right like so:

local function movement(e)  
sprite.x = sprite.x + 1  
end  
Runtime:addEventListener("enterFrame", movement)  

It’ll be fine and move the the right (or left or whichever)

But if I want a slightly faster speed, say 1.1, then the sprite image will start to gain an extra pixel width that starts to flicker.
Setting it up to speed +2, works fine again but that’s too fast.

The reason is obvious, because I’m moving the image by a fraction, which isn’t possible.
Although I don’t know how to solve this.

Is there a way to make the movement more sensitive, so I can slowing increase the speed?
How do running games move their characters at an curved speed without causing stretching.

Thanks for any help you can provide.
Yours Sincerely, Matt (???)? [import]uid: 91798 topic_id: 29547 reply_id: 329547[/import]

Is the flickering you see is on the device itself or on the simulator? [import]uid: 160496 topic_id: 29547 reply_id: 118596[/import]

Have you tried using the transtion.to () function?
Within this function you can define how fast it should move to the target position (which allows you to control the movement speed better - similar to what you were trying to archive with your “1.1” i guess)

http://docs.coronalabs.com/api/library/transition/index.html

[import]uid: 162464 topic_id: 29547 reply_id: 118622[/import]

Hmmm the flickering is strange. In the current game i’m making i alter the speed of my sprites loads of time using fractions and i’ve never had a problem…

Have you tried using “sprite:translate( 1.1, 0 )” etc instead?

Using translate is more efficient then calling the “x” value of your sprite every frame, so you should use that anyway :slight_smile: [import]uid: 69826 topic_id: 29547 reply_id: 118623[/import]

OOI are the dimensions odd or even? I haven’t seen this before but wonder if that could be a contributing factor. [import]uid: 52491 topic_id: 29547 reply_id: 118671[/import]

Hi again everyone,
Thanks for all your advice so far, Although I tried your methods I couldn’t solve it.
I find it hard to believe that you’ve never seen it before, I bet I didn’t explain very well is all.

So I made a video displaying the problem so it’s easier to understand.

http://youtu.be/Qo55tz9JXLI

@mike470 - The flickering is on the simulator, although I believe it presents itself on devices too.
I’m not entirely sure, I recall having the same issue on an older project that I tested on a phone.
I can test it and get back to you.

@Zwonkie - I tried transition.to but i couldn’t get it to work, My objects would just not move.
I did:

 local function moveMap(e)  
 transition.to(map, { time = 1100, x = map.x - 1.1})  
 end  
 Runtime:addEventListener( "enterFrame", moveMap )  

@TandG - I tried your method of gameHero:translate but got the same result as I got with my hero.x = hero.x method.
Although you’re likely right that your way is better so I’ve stuck to that anyway for the video.

@peach - The dimensions are a 40x40 tile. However an image may not take up all 40 pixels.
Although they usually end in really sharp lines (No half opacity lines).
Although the grass ‘walls’ are 40 pixels wide, but the dirt part of those walls are only 39 pixels wide.

Possibly the reason?
You can probably understand if I show you this.

Photobucket

I’m going to try and see what happens if I make the ‘dirt’ walls 40 pixels wide and get back to you.
*EDIT* That didn’t seem to work. I still get the extra pixel flickering, It must be due to the ‘fraction’ I’m moving the image by.

Thanks for your helps guys and gals.
Matt [import]uid: 91798 topic_id: 29547 reply_id: 118688[/import]

I think the flicker is the simulator artifact and you won’t see it on the device… [import]uid: 160496 topic_id: 29547 reply_id: 118689[/import]

This is an example of how to implement the transition.to code. but i tried at it doesnt work well, there is a small stop after each transition is over up until it starts again. I’ll give you the code anyway, maybe it will inspirer you to solve some other problems with this function.

local i = 1 --defines the next postion which transition should move the tagert to  
-- testing code --  
local function movement(e)  
 local listener = function( obj ) --this function is called when the transition.to is complete  
 moving = 0 --flags that the movement has stopped   
 i=i+1  
 end  
  
 if(moving == 0 ) then --if the target has stopped move it again  
 transition.to(map1, { time = 1100, x = (i\*100), y=0, onComplete=listener})   
 moving = 1 --flags that the target is moving, to prevent the transtion.to being called every frame  
 end  
end  
  
Runtime:addEventListener( "enterFrame", movement )  

I can see the flickering from your video. I hope the others are correct and that it only occurs in the simulation. But, since it looks like an interpolation/streching issue, you can try to enable anti-aliasing in the config.lua file. This might hide to issue, but will also take more processing power of the device :wink:

something like this:
application =
{
content =
{
width = 320,
height = 480,
scale = “zoomStretch”,
antialiasing = true, fps = 30
},

} [import]uid: 162464 topic_id: 29547 reply_id: 118703[/import]

Well I’m unsure of the cause still.
The only thing I’ve yet to try is to check whether this is, in fact, a simulator only artifact.

If I host the .apk somewhere would anyone be willing to have a look on their Android phone for the artifacts?
(I’m unsure if this is the correct place to ask such a question.)

I’ve made it so the character gets stopped by terrian & you can continually drag the scene backwards to continue looking.
(As there is no restart feature for a phone yet :P)

It’s built on the latest stable build (No dailys) Android 2.2.
If anyone agrees, just send an e-mail to thehivetyrant[at]msn[dot]com

And I’ll reply with a DropBox username & password so you can just log in online and transfer it to you PC. Or from your phone if you have the app.

Thanks in advance.
[import]uid: 91798 topic_id: 29547 reply_id: 118791[/import]

Another possible workaround is to substantially scale up your screen resolution settings in config.lua. If you have it set as the “default” of 320 x 480, you could notch it up to 3200 x 4800 (probably a bit extreme, but hear me out :wink: ). This would in theory provide you with 10x more fine-tuned movement.

Of course, not even the iPad3 HAS that pixel resolution, but all devices would squeeze that amount into their respective display… and from a programming standpoint, you’d get the tiny incremental movement capability.

What do you think? Worth a shot? :stuck_out_tongue:

Brent

[import]uid: 9747 topic_id: 29547 reply_id: 118824[/import]

You Crazy Fool, You’ll Kill Us All! =P

It sounds very weird, although I understand the logic behind it. Make everything bigger so 1 speed is Really Slow and every integer is only slightly faster instead of a leap faster.

I’ll look into it but it sounds like a crazy idea haha. [import]uid: 91798 topic_id: 29547 reply_id: 118874[/import]