Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Cocos2d style Actions with SFML  (Read 2593 times)

0 Members and 1 Guest are viewing this topic.

eventhorizon02

  • Newbie
  • *
  • Posts: 7
    • View Profile
Cocos2d style Actions with SFML
« on: January 08, 2016, 09:27:34 am »
Hi all,
I'm trying to implement cocos2d style actions (or spriteKit style actions or cocos2dx actions) with SFML
Actions such as move, animate etc.
I'm trying to figure out the best way to go about it and need your opinion.
Should I go the multi thread route or just implement it in the main thread somehow.
your ideas are appreciated.

Cheers

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Cocos2d style Actions with SFML
« Reply #1 on: January 08, 2016, 10:38:38 pm »
For those who don't know Cocos2d actions, can you quickly elaborate what you mean exactly and give some examples?

SFML itself probably doesn't provide what you're looking for, but there are extension libraries. For example, for animations, my library Thor could help you.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eventhorizon02

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Cocos2d style Actions with SFML
« Reply #2 on: January 09, 2016, 06:48:07 am »
Thanks, I already figured out the best way to go about it and started implementing it.
I like SFML for it's light weight and simplicity.
Actions are a hight level abstraction that can help you when writing your game. You define an action such as MoveAction provide the destination and the time then call runAction on a node.
You can also define a sequence of action with repeat forever or not, etc.
Anyway these are nice features that some other libraries have such as cocos2dx and decided to implement with SFML.
cheers

Resethel

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
Re: Cocos2d style Actions with SFML
« Reply #3 on: January 09, 2016, 03:04:39 pm »
Hmm, imo, i would go for an action struct, something like that:

This is your action:
struct Action:
{
     std::function<void(Actor&, sf::Time)>    action    
     Category                                 category
 }
 
Which contain a function and the category of the entities targeted. You create some lambdas in another/same file to make your actions, then you just have to make your Node's actors bearing a method like this one:

void Actor::receiveOrder(const Action& order, sf::Time dt)
{
      if (order.category == mCategory)
      {
             order.action(this, dt)
      }
      // Then you distribute this order to all the other nodes
 }
 
This way you may make an queue of actions, so you're sure they are triggered in the right order.

Well there are better system than categories, like a ID with specials value for differents actor or make category an array of categories and then check if the actor category fit one of the categories set ( 'cause you can use variadic functions, but I dislike it) or use bit shif (<<) to assign a int to each category  in order to use the bitwise operator . . . But at your place, I would go for something like that
« Last Edit: January 09, 2016, 03:27:26 pm by Resethel »

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 878
    • View Profile
Re: Cocos2d style Actions with SFML
« Reply #4 on: January 10, 2016, 10:14:30 am »
Looks like you're looking for something such as EntityX (see Events). SFML doesn't provide custom messaging/event handling.