Search Results

Search found 1061 results on 43 pages for 'movement'.

Page 7/43 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Implement looped movement animation with tap to cancel

    - by Nader
    Hi All; My app is based around a grid and an image that moves within a grid that is contained within a scrollview. I have an imageview that I am animating from one cell to another in time with a slow finger movement and recentering the scrollview. That is rather straight forward. I have also implement the ability to detect a swipe and therefore move the image all the way to the end of the grid and the uiscrollview recentering. I have even implemented the ability to detect a subsequent tap and freeze the swiped movement. The issue with the swipe movement is that the UIScrollView will scroll all the way to the end before the Image reaches the end and so I have to wait for the image to arrive. Also, when I freeze the movement of the image, I have to re-align the image to a cell (which I can do). I have come to the realization that I have to animate the image one cell at a time for swipes and recentering the uiscrollview before moving the image to the next cell. I have attempted to implement this but I cannot come up with a solution that works or works properly. Can anyone suggest how I go about implementing this? Even if you are able to put up code from a different example or sudo code, it would help a lot as I cannot workout how this should be done, should I be using selectors, a listener in delegates, I just simply lack the experience to solve this design pattern. Here is some code: Note that the sprite is an UIImageView - (void)animateViewToPosition:(SpriteView *)sprite Position:(CGPoint)pos Duration:(CFTimeInterval)duration{ CGMutablePathRef traversePath = CGPathCreateMutable(); CGPathMoveToPoint(traversePath, NULL, sprite.center.x, sprite.center.y); CGPathAddLineToPoint(traversePath, NULL, pos.x, pos.y); CAKeyframeAnimation *traverseAnimation = [CAKeyframeAnimation animationWithKeyPath:kAnimatePosition]; traverseAnimation.duration = duration; traverseAnimation.removedOnCompletion = YES; traverseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; traverseAnimation.delegate = sprite; traverseAnimation.path = traversePath; CGPathRelease(traversePath); [sprite.layer addAnimation:traverseAnimation forKey:kAnimatePosition]; sprite.center = pos; }

    Read the article

  • Implement looped movement animation with tap to cancel

    - by Nader
    Hi All; My app is based around a grid and an image that moves within a grid that is contained within a scrollview. I have an imageview that I am animating from one cell to another in time with a slow finger movement and recentering the scrollview. That is rather straight forward. I have also implement the ability to detect a swipe and therefore move the image all the way to the end of the grid and the uiscrollview recentering. I have even implemented the ability to detect a subsequent tap and freeze the swiped movement. The issue with the swipe movement is that the UIScrollView will scroll all the way to the end before the Image reaches the end and so I have to wait for the image to arrive. Also, when I freeze the movement of the image, I have to re-align the image to a cell (which I can do). I have come to the realization that I have to animate the image one cell at a time for swipes and recentering the uiscrollview before moving the image to the next cell. I have attempted to implement this but I cannot come up with a solution that works or works properly. Can anyone suggest how I go about implementing this? Even if you are able to put up code from a different example or sudo code, it would help a lot as I cannot workout how this should be done, should I be using selectors, a listener in delegates, I just simply lack the experience to solve this design pattern. Here is some code: Note that the sprite is an UIImageView - (void)animateViewToPosition:(SpriteView *)sprite Position:(CGPoint)pos Duration:(CFTimeInterval)duration{ CGMutablePathRef traversePath = CGPathCreateMutable(); CGPathMoveToPoint(traversePath, NULL, sprite.center.x, sprite.center.y); CGPathAddLineToPoint(traversePath, NULL, pos.x, pos.y); CAKeyframeAnimation *traverseAnimation = [CAKeyframeAnimation animationWithKeyPath:kAnimatePosition]; traverseAnimation.duration = duration; traverseAnimation.removedOnCompletion = YES; traverseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; traverseAnimation.delegate = sprite; traverseAnimation.path = traversePath; CGPathRelease(traversePath); [sprite.layer addAnimation:traverseAnimation forKey:kAnimatePosition]; sprite.center = pos;

    Read the article

  • Get hard drive to spin up upon mouse movement

    - by John
    My storage drive which does not contain the OS stops spinning after a few minutes. This is annoying and totally defeats the purpose of having a fast access drive. The drive will NOT spin up when I use the mouse! It only spins up when accessed. However, I don't want it to spin all the time. I would like it to spin up anytime there is mouse activity so it is at the ready when I am using the computer, but go to sleep during inactivity. Can anyone think of a trick to get a secondary drive to spin up on a mouse movement?

    Read the article

  • Multiple Key Presses in XNA?

    - by Bryan Harrington
    I'm actually trying to do something fairly simple. I cannot get multiple key presses to work in XNA. I've tried the following pieces of code. else if (keyboardState.IsKeyDown(Keys.Down) && (keyboardState.IsKeyDown(Keys.Left))) { //Move Character South-West } and I tried. else if (keyboardState.IsKeyDown(Keys.Down)) { if (keyboardState.IsKeyDown(Keys.Left)) { //Move Character South-West } } Neither worked for me. Single presses work just fine. Any thoughts?

    Read the article

  • Moving sprites on a graph in libGDX

    - by nosferat
    In my game I'd like to move sprites on a fixed path. Until this point I was trying to stick with the tools already provided by libGDX, like the Tiled map renderer classes so I'm looking for a solution nearly as convenient as that, e.g. I'd like to avoid creating the adjacency matrix by hand. Tiled has the functionality to add objects to the map but I'm not sure if I can use it for this purpose. Any idea?

    Read the article

  • Rotate/Translate object in local space

    - by Mathias Hölzl
    I am just trying to create a movementcontroller class for game entities. These class should transform the entity affected by the mouse and keyboard input. I am able to calculate the changed rotation and the new globalPosition. Then I multiply: newGlobalMatrix = changedRotationMatrix * oldGlobalMatrix; newGlobalMatrix = MatrixSetPosition(newPosition); The problem is that the object rotates around the global axis and not around the local axis. I use XNAMath for the matrix calculation.

    Read the article

  • AI control for a ship with physics model

    - by Petteri Hietavirta
    I am looking for ideas how to implement following in 2D space. Unfortunately I don't know much about AI/path finding/autonomous control yet. Let's say this ship can move freely but it has mass and momentum. Also, external forces might affect it (explosions etc). The player can set a target for the ship at any time and it should reach that spot and stop. Without physics this would be simple, just point to the direction and go. But how to deal with existing momentum and then stopping on the spot? I don't want to modify ship's placement directly. edit: Just to make clear, the physics related math of the ship itself is not the problem.

    Read the article

  • Efficient mapping layout in 2D side-scroller, and collisions between character and the world

    - by Jack
    I haven't touched Visual Studio for a couple months now, but I was playing a game from the '90s toady and had an epiphany: I was looking for something what i didn't need, and I wasn't using what I knew correctly. One of those realizations was collision, so let me tell you a bit about my project that I was working on. The project's graphics looks like Mario or Dangerous Dave, etc., you get the idea - old-school pixels. So anyway I remember trying to think of something else than AABB for character form, but I couldn't think of anything. Perhaps I could get a suggestion for this? Another thing is the world - I don't want it to be just linear world, I want mountains, etc.. My idea is to use triangles, and no idea yet what to do if I want just part of the cube, say 3/4 or 2/4 or whatever. Hard-coding such things seems inefficient. P.S. I am not looking at the precision level offered by Box2D. Actually I remember trying to implement it at first, but I failed as my understanding of C++ wasn't advanced enough, as it'll be mentioned below. P.P.S. I am programming in C++, and I haven't done it for a couple months now. I have no means of testing it either, as my PC is broken down, and this one can barely run games from late '90s, not to speak about a compiler or a program with inefficient resource management... I am also not an expert (obviously), I don't even know if I can consider myself an average programmer. In short, I am simply curious about my thoughts and my past experience when programming the game. I may come back to it when my PC is fixed, I'm already filling a note about these things.

    Read the article

  • Joystick example problem for android 2D

    - by iQue
    I've searched all over the web for an answer to this, and there are simular topics but nothing works for me, and I have no Idea why. I just want to move my sprite using a joystick, since I'm useless at math when it comes to angles etc I used an example, Ill post the code here: public float initx = 50; //og 425; public float inity = 300; //og 267; public Point _touchingPoint = new Point(50, 300); //og(425, 267); public Point _pointerPosition = new Point(100, 170); private Boolean _dragging = false; private MotionEvent lastEvent; @Override public boolean onTouchEvent(MotionEvent event) { if (event == null && lastEvent == null) { return _dragging; } else if (event == null && lastEvent != null) { event = lastEvent; } else { lastEvent = event; } // drag drop if (event.getAction() == MotionEvent.ACTION_DOWN) { _dragging = true; } else if (event.getAction() == MotionEvent.ACTION_UP) { _dragging = false; } if (_dragging) { // get the pos _touchingPoint.x = (int) event.getX(); _touchingPoint.y = (int) event.getY(); // bound to a box if (_touchingPoint.x < 25) { _touchingPoint.x = 25; //og 400 } if (_touchingPoint.x > 75) { _touchingPoint.x = 75; //og 450 } if (_touchingPoint.y < 275) { _touchingPoint.y = 275; //og 240 } if (_touchingPoint.y > 325) { _touchingPoint.y = 325; //og 290 } // get the angle double angle = Math.atan2(_touchingPoint.y - inity, _touchingPoint.x - initx) / (Math.PI / 180); // Move the beetle in proportion to how far // the joystick is dragged from its center _pointerPosition.y += Math.sin(angle * (Math.PI / 180)) * (_touchingPoint.x / 70); _pointerPosition.x += Math.cos(angle * (Math.PI / 180)) * (_touchingPoint.x / 70); // stop the sprite from goin thru if (_pointerPosition.x + happy.getWidth() >= getWidth()) { _pointerPosition.x = getWidth() - happy.getWidth(); } if (_pointerPosition.x < 0) { _pointerPosition.x = 0; } if (_pointerPosition.y + happy.getHeight() >= getHeight()) { _pointerPosition.y = getHeight() - happy.getHeight(); } if (_pointerPosition.y < 0) { _pointerPosition.y = 0; } } public void render(Canvas canvas) { canvas.drawColor(Color.BLUE); canvas.drawBitmap(joystick.get_joystickBg(), initx-45, inity-45, null); canvas.drawBitmap(happy, _pointerPosition.x, _pointerPosition.y, null); canvas.drawBitmap(joystick.get_joystick(), _touchingPoint.x - 26, _touchingPoint.y - 26, null); } public void update() { this.onTouchEvent(null); } og= original position. as you can see Im trying to move the joystick, but when I do it stops working correctly, I mean it still works like a joystick but the sprite dosnt move accordingly, if I for example push the joystick down, the sprite moves up, and if I push it up it moves left. can anyone PLEASE help me, I've been stuck here for sooo long and its really frustrating.

    Read the article

  • Moving player in direciton camera is facing

    - by Samurai Fox
    I have a 3rd person camera which can rotate around the player. My problem is that wherever camera is facing, players forward is always the same direction. For example when camera is facing the right side of the player, when I press button to move forward, I want player to turn to the left and make that the "new forward". My camera script so far: using UnityEngine; using System.Collections; public class PlayerScript : MonoBehaviour { public float RotateSpeed = 150, MoveSpeed = 50; float DeltaTime; void Update() { DeltaTime = Time.deltaTime; transform.Rotate(0, Input.GetAxis("LeftX") * RotateSpeed * DeltaTime, 0); transform.Translate(0, 0, -Input.GetAxis("LeftY") * MoveSpeed * DeltaTime); } } public class CameraScript : MonoBehaviour { public GameObject Target; public float RotateSpeed = 170, FollowDistance = 20, FollowHeight = 10; float RotateSpeedPerTime, DesiredRotationAngle, DesiredHeight, CurrentRotationAngle, CurrentHeight, Yaw, Pitch; Quaternion CurrentRotation; void LateUpdate() { RotateSpeedPerTime = RotateSpeed * Time.deltaTime; DesiredRotationAngle = Target.transform.eulerAngles.y; DesiredHeight = Target.transform.position.y + FollowHeight; CurrentRotationAngle = transform.eulerAngles.y; CurrentHeight = transform.position.y; CurrentRotationAngle = Mathf.LerpAngle(CurrentRotationAngle, DesiredRotationAngle, 0); CurrentHeight = Mathf.Lerp(CurrentHeight, DesiredHeight, 0); CurrentRotation = Quaternion.Euler(0, CurrentRotationAngle, 0); transform.position = Target.transform.position; transform.position -= CurrentRotation * Vector3.forward * FollowDistance; transform.position = new Vector3(transform.position.x, CurrentHeight, transform.position.z); Yaw = Input.GetAxis("Right Horizontal") * RotateSpeedPerTime; Pitch = Input.GetAxis("Right Vertical") * RotateSpeedPerTime; transform.Translate(new Vector3(Yaw, -Pitch, 0)); transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z); transform.LookAt(Target.transform); } }

    Read the article

  • Unity-Animation parameters are not being set

    - by user1814893
    I have the following animation controller: with two parameters of walkingSpeed and Jump. I have the following code which should change the values: animator.SetFloat("walkingSpeed",0.9f); animator.SetBool("Jump",true); and animator is the correctly referenced animator object. However the values that the parameters are set to do not appear to change in the animator window, nor do they appear to impact what is happening on the screen. However they do seem to impact the values obtained when doing the following: animator.GetFloat("walkingSpeed"); The animator consists of the shown blend tree, which works correctly and is always active, however due to the values not being changed it does not blends, and always acts as if the value with which it blends (walkingSpeed is 0). What is going on?

    Read the article

  • Increasing speed of circle over time as linear with Box2d

    - by Whispered
    Assume that there is a circle and it can be moved by using keyboard arrows.Is required that increasing speed over time like increasing car speed. For example; max speed is 25 and time to reach max speed shall be 5 sec. Over 5 sec the speed will reach to max speed. Does Box2d handle that situation?. I tried setting linear valocity but it seems to make the circle have constant speed instead of increased speed over time. Thank You! Note: I'm using Box2DWeb Javascript port of Box2D.

    Read the article

  • Can't get sprite to rotate correctly?

    - by rphello101
    I'm attempting to play with graphics using Java/Slick 2d. I'm trying to get my sprite to rotate to wherever the mouse is on the screen and then move accordingly. I figured the best way to do this was to keep track of the angle the sprite is at since I have to multiply the cosine/sine of the angle by the move speed in order to get the sprite to go "forwards" even if it is, say, facing 45 degrees in quadrant 3. However, before I even worry about that, I'm having trouble even getting my sprite to rotate in the first place. Preliminary console tests showed that this code worked, but when applied to the sprite, it just kind twitches. Anyone know what's wrong? int mX = Mouse.getX(); int mY = HEIGHT - Mouse.getY(); int pX = sprite.x; int pY = sprite.y; int tempY, tempX; double mAng, pAng = sprite.angle; double angRotate=0; if(mX!=pX){ tempY=pY-mY; tempX=mX-pX; mAng = Math.toDegrees(Math.atan2(Math.abs((tempY)),Math.abs((tempX)))); if(mAng==0 && mX<=pX) mAng=180; } else{ if(mY>pY) mAng=270; else mAng=90; } //Calculations if(mX<pX&&mY<pY){ //If in Q2 mAng = 180-mAng; } if(mX<pX&&mY>pY){ //If in Q3 mAng = 180+mAng; } if(mX>pX&&mY>pY){ //If in Q4 mAng = 360-mAng; } angRotate = mAng-pAng; sprite.angle = mAng; sprite.image.setRotation((float)angRotate);

    Read the article

  • Resources on expected behaviour when manipulating 3D objects with the mouse

    - by sebf
    Hello, In my animation editor, I have a 3D gizmo that sits on the origin of a bone; the user drags the mesh around to rotate the bone. I've found that translating the 2D movements of the mouse into sensible 3D transforms is not near as simple as i'd hoped. For example what is intuitively 'up' or 'down'? How should the magnitude of rotations change with respect to dX/dY? How to implement this? What happens when the gizmo changes position or orientation with respect to the camera? ect. So far with trial and error i've written something (very) simple that works 70% of the time. I could probably continue to hack at it until I made something that works 99% of the time, but there must be someone who needed the same thing, and spent the time coming up with a much more elegant solution. Does anyone know of one?

    Read the article

  • following a moving sprite

    - by iQue
    Im trying to get my enemies to follow my main-character of the game (2D), but for some reason the game starts lagging like crazy when I do it the way I want to do it, and the following-part dosnt work 100% either, its just 1/24 enemies that comes to my sprite, the other 23 move towards it but stay at a certain point. Might be a poor explenation but dont know how else to put it. Code for moving my enemies: private int enemyX(){ int x = 0; for (int i = 0; i < enemies.size(); i++){ if (controls.pointerPosition.x > enemies.get(i).getX()){//pointerPosition is the position of my main-sprite. x = 5; } else{ x=-5; } Log.d(TAG, "happyX HERE: " + controls.pointerPosition.x); Log.d(TAG, "enemyX HERE: " + enemies.get(i).getX()); } return x; } private int enemyY(){ int y = 0; for (int i = 0; i < enemies.size(); i++){ if (controls.pointerPosition.y > enemies.get(i).getY()){ y = 5; } else{ y=-5; } } return y; } I send it to the update-method in my Enemy-class: private void drawEnemy(Canvas canvas){ addEnemies(); // a method where I add enemies to my arrayList, no parameters except bitmap. for(int i = 0; i < enemies.size(); i++){ enemies.get(i).update(enemyX(), enemyY()); } for(int i = 0; i < enemies.size(); i++){ enemies.get(i).draw(canvas); } } and finally, the update-method itself, located in my Enemy-class: public void update(int velX, int velY) { x += velX; //sets x before I draw y += velY; //sets y before I draw currentFrame = ++currentFrame % BMP_COLUMNS; } So can any1 figure out why it starts lagging so much and how I can fix it? Thanks for your time!

    Read the article

  • How to follow object on CatmullRomSplines at constant speed (e.g. train and train carriage)?

    - by Simon
    I have a CatmullRomSpline, and using the very good example at https://github.com/libgdx/libgdx/wiki/Path-interface-%26-Splines I have my object moving at an even pace over the spline. Using a simple train and carriage example, I now want to have the carriage follow the train at the same speed as the train (not jolting along as it does with my code below). This leads into my main questions: How can I make the carriage have the same constant speed as the train and make it non jerky (it has something to do with the derivative I think, I don't understand how that part works)? Why do I need to divide by the line length to convert to metres per second, and is that correct? It wasn't done in the linked examples? I have used the example I linked to above, and modified for my specific example: private void process(CatmullRomSpline catmullRomSpline) { // Render path with precision of 1000 points renderPath(catmullRomSpline, 1000); float length = catmullRomSpline.approxLength(catmullRomSpline.spanCount * 1000); // Render the "train" Vector2 trainDerivative = new Vector2(); Vector2 trainLocation = new Vector2(); catmullRomSpline.derivativeAt(trainDerivative, current); // For some reason need to divide by length to convert from pixel speed to metres per second but I do not // really understand why I need it, it wasn't done in the examples??????? current += (Gdx.graphics.getDeltaTime() * speed / length) / trainDerivative.len(); catmullRomSpline.valueAt(trainLocation, current); renderCircleAtLocation(trainLocation); if (current >= 1) { current -= 1; } // Render the "carriage" Vector2 carriageLocation = new Vector2(); float carriagePercentageCovered = (((current * length) - 1f) / length); // I would like it to follow at 1 metre behind carriagePercentageCovered = Math.max(carriagePercentageCovered, 0); catmullRomSpline.valueAt(carriageLocation, carriagePercentageCovered); renderCircleAtLocation(carriageLocation); } private void renderPath(CatmullRomSpline catmullRomSpline, int k) { // catMulPoints would normally be cached when initialising, but for sake of example... Vector2[] catMulPoints = new Vector2[k]; for (int i = 0; i < k; ++i) { catMulPoints[i] = new Vector2(); catmullRomSpline.valueAt(catMulPoints[i], ((float) i) / ((float) k - 1)); } SHAPE_RENDERER.begin(ShapeRenderer.ShapeType.Line); SHAPE_RENDERER.setColor(Color.NAVY); for (int i = 0; i < k - 1; ++i) { SHAPE_RENDERER.line((Vector2) catMulPoints[i], (Vector2) catMulPoints[i + 1]); } SHAPE_RENDERER.end(); } private void renderCircleAtLocation(Vector2 location) { SHAPE_RENDERER.begin(ShapeRenderer.ShapeType.Filled); SHAPE_RENDERER.setColor(Color.YELLOW); SHAPE_RENDERER.circle(location.x, location.y, .5f); SHAPE_RENDERER.end(); } To create a decent sized CatmullRomSpline for testing this out: Vector2[] controlPoints = makeControlPointsArray(); CatmullRomSpline myCatmull = new CatmullRomSpline(controlPoints, false); .... private Vector2[] makeControlPointsArray() { Vector2[] pointsArray = new Vector2[78]; pointsArray[0] = new Vector2(1.681817f, 10.379999f); pointsArray[1] = new Vector2(2.045455f, 10.379999f); pointsArray[2] = new Vector2(2.663636f, 10.479999f); pointsArray[3] = new Vector2(3.027272f, 10.700000f); pointsArray[4] = new Vector2(3.663636f, 10.939999f); pointsArray[5] = new Vector2(4.245455f, 10.899999f); pointsArray[6] = new Vector2(4.736363f, 10.720000f); pointsArray[7] = new Vector2(4.754545f, 10.339999f); pointsArray[8] = new Vector2(4.518181f, 9.860000f); pointsArray[9] = new Vector2(3.790908f, 9.340000f); pointsArray[10] = new Vector2(3.172727f, 8.739999f); pointsArray[11] = new Vector2(3.300000f, 8.340000f); pointsArray[12] = new Vector2(3.700000f, 8.159999f); pointsArray[13] = new Vector2(4.227272f, 8.520000f); pointsArray[14] = new Vector2(4.681818f, 8.819999f); pointsArray[15] = new Vector2(5.081817f, 9.200000f); pointsArray[16] = new Vector2(5.463636f, 9.460000f); pointsArray[17] = new Vector2(5.972727f, 9.300000f); pointsArray[18] = new Vector2(6.063636f, 8.780000f); pointsArray[19] = new Vector2(6.027272f, 8.259999f); pointsArray[20] = new Vector2(5.700000f, 7.739999f); pointsArray[21] = new Vector2(5.300000f, 7.440000f); pointsArray[22] = new Vector2(4.645454f, 7.179999f); pointsArray[23] = new Vector2(4.136363f, 6.940000f); pointsArray[24] = new Vector2(3.427272f, 6.720000f); pointsArray[25] = new Vector2(2.572727f, 6.559999f); pointsArray[26] = new Vector2(1.900000f, 7.100000f); pointsArray[27] = new Vector2(2.336362f, 7.440000f); pointsArray[28] = new Vector2(2.590908f, 7.940000f); pointsArray[29] = new Vector2(2.318181f, 8.500000f); pointsArray[30] = new Vector2(1.663636f, 8.599999f); pointsArray[31] = new Vector2(1.209090f, 8.299999f); pointsArray[32] = new Vector2(1.118181f, 7.700000f); pointsArray[33] = new Vector2(1.045455f, 6.880000f); pointsArray[34] = new Vector2(1.154545f, 6.100000f); pointsArray[35] = new Vector2(1.281817f, 5.580000f); pointsArray[36] = new Vector2(1.700000f, 5.320000f); pointsArray[37] = new Vector2(2.190908f, 5.199999f); pointsArray[38] = new Vector2(2.900000f, 5.100000f); pointsArray[39] = new Vector2(3.700000f, 5.100000f); pointsArray[40] = new Vector2(4.372727f, 5.220000f); pointsArray[41] = new Vector2(4.827272f, 5.220000f); pointsArray[42] = new Vector2(5.463636f, 5.160000f); pointsArray[43] = new Vector2(5.554545f, 4.700000f); pointsArray[44] = new Vector2(5.245453f, 4.340000f); pointsArray[45] = new Vector2(4.445455f, 4.280000f); pointsArray[46] = new Vector2(3.609091f, 4.260000f); pointsArray[47] = new Vector2(2.718181f, 4.160000f); pointsArray[48] = new Vector2(1.990908f, 4.140000f); pointsArray[49] = new Vector2(1.427272f, 3.980000f); pointsArray[50] = new Vector2(1.609090f, 3.580000f); pointsArray[51] = new Vector2(2.136363f, 3.440000f); pointsArray[52] = new Vector2(3.227272f, 3.280000f); pointsArray[53] = new Vector2(3.972727f, 3.340000f); pointsArray[54] = new Vector2(5.027272f, 3.360000f); pointsArray[55] = new Vector2(5.718181f, 3.460000f); pointsArray[56] = new Vector2(6.100000f, 4.240000f); pointsArray[57] = new Vector2(6.209091f, 4.500000f); pointsArray[58] = new Vector2(6.118181f, 5.320000f); pointsArray[59] = new Vector2(5.772727f, 5.920000f); pointsArray[60] = new Vector2(4.881817f, 6.140000f); pointsArray[61] = new Vector2(5.318181f, 6.580000f); pointsArray[62] = new Vector2(6.263636f, 7.020000f); pointsArray[63] = new Vector2(6.645453f, 7.420000f); pointsArray[64] = new Vector2(6.681817f, 8.179999f); pointsArray[65] = new Vector2(6.627272f, 9.080000f); pointsArray[66] = new Vector2(6.572727f, 9.699999f); pointsArray[67] = new Vector2(6.263636f, 10.820000f); pointsArray[68] = new Vector2(5.754546f, 11.479999f); pointsArray[69] = new Vector2(4.536363f, 11.599998f); pointsArray[70] = new Vector2(3.572727f, 11.700000f); pointsArray[71] = new Vector2(2.809090f, 11.660000f); pointsArray[72] = new Vector2(1.445455f, 11.559999f); pointsArray[73] = new Vector2(0.936363f, 11.280000f); pointsArray[74] = new Vector2(0.754545f, 10.879999f); pointsArray[75] = new Vector2(0.700000f, 9.939999f); pointsArray[76] = new Vector2(0.918181f, 9.620000f); pointsArray[77] = new Vector2(1.463636f, 9.600000f); return pointsArray; } Disclaimer: My math is very rusty, so please explain in lay mans terms....

    Read the article

  • XNA: How to make the Vaus Spacecraft move left and right on directional keys pressed?

    - by Will Marcouiller
    I'm currently learning XNA per suggestion from this question's accepted answer: Where to start writing games, any tutorials or the like? I have then installed everything to get ready to work with XNA Game Studio 4.0. General Objective Writing an Arkanoid-like game. I want to make my ship move when I press either left or right keys. Code Sample protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here #if WINDOWS if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); else { if (Keyboard.GetState().IsKeyDown(Keys.Left)) MoveLeft(gameTime); } #endif // Move the sprite around. BounceEnergyBall(gameTime); base.Update(gameTime); } void MoveLeft(GameTime gameTime) { // I'm not sure how to play with the Vector2 object and its position here!... _vausSpacecraftPos /= _vausSpacecraftSpeed.X; // This line makes the spacecraft move diagnol-top-left. } Question What formula shall I use, or what algorithm shall I consider to make my spaceship move as expected left and right properly? Thanks for your thoughts! Any clue will be appreciated. I am on my learning curve though I have years of development behind me (already)!

    Read the article

  • Moving objects colliding when using unalligned collision avoidance (steering)

    - by James Bedford
    I'm having trouble with unaligned collision avoidance for what I think is a rare case. I have set two objects to move towards each other but with a slight offset, so one of the objects is moving slightly upwards, and one of the objects is moving slightly downwards. In my unaligned collision avoidance steering algorithm I'm finding the points on the object's forward line and the other object's forward line where these two lines are the closest. If these closest points are within a collision avoidance distance, and if the distance between them is smaller than the two radii of the two object's bounding spheres, then the objects should steer away in the appropriate direction. The problem is that for my case, the closest points on the lines are calculated to be really far away from the actual collision point. This is because the two forward lines for each object are moving away from each other as the objects pass. The problem is that because of this, no steering takes place, and the two objects partially collide. Does anyone have any suggestions as to how I can correctly calculate the point of collision? Perhaps by somehow taking into account the size of the two objects?

    Read the article

  • Moving characters on a grid [on hold]

    - by madmax1
    i am developing my first game with C++. My game uses a grid of rectangles. I have a class Board which manages the grid as a whole, initializes the terrain, places/removes characters, etc. It has a 2D vector of a class Field, which handles the Structure of the field, contained Objects, Characters, etc. Field again contains a vector of class Character, which are positioned on the field. Now i want to implement the functionality to move a character on the board, however dont know which is best practice to do so. Should i implement a moveCharacter(character, offset) function in Board, make it search for the character and move it? Or should i implement a function move(offset) in Character? This sure would be nicest, however makes characters necessary to know the board they are on, or the field which in turn knows the board. On the one hand i feel like i should avoid inclusion between classes as much as possible e.g. to increase portability of classes for different projects, on the other hand i think the character.move() functionality is most comfortable for further development. Im pretty new to "bigger" C++ projects and these kind of design questions pop up more and more often lately and i have troubles deciding. Thanks a lot for any advice!

    Read the article

  • Updating sprite location with controls

    - by iQue
    So ive got a character in a 2D game using surfaceView that I want to be able to move using a button(eventually a joystick), but my game crashes as soon as I try to move my sprite. This is my onTouch-method for my steering button: public void handleActionDown(int eventX, int eventY) { if (eventX >= (x - bitmap.getWidth() / 2) && (eventX <= (x + bitmap.getWidth()/2))) { if (eventY >= (y - bitmap.getHeight() / 2) && (y <= (y + bitmap.getHeight() / 2))) { setTouched(true); } else { setTouched(false); } } else { setTouched(false); } and if I try to put this in my update-method: public void update() { x += (speed.getXv() * speed.getxDirection()); y += (speed.getYv() * speed.getyDirection()); } the sprite moves on its own just fine, but as soon as I add: public void update() { if(steering.isTouched()){ x += (speed.getXv() * speed.getxDirection()); y += (speed.getYv() * speed.getyDirection()); } the game crashes. Does any1 know why this is or how to fix it? I cannot figure it out. Im using MotionEvent.ACTION_DOWN to check if the user if pressing the screen. }

    Read the article

  • Handling player/background movements in 2D games

    - by lukeluke
    Suppose you have your animated character controlled by the player and a 2D world (like the old 2D side-scrolling games). When the user press right on the keyboard, the background is moved to the right. If the path is always horizontal, this is simple to do (incrementation/decrementation of the x-coordinate). But suppose that the path is instead a polygonal chain. My questions are: How do you move the background? How do you move the background if the game objects are managed with a physics engine like box2D?

    Read the article

  • How to move an object using X and Y coordinates in JavaScript

    - by Geroy290
    I am making a 2d game with JavaScript and HTML5 and am trying to move an image that I have drawn with JavaScript like so: //canvas var c = document.getElementById("gameCanvas"); var ctx = c.getContext("2d"); //baseball var baseball = new Image(); baseball.onload = function() { ctx.drawImage(baseball, 400, 425); }; baseball.src = "baseball2.png"; I'm not sure how I would move it though, I have seen many people seem to just type something like ballX and ballY but I don't understand where the actual x and y definition comes from. Here is my code so far: http://jsfiddle.net/xRfua/ I have a different image source but it is a local source so I couldn't include it. Thanks in a dvance for any help!

    Read the article

  • Using multiplication and division with delta time

    - by tesselode
    Using delta time with addition and subtraction is easy. player.x += 100 * dt However, multiplication and division complicate things a bit. For example, let's say I want the player to double his speed every second. player.x = player.x * 2 * dt I can't do this because it'll slow down the player (unless delta time is really high). Division is the same way, except it'll speed things way up. How can I handle multiplication and division with delta time?

    Read the article

  • How game characters are made?

    - by Ahmed
    I'm new here. I would like to know how game characters are made that are movable? What kind of software and engines are used for these characters? I will be working with my friends on our final year project. Our game will be FPS and I have to draw some animations for FPS view and other enemy character that can be programmed easily to make a good game. Sorry if my questions seems dumb, but if you need more explanation i'm always here to discuss Thanks in advance

    Read the article

  • Brief pause after keypress

    - by user36324
    After i press and hold the key it goes forward once then pauses for a second or less then goes forward on forever. My problem is the brief pause I cant locate the issue. Thanks for your help. while(game){ while (SDL_PollEvent(&e)){ mainChar.manageEvents(e); } background.renderChar(); mainChar.renderChar(); SDL_RenderPresent(ren); } void Character::manageEvents(SDL_Event event) { switch(event.type){ case SDL_KEYDOWN: KEYS[event.key.keysym.sym] = true; printf("true"); handleInput(); break; case SDL_KEYUP: KEYS[event.key.keysym.sym] = false; printf("false"); break; default: break; } } void Character::handleInput() { if(KEYS[SDLK_a]) { dst.x--; } if(KEYS[SDLK_d]) { dst.x++; } if(KEYS[SDLK_w]) { dst.y++; } if(KEYS[SDLK_s]) { dst.y--; } }

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >