AS3 Side Scroller Not exactly how I want it - actionscript-3

Im trying to create a side scroller game on actionscrip3.0. I have it down and everything but it's not exactly what I'm looking for. I want my character to always be in the center of the screen. (www.realmofthemadgod.com) Is a great example of what type of side scroller I want my game to be like. Any help would be greatly appreciated.

Your best bet and mine is to implement a world camera, as I call it, to your game.
Each of your game objects will have two sets of coordinates. One is in relation to the game world (world coords), the other in relation to the camera (screen coords).
World coords are for everything other than displaying. So stuff like physics. Screen coords are just for displaying.
Your camera will also need a set of world coords. It doesn't need screen coords because that doesn't make any sense.
In the end your objects' screen coords will just be the differences between theirs and the camera's world coords.
For example if your object is at (100, 100) and your camera is at (90, 90) then your object will look like it's at (10, 10). Object at (200, 200) and camera at (150, 250) will end up at (50, -50).
Keep in mind the origin point of your screen coords is the top left corner of your screen by default. If you want the origin to be the center of your screen, that is an object that is right on top of the camera should appear in the center of your screen, you must add half the width and half the height of your screen to your final screen coords.

Related

Image crop position with HTML5 Canvas

I have an image which is 640px by 480px and I have coordinates where I want to create a canvas crop of the image. I am a bit confused as to how to work out for 1, the crop size, where to crop and so on.
How would one work out the correct position to crop and the crop size? e.g. what size to set the canvas from coordinates such as the following
coordinates = [160, 593, 345, 407] // [top, right, bottom, left]
essentially im returning image coordinates from a Python script but no idea how to work out the correct positions.
The drawImage() method takes arguments for source and destination coordinates.
context.drawImage(imageObj, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight);

Libgdx Position camera in TiledMap

I have create a sample tile map like this, I am confused on how to show the camera on the center of the tilemap or in a specific position.
the output looks like this. how do I make the camera show the center of the tilemap also how do I make the image show smaller
The camera's position is always considered to be the center of the camera.
An uninitialized camera will point to (0,0) and show as much space to the top, bottom, left and right as the viewport allows.
You can set the position in the create method:
OrthographicCamera camera = new OrthographicCamera(width, height);
camera.position.set(camera.viewportWidth / 2f, camera.viewportHeight / 2f, 0);
camera.update();
Do not forget to call the update method after any changes or they will not be visible.
In order to show the camera in a specific position after creation you need to move the camera by calling
camera.translate(x,y,z);
To zoom in and out simply set the zoom:
camera.zoom = someFloat;
If this does not make sense i recommend researching more about the orthographic camera
(https://github.com/libgdx/libgdx/wiki/Orthographic-camera)
and viewports (https://github.com/libgdx/libgdx/wiki/Viewports).
If this does not help at all, because I misunderstood something, post more information plus some code and we will figure something out.

is there a way to zoom in the screen?

In a certain point when you want to see things closer, can you zoom in the whole screen without changing the games' levels and items' size and scale?
In an swf file, you can right click to zoom in, but I want the same feature for the game using code.
Thanks.
You can play with the scaleXand scaleY properties of the DisplayObject, which holds your graphic elements.
Assumed,holder contains your stuff:
holder.scaleX = holder.scaleY = 2;
will scale the holder and all its children to double size.

Away3D: How to resize an ObjectContainer3D instance

my question is: how can I resize an ObjectContainer3D instance (as it doesn't have "width", "height" and "depth" properties)?
Maybe you can use 'scaleX', 'scaleY', 'scaleZ', or 'scale'.
Note that this will chance the size of the objects in the ObjectContainer3D within the 3D space. Not sure if that's what you're trying to do, given that 3D objects have width, height & depth.
In 3D space there is no concept of pixels. Usually the size is in "units". What you are looking for is a way to render pixel perfect textures. So a pixel mapped onto the 3D object renders as a pixel on screen. This is usually achieved by moving the object at a specific distance from the camera.
Here's a link to a blog post I found on the subject that should point you in the right direction.
In the end the size of the actual 3D object doesn't matter. What matter is the scale and mainly the aspect ratio to render texture as needed. To render a 400px by 200px texture on screen, the 3D plane can be 4 units by 2 units. After that positioning it correctly in front of the camera will produce a 400px by 200px image on screen.
hth.
J.

Collision box for AS3 + papervision3d + jiglib

I'm trying to recreate the "tutorial" explained on the site below. It's 5 dices bouncing around on the scene. But i'm stuck at the very beginning :)
papervision3d-jiglib-dice-demo
My problem is the bounding box. I want to create a box with a floor and 4 walls based on the size of the stage. I can get it the right size using zoom/focus on the camera. But the problem is the dices go through it.
How can i build 4 walls and make sure a dice doesnt go through it when i apply forces to it?
I tried the solution in the following source, but somehow the dices keep going through :(
throwing-dice-with-the-jiglib-physics-engine-and-away3d
Anybody knows how to do it? Or a better way to keep the dices on screen?
I solved the problem. Just to share with others who want to try the same:
Set camera zoom = 2
Set camera focus = distance / zoom
// now the scene width and height match the actual size of the stage.
add the planes for all sides and make sure you make the segments smaller then the dice size. (EG: dice size = 30; stage width = 300; segments = stage width/ dice size = 10).
make sure you ceil the results because segments require int
Ofcourse you can make it larger, but then it will be harder to render.
I made the height of the planes a little smaller then twice the dice size to make sure they never get on top of eachother.
And finally add a ceiling by placing another plane with small segments on top of the other planes