Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Something weird with sprite positioning...
Started by mike470 Jul 09 2012 03:33 PM

3 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

mike470

[GLOBAL: userInfoPane.html]
mike470
  • Contributor

  • 327 posts
  • Corona SDK

I am getting some weird results, can someone explain this to me?

I have three sprites - clouds. Here is the .lua table from TexturePacker:
			{
				name = "cloudbig.png",
				spriteColorRect = { x = 0, y = 0, width = 352, height = 96 },
				textureRect = { x = 2, y = 2, width = 352, height = 96 },
				spriteSourceSize = { width = 352, height = 96 },
				spriteTrimmed = false,
				textureRotated = false
			},
			{
				name = "cloudmed.png",
				spriteColorRect = { x = 2, y = 1, width = 254, height = 68 },
				textureRect = { x = 2, y = 780, width = 254, height = 68 },
				spriteSourceSize = { width = 256, height = 72 },
				spriteTrimmed = true,
				textureRotated = false
			},
			{
				name = "cloudsmallpng.png",
				spriteColorRect = { x = 0, y = 5, width = 120, height = 58 },
				textureRect = { x = 902, y = 606, width = 120, height = 58 },
				spriteSourceSize = { width = 120, height = 64 },
				spriteTrimmed = true,
				textureRotated = false
			},
===========================================================
Here is the sample code for display:
===========================================================
local SheetData = require("stuff").getSpriteSheetData()
local Sheet = sprite.newSpriteSheetFromData( "stuff.png", SheetData )

local Set = sprite.newSpriteSet(Sheet, 1,35)

sprite.add( Set, "CloudBig", 1,1, 10000, 0)							-- clouds
sprite.add( Set, "CloudMed", 2,1, 10000, 0)							-- clouds
sprite.add( Set, "CloudSmall", 3,1, 10000, 0)							-- clouds

C1=sprite.newSprite(Set)
C1:prepare("CloudBig")
C1:play()
C1:setReferencePoint(display.TopLeftReferencePoint)
C1.x=0
C1.y=100

C2=sprite.newSprite(Set)
C2:prepare("CloudMed")
C2:play()
C2:setReferencePoint(display.TopLeftReferencePoint)
C2.x=0
C2.y=200

C3=sprite.newSprite(Set)
C3:prepare("CloudSmall")
C3:play()
C3:setReferencePoint(display.TopLeftReferencePoint)
C3.x=0
C3.y=300

And here is the (weird, at least to me) result:

http://i49.photobucket.com/albums/f259/bigbadterr/Image3-1.png

As you can see from the .lua table, the widths are NOT the same. The clouds are saved autosized - so they don't have empty spaces to the side. WHY in the world are they showing up like this and not aligned to the left as I would have expected them to?
uid: 160496 topic_id: 28469 reply_id: 328469


[TOPIC: post.html]
#2

krystian6

[GLOBAL: userInfoPane.html]
krystian6
  • Contributor

  • 560 posts
  • Corona SDK

The alignment in Corona is a tricky thing.
I have discovered, that you have to add element to the group, and you have to do that prior setting x and y AND prior changing alignment.
The correct [at least it works for us] order is:
- create display object
- add it to the group
- set the reference point
- set X and Y

If you change the order and first set X and Y and then set reference point, you will not have your object aligned.
Also, note, that for text objects you will have to change reference point and set coordinates every time you modify text.
uid: 109453 topic_id: 28469 reply_id: 114999


[TOPIC: post.html]
#3

jkrassman

[GLOBAL: userInfoPane.html]
jkrassman
  • Contributor

  • 573 posts
  • Corona SDK

Thats strange, try printing out the width and height of the sprites, that could give you a clue on whats going on.

It looks like they are centered and not left aligned. But there could be some whitespace around them maybe? Could be some problems with your sprite sheet maybe?

Joakim
uid: 81188 topic_id: 28469 reply_id: 115001


[TOPIC: post.html]
#4

mike470

[GLOBAL: userInfoPane.html]
mike470
  • Contributor

  • 327 posts
  • Corona SDK

Found a way to fix this - before setting x and y, set currentFrame to 1

Kludge but works
uid: 160496 topic_id: 28469 reply_id: 115078



[topic_controls]
[/topic_controls]