Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411913 Posts in 69429 Topics- by 58477 Members - Latest Member: KriegsHetzer

June 10, 2024, 11:56:42 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Setting sprite origin in FlashDevelop
Pages: [1]
Print
Author Topic: Setting sprite origin in FlashDevelop  (Read 1281 times)
davidp
Level 6
*



View Profile WWW
« on: July 07, 2010, 01:24:56 AM »

Ok, you guys have been of great assistance so far and now i have yet another Flash related question.

Terms might be taken from game maker (sprite in combination with origin) but i hope you get the point. I'm trying to find out how to set the image xy origin. This is quite easy to do in adobe flash csX, but i can't figure it out in pure flash code.

to illustrate what i mean:



let's say this rectangle is my sprite. its xy originate on 0,0, but I'd like to set it to 32,32 (for rotation purposes, etc). how would i do that?
« Last Edit: July 07, 2010, 01:28:12 AM by davidp » Logged

grapefrukt
Level 1
*



View Profile WWW
« Reply #1 on: July 07, 2010, 01:55:46 AM »

You can do it the complicated way and use some trigonometry when rotating, but it'll be a bit cumbersome and potentially slow. What I would do is wrap the graphic in another sprite. My standard hiearchy looks a bit like this (in pseudocode)

Code:
public class Player extends Sprite {
  private var _gfx:Sprite;
}

This let's me keep the position of the player separate from the relative position of the players graphics, so, offsetting the _gfx object's coordinates by 32 on each axis will give the effect you desire.

This also makes it easier to switch your graphics to say a Movieclip or a Bitmap, since it's all internal to the class.
Logged
st33d
Guest
« Reply #2 on: July 07, 2010, 04:03:43 AM »

In CSX you generally have a Bitmap inside a Sprite like grapefrukt says.

But if you're unfamiliar with it already, you should look at the Transform object that is a property of all DisplayObjects in Flash:

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/geom/Transform.html

In particular, look at the Matrix property. This object is connected to your Sprite's rotation and position.
Logged
davidp
Level 6
*



View Profile WWW
« Reply #3 on: July 07, 2010, 04:49:45 AM »

yes, i thought i'll end up with matrixes eventually Smiley

i'll take both suggestions in consideration.

thank you.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic