I'm new to Corona SDK development and I'm looking around to get some documentations and see if this platform is goot to reach my goal.
Let's say that I have a background image in my screen (320X480 for example), and I want to move an object from one point to another. For example I want to move an object from 100,100 to 300,300. In this case, my object follow a line that almost covers the entire width of my screen. But what happens when I run the app on a different screen resolution? For example on a Ful HD screen, moving an object from 100 to 300 on the X axis, it just moves a little.
What I saw from Corona documentations is that multiple screen is supported by providing different image resolutions. But what happens when I have to go through screen coordinates? Do I have to check at runtime for the screen resolution and do all the Math operations to scale my points coordinates? Or is there anything else that I'm missing?
I ask you sorry if I missed something from the doc :(
Usually corona will do all such work for you, if you have added proper config.lua to your project. But I'm doing it in a different way for more precision and for my satisfaction:
In normal case:
-- Your object at point (100,100)
local myObject = display.newRect(0,0,50,50)
myObject.x = 100
myObject.y = 100
-- sample transition
transition.to(myObject,{time=1000,x=300,y=300})
What I'm doing:
-- Create a scale factor for X and Y
local _x = display.contentWidth/320
local _y = display.contentHeight/480
-- Multiply X values with '_x' and Y values with '_y', as below:
local myObject = display.newRect(0,0,50*_x,50*_y)
myObject.x = 100*_x
myObject.y = 100*_y
transition.to(myObject,{time=1000,x=300*_x,y=300*_y})
Note:
While trying the above code, you have to develop your code for iPhone simulator. Hence, I obtained local _x = display.contentWidth/320, where the division factor is the width of the simulator/screen that you are using to build your app. And in local _y = display.contentHeight/480, the division factor is the height of the simulator/screen.
Keep Coding................. :)
It scales it all for you. I'm not sure if it specifically mentions it in the documentation, probably.
I am also newer to Corona (since July) with no previous mobile experience. It has blown me away with what it can do.
Corona does all the work for you. You define your default screen resolution (320x480 for example) and in whatever resolution you want to move from 100 to 300 it will behave equally because corona will treat all screens resolutions as it was 320x480.
Related
I'm trying to use Kudan AR in a project, and I have a couple questions:
1) The marker size relation to the scene seems pretty weird to me. For example, I'm using a 150x150 px image as a marker, and when I use it in the scene it occupies 150 unities! It requires all my objects to be extremely huge, sometimes even extending further than the camera far plane, which breaks the augmentation. Is it correct, or am I missing something?
2) I'm trying to use a marker to define the starter position of the augmentation, and then switch to the markerless tracking to have a broader experience. They have a sample code using the native iOS lib (https://wiki.kudan.eu/Marker_to_Markerless), but no reference on how to do it in Unity. That's what I'm trying:
markerlessDriver.localScale = new Vector3(markerDriver.localScale.x, markerDriver.localScale.x, markerDriver.localScale.z);
markerlessDriver.localPosition = markerDriver.localPosition;
markerlessDriver.localRotation = markerDriver.localRotation;
target.SetParent(markerlessDriver);
tracker.ChangeTrackingMethod(markerlessTracking);
// from the floor placer.
Vector3 floorPosition; // The current position in 3D space of the floor
Quaternion floorOrientation; // The current orientation of the floor in 3D space, relative to the device
tracker.FloorPlaceGetPose(out floorPosition, out floorOrientation);
tracker.ArbiTrackStart(floorPosition, floorOrientation);
It switches, but the position/rotation of the model goes off. Any idea on how that can be done?
Thanks in advance!
displaycontent = display.newImageRect (rawdata[currentpath][3], screenW*1.1, ((screenW*1.1/1654)*rawdata[currentpath][6]))
displaycontent.anchorY = 0
displaycontent.y = screenH*0.78
My program loads an image from a database to be displayed on the mobile phone's screen, everything works correctly apart from being able to position it with the y coordinates.
The only thing that changes its position is the anchor point 0 puts the top of the image in the centre of the screen, and values from 0.1 - 1 all position it higher. Changing the y position via object.y has zero effect regardless of what I set it as.
(the size settings probably look a bit weird in the first line, but this is because the images are different sizes and need to show the correct proportions on different screen types).
Btw I am using a tabbar widget as the UI (in case that is relevant)
Any help would be appreciated.
Edit: I am aware that displaycontent is bad name for a variable because of its similarity to things like display.contentCenterY for example, this will be changed to prevent any confusion when I look over the code in future.
I went through my code and tried disabling sections to find the culprit and a content mask was preventing me from setting the position of the loaded images within it.
I will look over my masking code and fix it (should be straight forward now I know where the problem started).
If anyone else has a similar problem (where an image or object wont position itself on given coordinates) check your content mask as that may be the issue!
I'm trying to make a tilemap-based game using cocos2d 2.1 and Tiled 0.9.1. The game runs perfectly on the simulator, but I have gaps (artifact lines) between the tiles when running on the device.
Please see the screenshot.
The diff is the difference (made in photoshop) between the original tile (taken straight from the png of the tileset) and the tile as rendered by cocos2d. As you can see, in simulator they are 100% identical. However, on the device it seems that cocos2d shrinks the tile texture vertically by just a little bit. The 1 pixel stripe is actually the texture above the troublesome tile in the tileset.
Any idea what caused this and how to fix it?
While using this answer In my case enabling CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL was not enough.
I also added the following code to AppDelegate::applicationDidFinishLaunching() function and rounded values passed to setPosition(x, y) function to nearest int.
Director::getInstance()->setProjection(Director::Projection::_2D);
I use cocos2d-x 3.4.
Not certain why this happens on devices only, but you should read in ccConfig.h for parameter CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL. This in itself is a bad kludge, but it gives you a hint as to where to look.
Basically, you should make certain that all your positions are on an exact pixel boundary, ie on non-retina devices cast them to int, and on retina devices round to the nearest exact multiple of .5. Best way to ensure that is to make all your textures w,h even numbers ... the onus is on the artist for anything that will not move. If you move things, and the final position is calculated (for example in a ccTouches move,end), make certain you do this rounding there. Beware of batch nodes : the node itself, and all its children should be on pel boundary.
I am working on a iOS Game Application (Race) which requires the background to have transition coming forward.
For the above requirement I have written a code where I have to make people feel as if the objects were coming from a far distance to nearby.
Hence I am using transition to do so where I increase their y position and scaling (both xScale and yScale). While doing so, the problem I am facing is when the objects seem to come closer with their size increasing (using scaling), the distance between the objects decreases from their actual distance because of scaling and it does not perfectly look as if the objects were coming from far behind.
Please let me know what is the best way to achieve what I trying to do or else if there is any available sample code having the functionality of car/bike racing.
transition.to ( object,{ time=500, alpha=1,x = (destination x coor),y = (destination y coor),width =(to scale x),height =( to scale y), onComplete=saltCellarOnComplete} )
I would think MyImagePicker.frame.center is where I should place the icon (subtract icon.size.width/2 and height /2., but when the picture actually saves, what I thought the cross hair is pointing at is not the middle of the image at all. X seems okay, but Y happens to be some distance off. I can approximate by trial and error, but I would like to be exact.
Help?
The frame actually defines the origin and dimensions of the view in the coordinate system of its superview and is commonly used during layout to adjust the size or position of the view as detailed here.
You most likely want to use MyImagePicker.bounds.size.width / 2 and MyImagePicker.bounds.size.height / 2 to get the actual center of your image picker.
I actually learned this recently by watching the Stanford lecture series on iOS 5 development on iTunes U.