Pixel-perfect actor placement in scene

I'm working on a game with a unique pixelated design that requires pixel-perfect placement of each actor in the scene. Dragging actors into the scene is a nightmare in this scenario. Sure, I can edit each individual actor to have an exact pixel position ... but that's very time-consuming. Since GameSalad shockingly does not have a snap-to-grid option, I'm sorta stuck. To the point that I'm seriously considering switching to a different tool like Stencyl. But before I make that drastic move ... I'm wondering if anyone can offer any tips or tricks. Or even better ... a sample file I can download and study.

I'm wondering if this can be done with tables where the table tells each actor where to place itself in the scene. Think of it this way ... say you have 100 32px blocks that you want to appear on the scene with no gaps or overlaps as they sit next to each other. Right now I'm forced to drag each of those 100 blocks into the scene and edit each one to have a perfect position. And I'm about to go nuts doing that. ???

Any help would be REALLY appreciated.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I'll make you a demo.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2013
    You can certainly use tables but if you just need a simple regular grid, there's no need to store the positions as you can just use mathematical formulas to generate them.

    If you don't want to use a spawner (see attached demo) and prefer to drag the actors near their final positions, you can use a snap-to-grid behavior:

    Change Attribute self.position.X to floor(self.position.X/32)*32+16

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • pHghostpHghost London, UKMember Posts: 2,342
    I've got a related issue:

    I'm creating an endless runner with 8-bit pixel-perfect assets. I've got two issues with pixel perfect placement.

    As in pretty much any endless runner, the actor needs to jump to avoid death.

    1. During jumping, is there any way to make GS render the actor only on integer coordinates, so the actor is all sharp throughout?

    2. More importantly -- I'm using gravity to bring the actor back down after the jump. But when the actor does land, he isn't sharp, because the collision system isn't that perfect, I guess (the ground actor is on an integer coordinate). Is there a way around this? Even if it means turning off the collision. Is there a way to for example set a certain coordinate as 'ground' for the actor to stop?

    Thanks a lot!
  • SocksSocks London, UK.Member Posts: 12,822
    1. During jumping, is there any way to make GS render the actor only on integer coordinates, so the actor is all sharp throughout?

    2. More importantly -- I'm using gravity to bring the actor back down after the jump. But when the actor does land, he isn't sharp, because the collision system isn't that perfect, I guess (the ground actor is on an integer coordinate). Is there a way around this? Even if it means turning off the collision. Is there a way to for example set a certain coordinate as 'ground' for the actor to stop?

    Thanks a lot!
    Stick in a rule that says when he lands round up his position to the nearest pixel - something like change self position to floor(self position)

  • pHghostpHghost London, UKMember Posts: 2,342
    Perfect! Did a Constrain Attribute: self.Position.Y to: floor(self.Position.Y), which if I understand it right, should actually solve both issues, right?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited November 2013
    Perfect! Did a Constrain Attribute: self.Position.Y to: floor(self.Position.Y), which if I understand it right, should actually solve both issues, right?
    The floor() function rounds down. If Y is 10.9, it will round down to 10. If you're okay with that, it's fine but if you want it to round both up and down you'll need to do something like this:

    floor(self.position.Y)+floor((((self.position.Y)*10-(floor(self.position.Y)*10))*2)/10)*10

    edit: Ack! It doesn't work... back to the drawing board


    I believe the answer is prec(self.position.Y,0)

    I'm sure someone like @RThurman or @Socks can simplify that down quite a bit so I'll just leave that there. :-/

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited November 2013
    And in case you want to build a precision formula yourself or *ahem* you just like seeing me struggle, here's the final expression I worked out:

    floor(self.Position.Y)+floor((self.Position.Y*10-(floor(self.Position.Y)*10))/5)

    phew.

    And just so I don't feel my whole morning was wasted, here's a demo with snap-to-pixel. Drag the actor and then release to snap to rounded pixels using the formula above.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @tatiang -- go man go! You are on fire!

    The precision function is the way to quickly round up and down. But you need to be careful about rounding at the midpoint. For example prec(111.499999,0) rounds down to 111 but prec(111.5,0) rounds up to 112.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    lol @RThurman. Brain strain for sure.

    But aren't your choices to round down at 111.5 or up at 111.5? What difference does it make which way you choose? For example, 111.0 to 111.49 is a range of .49 while 111.5 to 111.99 is also a range of .49 so it seems like a toss-up.

    Prec() works the way I expect it to, which is to say that it rounds up at 111.5.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @tatiang -- I should know better than to tell a school teacher about rounding.

    Carry on!
  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2013
    @tatiang -- I should know better than to tell a school teacher about rounding.
    @RThurman

    :))

    Careful, you don't want to get detention from tatiang.

    image

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Thank you @Socks, @Rthurman and @BartSimpson. Made my day!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.