Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Assemblies of sprites and using SetSpriteOffset multiple times

Author
Message
xtremi
6
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 26th Aug 2018 14:28 Edited at: 26th Aug 2018 14:40
I'm trying to work with groups of multiple sprites, assemblies of such groups and correctly rotate and transform these.

So in the this code, which is just an example of my problem, I have the following types:
- Block : represents a sprite and holds a sprite ID (should hold other properties, but not in this example)
- BlockShape : represents connected blocks (sprites) which together forms a shape (see f.ex. tetris shapes, L-shape, cross, lines...)
- BlockGroup : represents a group of Block Shapes. In this example the groups are just multiple shapes on one line.
- BlockGroupAssembly : represents an assembly of groups.


What I want is to be able to orient a BlockShape in a certain direction, group multiple BlockShapes in a group, which again is oriented. Multiple BlockGroups should be controled by a BlockGroupAssembly, which should also be rotatable.

Here is a picture of what my example code gives:



Here is the example code:




So the only function that is being called to create the sprites is createBlockGroupAssembly(), this will create a few BlockGroups and using the rotateBlockGroup() will rotate each group.

What I tried to do in the function rotateBlockGroupAssembly() is to spin the whole assembly of block groups around a specific rotation group, while still keeping the relative orientations and positions between each group.

Eventually I'd like to this at many level, so, rotate the sprite around one point, the shape around another, the group, and then the assembly.

Is there a simple solution for this, or should I implement myself a system that takes care of the transformation calculation and keep track of different coordinate systems?
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 26th Aug 2018 17:31
i would just get a new image of the created shape using GetImage() and create a sprite from that, if you are only doing it every so often it will be fine (the command can/will slow things down though if you are planning to need this a lot in 1 cycle or every frame but it's not clear how often you want to create the shapes, if it's only during the loading process or 1 shape every so often it will be fine even on mobile).

GetImage() requires you to manually render the screen so can be confusing for a new user but what i generally do is draw a blank sprite at about depth 5 (default depth for sprites is 10 but as long as you place the background in front of any known depths you will be fine) as a temporary background (to easily hide whatever is already on screen), then draw the sprites you want to get the image of (remember to set the depth to less than the temporary background), you can draw these anywhere but i normally draw them starting at 0,0 just to be sure you will always be in the same location on all devices.
then get an image of the desired screen area (this will be based on the sprites you just drew), create a new sprite with the image and delete the previous sprites and remove the temporary background... this way you can pretty much ignore all the rest of your code no matter when you want to get an image because it will all be hidden behind the temporary background and you won't need to worry about moving it etc and it will all still sync correctly once the background is removed.
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
xtremi
6
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 27th Aug 2018 01:42
Not a bad idea. I haven't tried GetImage(), but I have heard about it. I think the slowness of the command would be ok in my case, since this blocks/sprites are not going to be created too often (once per level is the plan for now).
The problem, I think, is that, if I want individual properties per block (sprite) within the shapes. Also, possibly, individual properties for each shape within each group. Making one image per shape or group of shape, will make the whole thing one sprite only. This will limit certain other aspects.


I'm thinking maybe just going for a more mathematical solution, and have:


Assembly type:
- position in world (2 floats)
- direction in world (2 floats)
- array of BlockGroups
- properties

BlockGroups type
- position relative to Assembly position/orientation (2 floats)
- orientation relative to Assembly position/orientation (2 floats)
- array of BlockShapes
- properties

BlockShapes type
- position relative to BlockGroup position/orientation (2 floats)
- orientation relative to BlockGroup position/orientation (2 floats)
- array of Blocks
- properties

Block type
- position relative to BlockShape position/orientation (2 floats)
- orientation relative to BlockShape position/orientation (2 floats)
- properties
- one sprite

Then whenever something has to move, have a function that goes through the different levels of "coordinate systems" (orientations and positions), and calculates the correct position and orientation in world coordinates.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 27th Aug 2018 18:18
then perhaps this thread will help
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu

Login to post a reply

Server time is: 2024-11-23 04:54:10
Your offset time is: 2024-11-23 04:54:10