Is there a way to programatically check if #2x images are being used? - coronasdk

I have a calculation that depends on the frame size in a sprite sheet and this currently breaks when #2x images are used. So i need to tweak the calculation to adjust for #2x.

You can check the image suffix you are using with:
local imageSuffix = display.imageSuffix
print( imageSuffix )
Check this link in Corona docs

Check this one. Do you use any sprite creator in creating your sprites? because basically you can adjust its size prior to creating the sprites. Im using Texture Packer. It never fails me.

Related

Arcore: How can I get the dimensions of an image that I placed on the surface?

I have placed an image on a surface and I am trying to display the height and width of the image when I tap on it (having an idea to select and resize later).
I am converting the TransformableNode to an imageView and then using getHeight() and getWidth(). but is there a simple way provided by ARCOre?
Thanks in advance.
i have created a project like Google measure App where I am scaling the node placed and then getting its size. Here is the link: Object Measurement

Texture Atlas in Sprite Kit not working

I am getting very frustrated with XCode today. I already looked at the answer to this question: Sprite Atlas and #2x images but, that answer did not work.
So, here's the problem:
-I have a sprite in XCode with dimensions 178x50, and in my code, I load [SKSpriteNode spriteNodeWithImageNamed:#"image"]; and that code runs just fine. My image is named "image#2x.png" and is in my project.
So today, I wanted to animate it. I made the files, named "default01.png, default02.png .... default10.png", and put them in a folder with .atlas extension. Dragged into my project, added them, changed my line of code to [SKSpriteNode spriteNodeWithImageNamed:#"default01"]; Just to make sure everything was working. Loaded up the game, and the sprite was displayed much larger than normal. Doh, forgot to add the #2x suffixes. So, I went through and added them... same problem continued. I saw the above answer on this site, so I deleted the atlas, made a new one with the #2x suffixes already added, and THEN added that one to the project. Still same problem!
In my element inspector (I believe that's what it's called), I can see that the dimensions for the two images are literally exactly the same. They look identical. They both have #2x suffixes. Yet loading from the atlas displays the image at a much larger size.
No idea what to do.
So if you're using a texture atlas, a folder ending with .atlas to hold the images, you should use the texture method not the image method.
Also, you need to explicitly set the size of the sprite at the size you want or it will interpret the size from the image size.

obj-c images resizing automatically...?

I just started learning obj-c the other day and i'm putting together a crappy game as practice. I have an IMG as a main character to the game and every time this character hits certain obstacles, i wanted the size of the image to change (decrease or increase depending on the circumstance).
I used photoshop the change the size of the images to the appropriate sizes but for some reason, when i run the game, the images change when i want them too, but they are way smaller than the size i set them to in photoshop......
any ideas?
i don't think its necessary to post my code for something as simple as this, right? its just a simple "if" statement followed by the instance and the UIimage named for the image name...
I assume you display the image in an UIImageView? Or do you use SpriteKit? If you use an UIImageView the image is actually automatically scaled to the size of the UIImageView.
Therefore you would just change the size of the UIImageView (you can of course also change the image inside the UIImageView.
If you are using SpriteKit, you have to remember, that your are probably testing on a 'retina' device and for this reason the image's width and height is divided by 2 (the real resolution of the current iPhone 5/5s is 1136x640 and not 568x320 !

How to get rid of empty transparent areas in a PNG image so that it conforms to actual image size?

I have a series of images that I would look to loop through using iOS's [UIView startAnimating]. My trouble is that, when I exported the images, they all came standard in a 240x160 size, although only 50x50 contains the actual image, the rest being transparent parts that are just taking up space.
When I set the frame of the image automatically using image.size.width and image.size.height, iOS takes into images' original size of 240x160, so I am unable to get a frame that conforms to the actual parts of the image. I was wondering if there is a way using Illustrator or Photoshop, or any other graphics editing software for me to export the images based on their natural dimensions, and not a fixed dimension. Thanks!
I am a fan of vector graphics and thinks everything in the world should be vector ;-) so here is what you do in illustrator: file - document setup - edit artboards. Then click on the image, and the artboard should adjust to the exact size. You can of course have multiple artboards, or simply operate with one artboard and however-many images.

How to update an app comprised entirely of images for the iPhone 5

I need to update an app which was written for the iPhone 4 screen size to work on the iPhone 5. I have read on SO about AutoLayout and so on, but the problem is that each screen in this app is made up of a background image, which then has touchable areas and such drawn on in code. These are positioned absolutely. This isn't the way I would have designed the app, but it's the task I am faced with.
I have two problems to solve:
1) How do I load the correct background image. Do I need to create a separate image size for each and them in code query the device size each time an image is loaded? To give some context, there are well over 100 images.
2) How do I maintain the touchable areas. Is it best to just add the required number of pixels to the bottom of the app? Would this then work, or will I need to query device size and change coords accordingly every time I draw something?
Thank you,
Sam
Autolayout will work in the device is running iOS 6 or higer.
1) Yes you will need a image larger image for all the images in your app. You could overload some methods in a base class to make this more easy to load the correct image.
An other option is to stretch the image, but this is up to you.
2) I would adjust my coordinates to the size of the device.
If Apple would add an other screen size you will run in the same problem again. You should try and create an interface that can grow with the screen.

Resources