Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Image sheet images displayed differently depending on position.
Started by Divergent Monkey Nov 25 2019 01:41 PM

- - - - -
13 replies to this topic
image sheet rendering
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 353 posts
  • Corona SDK

Look at the attached project. It contains an image sheet that is displayed on the screen. The strange thing is that for some y positions, there is an artefact around the upper and lower edges of the image.

 

Try e.g. y= 100, y=110 and y=120 (or some other values if those don't work for you) to see the difference. In other words, the rendering of the image is different depending on the position of the image.

 

Is this a bug? 



[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 721 posts
  • Corona SDK

I'm not seeing any attachment



[TOPIC: post.html]
#3

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 353 posts
  • Corona SDK

Sorry, please see it attached to this post...

Attached Files

  • Attached File  test.zip   5.87KB   16 downloads


[TOPIC: post.html]
#4

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 353 posts
  • Corona SDK

Has anyone got any ideas? As you can see from my example, it's just a plain wigdet so I guess others must have experienced this also...



[TOPIC: post.html]
#5

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,117 posts
  • Corona SDK

Looks to me like you've clipped / defined the sheet incorrectly, HOWEVER, I may not be seeing the same thing as you are. The best steps to take in these kind of situations is to also provide screenshots of the issue so that you know that everyone is seeing the same issue that you are, because your issue may only be present on some specific devices, etc. and not just depending on the y-axis.



[TOPIC: post.html]
#6

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 353 posts
  • Corona SDK

I also thought it had to do with the definition of the image sheet, but when I tried to correct it I realized that for some positions, the image was displayed correctly.

 

Please see the three attached screenshots. I've named them according to the y position of the image. The artefacts are most visible below the dark grey area to the left.

Attached Thumbnails

  • y110.png
  • y114.png
  • y140.png


[TOPIC: post.html]
#7

firemaplegames

[GLOBAL: userInfoPane.html]
firemaplegames
  • Contributor

  • 179 posts
  • Corona SDK

I had that issue when my game was scaled on different devices.

 

I had tons of image sheet animations in the game. They worked flawlessly on the simulator, on an iPhone X, on an iPhone 5, etc, but the positions were off by a fraction of a pixel on the iPhone6, and some of the iPads.

And I assume a bunch of Android sizes I don't have access to.

 

But that fraction of a sub pixel was really noticeable. The image sheets appeared to stutter and shake. It looked terrible.

 

I also use image sheets for button states, and different things throughout the game that are static. I assume the issue is happening there as well but it isn't noticeable. Those buttons and things are always .png images with enough of a transparent bleed around them so I wasn't getting any artifacts.

 

For the animations though I had to revert back to a method I used before image sheets were even in Corona - an old MovieClip library which loaded each image individually.

 

It got rid of the positioning problems but those scenes where the animations were needed to load for a second or two on older devices which made the game seem sluggish.

 

You might just need to remake those graphics old school, with a stack of images and turn their alpha on and off when necessary.

 

Good luck!

Joe



[TOPIC: post.html]
#8

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,117 posts
  • Corona SDK

Yeah, Joe put it really well.

I've run into similar issues often. I am guessing that it has something to do with Corona's scaling. For instance, if you were to design your app using Corona's default 480x320 and you then created all of your assets according to that, then I doubt you'd experience any issues on that particular resolution.

 

However, once the resolution or aspect ratio begins to change, then you'll get these oddities popping up at weird places. I'm not really sure about this, but it may have something to do with Corona attempting to render half pixels, e.g. in some cases a 48 pixels tall image would scale to 47.5 or 48.5 (or some fraction of a pixel), but such a value can't obviously be rendered, and I guess that these issues cause those artifacts.



[TOPIC: post.html]
#9

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 353 posts
  • Corona SDK

@Joe & XeduR: thanks for your answers. One thing I do to prevent decimal sizes or positions due to scaling is to use math.floor() every time the position of a display object is a calculated value or a variable. I don't know if that is why scaling has never been a problem. The only time I can actually see artifacts is when I take a screenshot and enlarge the image. 

 

Here is the interesting thing: if you just display the png file as a regular image (i.e. not in a slider widget), then there are never any artefacts, regardless of the position. In other words: this seems to be something caused by the slider widget. 

 

The image in question is used in a slider widget as a sound volume control. I guess I could manually create a slider itself, but is seems like a clumsy workaround.

 

Can someone from Corona staff shed some light on how images are handled when being part of a slider widget? What is "done" with the images that could cause this? 



[TOPIC: post.html]
#10

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,544 posts
  • Enterprise

I don't believe there is any light to shed on this. It's likely sub-pixel rendering. I looked at the image sheet and my measurements of the images didn't quite match what you said, but maybe you could maybe fill in another row or two of pixels both on the top and bottom and not have the hard-green-to-white edge be part of the image.

 

The widget source is available on GitHub: https://github.com/coronalabs/framework-widget

 

It's open source. You can download it and make any changes you need to it.

 

I don't believe we are doing any magic in the widget code other than using an imagesheet.

 

Rob



[TOPIC: post.html]
#11

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 353 posts
  • Corona SDK

I tried to set the frame height to the entire image height, which means that there are 27 extra (empty) pixels on both sides top and bottom. Still the same artefacts. Therefore, I don't think it has to do with a lack of extra pixels. Also, I'm thinking that if it really was the height of the frames that caused the problems, then the positioning of the image would not matter, right?
 
ALTERNATIVE 1. 
When I display the image as it is:
 
local image = display.newImageRect("audiosliderimagesheet.png", 170, 70)
image.x = 300
image.y = 140  
 
there are never any problems with artefacts, regardless of the position of the image.
 
 
ALTERNATIVE 2:
When I display it as individual images from the sheet:
 
local frame1 = display.newImage( sliderSheet, 1 )
frame1.x = 100
frame1.y = 500
local frame2 = display.newImage( sliderSheet, 2 )
frame2.x = 150
frame2.y = 500
local frame3 = display.newImage( sliderSheet, 3 )
frame3.x = 200
frame3.y = 500
local frame4 = display.newImage( sliderSheet, 4 )
frame4.x = 250
frame4.y = 500
local frame5 = display.newImage( sliderSheet, 5 )
frame5.x = 300
frame5.y = 500
there are also no problems with artefacts.
 
In other words, it is not the image or the image sheet definition itself that is causing it, but something when it is used in the slider widget.


[TOPIC: post.html]
#12

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 353 posts
  • Corona SDK

Is there anyone who has any input on this? 

 

@Corona staff: please see my previous post. As you can see, the artefacts do not appear when the image is displayed as a "regular image" or as an image sheet. The artefacts ONLY appear when displayed as part if a slider widget. If you use my examples above, you can easily reproduce my findings and you will see that it has to be something in the widget causing this.

 

EDIT: the fact that other users have experienced the same thing also suggests that it is not simply a question of configurating the image sheet wrong. 



[TOPIC: post.html]
#13

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,544 posts
  • Enterprise

First, here is the source for the widget:  It's just Corona Lua, so anyone who wants to look at the code and try and figure this out is more than welcome to:  https://github.com/coronalabs/framework-widget/blob/master/widgetLibrary/widget_slider.lua

 

I don't see any reason why this happening. What I see is that it's either a. making the end cap too small or b. making the fill bar too large. As a test, I colored the fill bar red. 

 

Here is the result:

Screen Shot 2019-12-09 at 9.02.23 PM.png

 

I don't see any artifacts in the red. What I see is the left end cap and fill are different heights.

 

What I don't see is why this is happening. As I said, there isn't any magic going on. I thought it might be a rounding issue and drying to draw on a half-pixel. But the height is even, so that shouldn't be the cause.

 

I'll keep looking. But I don't think this is an under the hood graphics issue.

 

Rob



[TOPIC: post.html]
#14

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 353 posts
  • Corona SDK

@Rob: when you colored the fill bar red, the artefact is visible in the form of a solid colored "extra height", that's very interesting. But I still don't understand  why this happens. As you also said: the cap and the bar heights are identical in the image sheet, and yet they are displayed differently.

 

I'd like to emphasize that if you display the image as separate images from the image sheet (see "ALTERNATIVE 2" in my previous post), no artifacts are visible at all. The only conclusion I can draw from that is that it *HAS* to be a result of the widget. I understand that there is no strange stuff done with the image sheet in the widget but the fact remains, that is the only place where the artefacts are visible. I have looked at the widget code but I cannot see what may be causing this. 

 

Has anyone got any ideas?




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: image sheet, rendering