I'm creating Poker game. So initially I'm showing back face of playing cards and then I need to add flip animation on the cards to show the value of cards. I've searched the net but I didn't find anything that could have helped me.
my code is as follows.
void LoadBacksideOfCards()
{
player1Card1.SetImageResource(Resource.Drawable.backside);
player1Card2.SetImageResource(Resource.Drawable.backside);
player2Card1.SetImageResource(Resource.Drawable.backside);
player2Card2.SetImageResource(Resource.Drawable.backside);
player3Card1.SetImageResource(Resource.Drawable.backside);
player3Card2.SetImageResource(Resource.Drawable.backside);
player4Card1.SetImageResource(Resource.Drawable.backside);
player4Card2.SetImageResource(Resource.Drawable.backside);
centerCard1.SetImageResource(Resource.Drawable.backside);
centerCard2.SetImageResource(Resource.Drawable.backside);
centerCard3.SetImageResource(Resource.Drawable.backside);
centerCard4.SetImageResource(Resource.Drawable.backside);
centerCard5.SetImageResource(Resource.Drawable.backside);
}
And showing the cards using following code
void ShowCenterCardNumber(int cardNumber)
{
if (cardNumber == 3)
{
centerCard4.SetImageResource(DrawableImageMap[_shuffledCardsData.CenterCardsData[3].CardNumber + _shuffledCardsData.CenterCardsData[3].CardType]);
}
else
{
centerCard5.SetImageResource(DrawableImageMap[_shuffledCardsData.CenterCardsData[4].CardNumber + _shuffledCardsData.CenterCardsData[4].CardType]);
}
}
void ShowFirstThreeCenterCards()
{
centerCard1.SetImageResource(DrawableImageMap[_shuffledCardsData.CenterCardsData[0].CardNumber + _shuffledCardsData.CenterCardsData[0].CardType]);
centerCard2.SetImageResource(DrawableImageMap[_shuffledCardsData.CenterCardsData[1].CardNumber + _shuffledCardsData.CenterCardsData[1].CardType]);
centerCard3.SetImageResource(DrawableImageMap[_shuffledCardsData.CenterCardsData[2].CardNumber + _shuffledCardsData.CenterCardsData[2].CardType]);
}
I want to add some flip functionality to make it more interactive to users.
I'm using simple XML (without MONO Games).
any help in this regard will be much appreciated.
A few suggestions:
http://developer.android.com/training/animation/cardflip.html
http://2cupsoftech.wordpress.com/2012/09/18/3d-flip-between-two-view-or-viewgroup-on-android/
Android flip image animation
https://github.com/castorflex/FlipImageView
Related
im working on the spatial mapping processing for my HoloLens project.
Somehow calling "SpatialSurfaceMesh::TryComputeLatestMeshAsync" keeps returning the same mesh data overtime.
Is there another process involved updating the observer?
void SpatialMapping::AddOrUpdateSurface(winrt::Windows::Perception::Spatial::SpatialCoordinateSystem const& coordinateSystem)
{
using namespace winrt::Windows::Perception::Spatial::Surfaces;
SpatialBoundingBox axisAlignedBoundingBox =
{
{ 0.f, 0.f, 0.f },
{ 50.f, 50.f, 50.f },
};
SpatialBoundingVolume bounds = SpatialBoundingVolume::FromBox(coordinateSystem, axisAlignedBoundingBox);
m_surfaceObserver.SetBoundingVolume(bounds);
m_surfaceObserver.ObservedSurfacesChanged(
winrt::Windows::Foundation::TypedEventHandler
<SpatialSurfaceObserver, winrt::Windows::Foundation::IInspectable>
({ this, &SpatialMapping::Observer_ObservedSurfacesChanged })
);
}
void SpatialMapping::Observer_ObservedSurfacesChanged(winrt::Windows::Perception::Spatial::Surfaces::SpatialSurfaceObserver const& sender
, winrt::Windows::Foundation::IInspectable const& object)
{
{
using namespace winrt::Windows::Perception::Spatial::Surfaces;
const auto mapContainingSurfaceCollection = sender.GetObservedSurfaces();
// Process surface adds and updates?.
for (const auto& pair : mapContainingSurfaceCollection)
{
auto id = pair.Key();
auto info = pair.Value();
InsertAsync(id, info);
}
}
}
Concurrency::task<void> SpatialMapping::InsertAsync(winrt::guid /*const&*/ id, winrt::Windows::Perception::Spatial::Surfaces::SpatialSurfaceInfo /*const&*/ newSurfaceInfo)
{
using namespace winrt::Windows::Perception::Spatial::Surfaces;
return concurrency::create_task([this, id, newSurfaceInfo]
{
const auto surfaceMesh = newSurfaceInfo.TryComputeLatestMeshAsync(m_maxTrianglesPerCubicMeter, m_surfaceMeshOptions).get();
std::lock_guard<std::mutex> guard(m_meshCollectionLock);
m_updatedSurfaces.emplace(id, surfaceMesh);
});
}
Generation works, Update does not
Manuel attempt same problem:
winrt::Windows::Foundation::IAsyncAction SpatialMapping::CollectSurfacesManuel()
{
const auto mapContainingSurfaceCollection = m_surfaceObserver.GetObservedSurfaces();
for (const auto& pair : mapContainingSurfaceCollection)
{
auto id = pair.Key();
auto info = pair.Value();
auto mesh{ co_await info.TryComputeLatestMeshAsync(m_maxTrianglesPerCubicMeter, m_surfaceMeshOptions) };
{
std::lock_guard<std::mutex> guard(m_meshCollectionLock);
m_updatedSurfaces.emplace(id, mesh);
}
}
}
MVCE:
Create a New Project with the template
"Holographic DirectX 11 App (UWP) C++/WinRT)"
Add the files:
https://github.com/lpnxDX/HL_MVCE_SpatialSurfaceMeshUpdateProblem.git
Replace m_main in AppView.h
We did some research and have some thoughts about your question right now, let me explain the findings
Has your Observer_ObservedSurfacesChanged method triggered exactly? Adding output statements or breakpoints can help you check it. Since SurfaceObserver should be always available, usually we need to check the availability of surfaceObserver in each frame and recreate a new one when necessary, sample code snippt please see here.
Have you set m_surfaceMeshOptions? It is not visible in the code you posted. If it is missing, you can configure it with the following statement:
surfaceMeshOptions-> IncludeVertexNormals = true;
Microsoft provided the Holographic spatial mapping sample, shows how to acquire spatial mapping data from Windows Perception in real-time. it is similar to your needs, to narrow down issue if it's an issue with your code, please try to check and run this example on your device
If after the above steps, you still can't solve the problem, could you provide an
MVCE, so that we can locate the issue or find a solution? Be careful to remove any privacy-related or other business function codes.
Your code has the following problems:
TryComputeLatestMeshAsync should be called from Observer_ObservedSurfacesChanged not from concurrency::create_task
TryComputeLatestMeshAsync return mesh with matrix, vertices and indices. Indices should be stored to a safe location at the first run, they don't change later. Vertices and matrix should copied as they returns. You shouldn't save the mesh itself, because its data updates from various threads.
ObservedSurfacesChanged shouldn't be called every frame. This is long running function.
Maybe it has something more. I would recommend to start from the sample mentioned earlier.
I'm trying to create a 'Bomber-man' like game using Phaser3 library.
For this purpose I'd like to define a collision relationship between the player and the bricks,
and more importantly - detect the collision direction relative the the player.
I've noticed body properties like touching or blocked but they are always set to false. (please see below)
//scene.js
// bricks static group
this.scene.physics.add.staticGroup({ immovable: true });
// player defined in external file (as sprite)
this.player = new Player(this, 90, 90)
// player.js
// ...
this.physics.add.collider(
this,
scene.bricks,
function(player, brick) {
if(player.body.touching.left) { //ALWAYS FALSE!!!
this.isBlockedFromLeft = true;
}, else if(player.body.touching.right) {
this.isBlockedFromRight = true; // ALWAYS FALSE!!!
}
},
null,
this
);
I'd appreciate any help. This is driving me crazy. Maybe there is a better way to do it and i'm missing something...
Thanks in advance.
So I finally figured it out.
The major issue was the way I defined the player movement. It should be
if (this.keyboard.right.isDown) {
this.body.setVelocityX(this.speed);
}
rather than
if (this.keyboard.right.isDown) {
this.x += this.speed;
}
The second way prevent collision detection and the body.touching and body.blocked properties to be updated.
Furthermore, I've found out that when it comes to top-down tiled games, it's really easier to build up the game using the tile-map feature.
official examples can be found here:
https://phaser.io/examples/v3/search?search=map
and here is a tutorial of how to make a tiled-map using a light-weight software called 'Tiled'
https://www.youtube.com/watch?v=2_x1dOvgF1E
Thank you all!
I'm trying to implement a picture-in-picture mode in my app. I'm Implementing google Maps on PIP mode but I can't resize the full-screen map. It always zooms on the map center point. I have done R&D related to this issue but not finding any proper answer. Basically, I need the layout like Whatsapp app pip Screen on my app how to implement it? And my code is here:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Display display=getWindowManager().getDefaultDisplay();
Point size=new Point();
display.getSize(size);
int width=size.x;
int height=size.y;
Rational aspectRatio=new Rational(width,height);
PictureInPictureParams params = new PictureInPictureParams.Builder()
.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(params);
}
and here is Manifest code:
<activity android:name=".activities.MainActivity"
android:supportsPictureInPicture="true"
android:resizeableActivity="true"
android:launchMode="singleTask"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"/>
In this code, I have the screen like
and I want
How can I solve this?
Thanks in advance!!
Just Change Your this code
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Display display=getWindowManager().getDefaultDisplay();
Point size=new Point();
display.getSize(size);
int width=size.x;
int height=size.y;
Rational aspectRatio=new Rational(width,height);
PictureInPictureParams params = new PictureInPictureParams.Builder()
.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(params);
}
To
Rational aspectRatio = new Rational(3, 4);
PictureInPictureParams params = new PictureInPictureParams.Builder()
.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(params);
I'm new to Phaser and am following this tutorial here: https://phaser.io/tutorials/making-your-first-phaser-3-game/part7
What do I need to change for use on a mobile cell phone browser to make the player automatically run to the right and jump when the screen is tapped? I've searched for ages but can't find the answer and am trying to learn
// Input Events
cursors = this.input.keyboard.createCursorKeys();
if (cursors.left.isDown)
{
player.setVelocityX(-160);
player.anims.play('left', true);
}
else if (cursors.right.isDown)
{
player.setVelocityX(160);
player.anims.play('right', true);
}
else
{
player.setVelocityX(0);
player.anims.play('turn');
}
if (cursors.up.isDown && player.body.touching.down)
{
player.setVelocityY(-330);
}
What I would do:
Add an input handler to your general game that calls a 'jump' function when a pointer is down.
this.input.on('pointerdown', this.jump, this);
Jump should now verify that the player can jump. Something like:
jump() {
if (this.player.body.touching.down) {
this.player.setVelocityY(-330);
}
}
To have your player automatically move at a speed, you can just set the player's body velocity when you're creating the player.
this.player.body.velocity.x = 160;
Note that if you want to keep the current ability to control the player, another option is to have actual buttons on the screen that the user can tap/click on to have the player move/act accordingly. There's an official plugin for Phaser 2 that does this, that you could look at.
I have tried my textfield to have the very first letter to be capitalized with the following code :-
Form f = new Form();
TextField firstname = new TextField();
firstname.setConstraint(TextField.INITIAL_CAPS_SENTENCE);
f.addComponent(firstname);
f.show();
But this is not working.
What am I missing here? Can anybody suggest a correct way to achieve it?
Note : I am using LWUIT 1.5
Edited
This is how I finally did it with the help of Shai
public void insertChars(String c) {
super.insertChars(c); //To change body of generated methods, choose Tools | Templates.
if(super.getText()!=null && super.getText().length()>0){
super.setText((super.getText().substring(0,1).toUpperCase())+super.getText().substring(1, super.getText().length()));
}else{
super.setText(super.getText());
}
}
Are you using a qwerty J2ME device by any chance? If so this won't work since this only applies to the native side of the things.
You need to derive TextField and override insertChar() to implement this.